引导加载程序不断将 eax 添加到 al

Boot loader keeps adding eax to al

我正在尝试构建我的第一个引导加载程序,它确实有效,但根据 gdb 的说法,还有一件事我不明白。

这是我用 nasm 编写的引导加载程序:

org 0x7c00
bits 16
start: jmp boot

msg db "Bootinggggg!", 0

Print:
lodsb ;loading si to al
cmp al,0 ;loop
je PrintDone
mov ah,0eh
mov bl,14 ;yellow color
int 10h
jmp Print 

PrintDone:
ret

boot:
mov ah,00h
mov al,0eh
int 10h ;stepping into graphic mode
mov si,msg
call Print
cli
cld
hlt


times 510-($-$$) db 0
dw 0xAA55 

我在我的 unbuntu 机器上使用 qemu 并可视化 8086 架构。在 gdb 中使用 ni 命令几次后,gdb 显示程序只是无休止地将 eax 添加到 al。我按了很多次 ni,它一直在添加它。但是当我按下继续时,它确实起作用了,正如您所看到的,它打印了字符串。为什么会这样?

您正在拆解空白内存。 00 00add %al, (%eax)add [eax], al的编码。您可以使用 this online disassembler

轻松检查
0:  00 00                   add    BYTE PTR [eax],al

请注意,该指令不是将 eax 添加到 al。它将 al 添加到 eax

指向的地址处的值