【发布时间】:2013-09-16 21:26:21
【问题描述】:
请注意,我是引导加载程序和程序集的菜鸟,所以我一直在关注一些(可能不是最好的)示例。 我正在为一个项目在 NASM 中编写引导加载程序。它只是在屏幕上打印一个字符串并等待 Enter 键。输入后它加载另一个扇区并打印第二个字符串。在 VBox 中进行测试非常棒:字符串已打印,一切正常。
在真实计算机上对其进行测试后,我得到的不是第一个字符串,而是垃圾。第二个程序运行良好。 我正在使用自定义脚本写入软盘。全部在 Linux Mint 下完成。 如有错误请见谅。
org 7c00h
start:
jmp short begin ; jump over the DOS boot record data
;----------------------------------------------------------------------
; data portion of the "DOS BOOT RECORD"
; ----------------------------------------------------------------------
;DOS data goes here
;------------------------------------------------------------------------
mesaj db "Some string here" ,10
len equ $-mesaj
begin:
mov ah, 0
mov al, 03h
int 10h
mov ah, 13h
mov al, 0
mov cx, len
mov bh, 0h
mov bl, 02h
mov bp, mesaj
mov dl, 20
mov dh, 12
int 10h ;printing the string
read:
xor ah, ah
int 16h ; read a key from keyboard
cmp al, 0
jz read ; if special key, continue reading
mov ah, 0Ah
mov cx, 100
mov bh, 0
int 10h ; write keyboard character to screen
cmp al, 0dh ; if character is Enter, load second program
jne read
; loading the second sector
mov ax, 0x500
mov es, ax
mov al, 1
mov ch, 0
mov cl, 2
mov dh, 0
mov dl, 0
xor bx, bx
mov ah, 2
int 0x13
jmp 0x500:0
【问题讨论】:
-
“打印字符串”服务要求字符串指针位于
es:bp。我看到你在哪里设置bp。你在哪里设置es? -
我没有设置。如前所述,我对组装很陌生。由于在 VirtualBox 中一切正常,如果我阅读的示例在打印前设置了 es,我认为我不需要设置它...
-
通话文档显示
es:bp。有可能在 VirtualBox 中,es恰好设置为您需要的(例如,可能设置为等于ds)。不过,你不能这样假设。最好遵守文档。
标签: assembly nasm bootloader