当我进行这种开发时,我从头开始构建磁盘映像并将 VM 指向它作为软盘。这样,您的汇编程序的输出,即目标文件,可以成为软盘的完整引导扇区,您可以轻松地链接加载更多扇区。例如:
; x86 architecture systems all support MBR style boot sectors. An
; MBR boot sector must be 512 bytes in length and have machine
; language code originating at 0000:7c00. Additionally, it must
; have the signature "0x55aa" as the final word in the sector or it
; is not a valid boot sector.
org 0x7c00 ; BIOS will load the MBR to this location
; and then jump here to continue execution
; Your code here!
; As stated above, the boot sector must
times 510-($-$$) db 0 ; Create padding to fill out to 510 bytes
dw 0xaa55 ; Magic number in the trailer of a boot sector
; We write it as 0xaa55 because we're little
; endian and it will be reversed to the required
; 0x55 0xaa
只需添加您的初始代码。创建一个指向名为“floppy.img”或类似名称的目标文件的链接,然后告诉 VirtualBox 在哪里可以找到它。瞧!
您没有问,但我希望您能看到您实际上可以将所有代码放入此文件中;只需在后面添加要从后面的扇区链式加载的代码0xaa55
,您就可以简单地将其加载到内存中,因为您知道它位于下一个扇区的开头。