【发布时间】:2012-05-21 06:07:20
【问题描述】:
我在 Windows 7 上使用 VirtualBox 4.1.14,并试图让它运行我的测试操作系统。我正在使用下面的汇编代码,并使用
编译它nasm -f bin -o boot.bin boot.asm
我正在尝试将生成的 bin 文件转换为 VB4.1.14 可以使用的 ISO(我不想花钱或受到试用程序的任何限制)。我曾尝试下载不同的转换器,如 bin2iso,但每当我尝试打开其中生成的 ISO 时,VB 都会出现不同的错误,如 VERR_NOT_SUPPORTED 等。
我希望该解决方案是一个命令行工具,这样我就可以在批处理脚本中使用它来加快测试速度。
BITS 16
start:
mov ax, 07C0h ; Set up 4K stack space after this bootloader
add ax, 288 ; (4096 + 512) / 16 bytes per paragraph
mov ss, ax
mov sp, 4096
mov ax, 07C0h ; Set data segment to where we're loaded
mov ds, ax
mov si, text_string ; Put string position into SI
call print_string ; Call our string-printing routine
jmp $ ; Jump here - infinite loop!
text_string db 'This is my cool new OS!', 0
print_string: ; Routine: output string in SI to screen
mov ah, 0Eh ; int 10h 'print char' function
.repeat:
lodsb ; Get character from string
cmp al, 0
je .done ; If char is zero, end of string
int 10h ; Otherwise, print it
jmp .repeat
.done:
ret
times 510-($-$$) db 0 ; Pad remainder of boot sector with 0s
dw 0xAA55 ; The standard PC boot signature
【问题讨论】:
-
只是一个建议。但是大多数与此类似的示例都将指令“cli”放在开始标签之后以关闭可屏蔽的外部中断。您可能也想考虑这样做。
-
虽然我会指出,由于您在这里执行无限循环,因此实际上不需要使用“cli”指令。该指令最常用作处理器同步工具,以避免驱动程序和内核之间的竞争条件。当与“hlt”指令结合使用时,它也常用于暂停系统。与您使用的无限循环相比,使用“cli”然后“hlt”通常是有意停止系统的首选方法。
标签: assembly operating-system virtualbox nasm bin