2016-12-17 62 views
2

我使用NASM這是我的代碼:INT 10H 13H BIOS字符串輸出不工作

org 0x7c00 
bits 16 



section .data 
zeichen dw 'hello2' 
section .text 


mov ax,0x7c00 
mov es,ax 
mov bh,0 
mov bp,zeichen 

mov ah,13h 
mov bl,00h 
mov al,1 
mov cx,6 
mov dh,010h 
mov dl,01h 

int 10h 

jmp $ 

times 510 - ($-$$) hlt 
dw 0xaa55 

它並把光標放在合適的位置,但不打印輸出。 我使用qemu-system-i386加載此文件。 int10 ah = 13h是一個字符串輸出,並在寄存器es中:bp必須是字符串的地址

+0

不止一個問題。你必須更好地理解segment:offset尋址,但是一個bootloader被加載到物理地址0x07c00。您必須選擇一個等於該地址的ORG和分段。如果選擇ORG 0x7c00,則需要將段(本例中爲_ES_)設置爲零,因爲(0x0000 << 4)+ 0x7c00 = 0x07c00(物理地址)。您正在使用0x7c00加載_ES_,這對您選擇的_ORG_不正確。 –

+0

其次,當使用'-f bin' _NASM_輸出時,您不想使用'.data'節。將數據放在代碼後面的'text'部分內,但在引導簽名之前。如果使用'section data',NASM將實際將數據放在引導扇區之外的字節512之後。 –

+0

您將_BL_設置爲0x00。這是黑色的黑色,所以不會顯示輸出。也許嘗試0x07? –

回答

1

爲了將來的參考,因爲我一直試圖讓這個工作很長一段時間,這裏是一個工作版本!

org 0x7c00 
    bits 16 

    xor ax, ax 
    mov es, ax 
    xor bh, bh 
    mov bp, msg 

    mov ah, 0x13 
    mov bl, [foreground] 
    mov al, 1 
    mov cx, [msg_length] 
    mov dh, [msg_y] 
    mov dl, [msg_x] 

    int 0x10 

    hlt 

foreground dw 0xa 
msg db 'Beep Boop Meow' 
msg_length dw $-msg 
msg_x dw 5 
msg_y dw 2 

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

這裏是最接近原始的版本。

org 0x7c00 
    bits 16 

    ; video page number. 
    mov bh, 0  
    ; ES:BP is the pointer to string. 
    mov ax, 0x0 
    mov es, ax  
    mov bp, msg 

    ; attribute(7 is light gray). 
    mov bl, 0x7 
    ; write mode: character only, cursor moved. 
    mov al, 1 
    ; string length, hardcoded. 
    mov cx, 6 
    ; y coordinate 
    mov dh, 16 
    ; x coordinate 
    mov dl, 1 

    ; int 10, 13 
    mov ah, 0x13 
    int 0x10 

    ; keep jumping until shutdown. 
    jmp $ 

msg dw 'hello2' 

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