我使用Bochs模拟器来运行一个引导扇区,该扇区在NASM中编码如下:
org 07c00h ;told the compiler to load the code to 0x7c00h
mov ax, cs
mov ds, ax
mov es, ax
call DispStr ;call the string process
jmp $ ;infinite loop
DispStr:
mov ax, BootMessage
mov bp, ax ;ES:BP = string address
mov cx, 16 ;CX = length of the string
mov ax, 01301h ;AH = 13, AL = 01H
mov bx, 000ch ;(BH = 0)
mov dl, 0
int 10h ;10h interrupt
ret
BootMessage: db "Hello, OS world!" ;message printed
times 510-($-$$) db 0 ;fill the left of the 510 byte with 0
dw 0xaa55
如果times 510-($-$$) db 0
被禁止,有没有其他方法可以用0填充510字节区域的左侧?
我尝试过循环命令,但无法正常工作。
另一种方法是使用预处理器循环(%rep
):
%rep 510-($-$$)
db 0
%endrep
如果你的TA仍然不满意,我会让你仔细阅读NASM手册,寻找实现同样目标的其他可能方法。