简单引导扇区编码:用0填充512字节

时间:2016-04-07 07:46:45

标签: x86 nasm boot

我使用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字节区域的左边?

我尝试过循环命令,但无法正常工作。

1 个答案:

答案 0 :(得分:1)

另一种方法是使用预处理器循环(%rep):

%rep 510-($-$$)
db 0
%endrep

如果您的技术支持人员仍然不满意,我会留下您通过NASM手册深入了解实现相同目标的其他可能方法。

相关问题