这是我的代码: http://pastebin.com/pSncVNPK
[BITS 16] ;Tells the assembler that its a 16 bit code
[ORG 0x7C00] ;Origin, tell the assembler that where the code will
;be in memory after it is been loaded
MOV SI, HelloString ;Store string pointer to SI
CALL PrintString ;Call print string procedure
JMP $ ;Infinite loop, hang it here.
PrintCharacter: ;Procedure to print character on screen
;Assume that ASCII value is in register
AL MOV AH, 0x0E ;Tell BIOS that we need to print one charater on screen.
MOV BH, 0x00 ;Page no.
MOV BL, 0x07 ;Text attribute 0x07 is lightgrey font on black background
INT 0x10 ;Call video interrupt RET ;Return to calling procedure
PrintString: ;Procedure to print string on screen
;Assume that string starting pointer is in register SI
next_character: ;Label to fetch next character from string
MOV AL, [SI] ;Get a byte from string and store in AL register
INC SI ;Increment SI pointer
OR AL, AL ;Check if value in AL is zero (end of string)
JZ exit_function ;If end then return
CALL PrintCharacter ;Else print the character which is in AL register
JMP next_character ;Fetch next character from string
exit_function: ;End label
RET ;Return from procedure
;Data
HelloString db 'Hello World', 0 ;HelloWorld string ending with 0
TIMES 510 - ($ - $$) db 0 ;Fill the rest of sector with 0
DW 0xAA55 ;Add boot signature at the end of bootloader
如您所见,语法似乎是正确的,将其编译成 .bin 文件,但我正在尝试弄清楚如何测试它。请像对待我有点慢一样对待我,因为我花了 HOURS 谷歌搜索这个主题但似乎没有任何效果,我什至尝试按照一些教程使用十六进制编辑器但它没有用。这似乎是我得到的最接近的是使用这些说明: http://puu.sh/6KzUo.png
来自此链接:How to make an bootable iso(not cd or flash drive) for testing your own boot loader?
除了我不太明白第 6 步,因为 VM box 不允许我选择 img 文件作为可启动磁盘。
谢谢!
最佳答案
如果您只需要在磁盘 Controller 中添加一张软盘,可以这样做:
点击软盘 Controller 。带有绿色加号的软盘图标应该出现在您选择的左侧。点击这个小图标。
现在应该出现一个对话框:
选择“选择磁盘”
将出现文件选择框---此时,从文件选择框中选择您的.img
文件。
从现在开始,您应该能够从软盘启动虚拟机并测试您的引导加载程序。
关于linux - 如何在软盘上测试引导加载程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21570017/