【问题标题】:simple boot sector coding: Filling the 512 Byte with 0简单的引导扇区编码:用 0 填充 512 字节
【发布时间】:2016-07-27 23:01:35
【问题描述】:

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

我试过循环命令,但不能正常工作。

【问题讨论】:

  • "If times 510-($-$$) db 0 if disabled" 为什么会被禁止?
  • @Michael 但是我们操作系统课的助手让我们想出一个可选的方法来填补空白......
  • 嗯。对我来说听起来像是在浪费时间。这是 OS 类还是 NASM 指令类?
  • 一个使用 NASM 进行实验的 OS 类
  • 助教在浪费你的时间。在 OS 开发类中,有比如何使用 rep 与 $-$$ 更重要的事情。

标签: x86 nasm boot


【解决方案1】:

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

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

如果您的 TA 仍然不满意,我会让您通过 NASM 手册来挖掘实现相同目标的其他可能方法。

【讨论】:

    猜你喜欢
    • 2015-12-29
    • 1970-01-01
    • 2021-09-03
    • 2017-12-04
    • 2018-01-14
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    相关资源
    最近更新 更多