0

请注意,我是引导加载程序和程序集的菜鸟,所以我一直在关注一些(可能不是最好的)示例。我正在为一个项目在 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
4

1 回答 1

0

多亏了 mbratch 的评论,我已经设法让它工作了。因为es没有设置,es:bp所以不要指向我的字符串,而是指向内存中的某个随机位置。

答案是设置es为 0,因为我使用的是绝对地址(即 7c00h)。这仅org 7c00h在开头有 时才有效。如果您不想/不能使用orgset esto 7c0h.

所以,要么:

org 7c00h
mov ax, 0
mov es, ax

或者:

mov ax, 7c0h
mov es, ax 

我从http://wiki.osdev.org/Babystep2获得信息,从 mbratch 获得想法。

于 2013-09-17T14:28:25.653 回答