【发布时间】:2017-08-06 11:43:46
【问题描述】:
我正在学习关于操作系统开发的book by Nick Blundell。它在第 3 章中有一个示例。引导扇区编程(在 16 位实模式下),如下所示:
;
; A simple boot sector program that demonstrates addressing.
;
mov ah, 0x0e ; int 10/ ah = 0eh -> scrolling teletype BIOS routine
; First attempt
mov al, the_secret
int 0x10 ; Does this print an X?
; Second attempt
mov al, [the_secret]
int 0x10 ; Does this print an X?
; Third attempt
mov bx, the_secret
add bx, 0x7c00
mov al, [bx]
int 0x10 ; Does this print an X?
; Fourth attempt
mov al, [0x7c1e ]
int 0x10 ; Does this print an X?
jmp $ ; Jump forever.
the_secret :
db "X"
; Padding and magic BIOS number.
times 510 -( $ - $$ ) db 0
dw 0xaa55
书中提到:
如果我们运行程序,我们会看到只有后两次尝试打印成功 一个“X”。
嗯,这不是我得到的结果:
$ nasm BOOK_EXAMPLE.asm -f bin -o BOOK_EXAMPLE.bin
$ qemu-system-i386 BOOK_EXAMPLE.bin
我的结果是这样的:
这暗示我的 QEMU BIOS 仅在第三次尝试时打印“X”。我没有修改本书的例子,我想知道我错过了什么。
更新
我的二进制代码的对象转储显示“X”的十六进制 ASCII 代码,即 0x58 位于内存地址 0x7c00+0x001d=0x7c1d
$ od -t x1 -A x BOOK_EXAMPLE.bin
000000 b4 0e b0 1d cd 10 a0 1d 00 cd 10 bb 1d 00 81 c3
000010 00 7c 8a 07 cd 10 a0 1e 7c cd 10 eb fe 58 00 00
000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*
0001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa
000200
因此我用以下代码替换了一行代码:
mov al, [0x7c1d ]
现在输出如预期:
【问题讨论】: