Nasm int 10h 13h bios字符串输出不工作

Nasm int 10h 13h bios字符串输出不工作,nasm,x86-16,bootloader,bios,Nasm,X86 16,Bootloader,Bios,我正在使用nasm,以下是我的代码: 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 i

我正在使用nasm,以下是我的代码:

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必须是字符串的地址

,以备将来参考,因为我已经尝试使其工作了很长时间,这里有一个工作版本

    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

不止一个问题。您必须更好地理解段:偏移地址,但引导加载程序是在物理地址0x07c00处加载的。您必须选择与该地址相等的组织和部门。如果选择ORG 0x7c00,则需要将段(在本例中为ES)设置为零(0x0000secondary当使用
-f bin
NASM输出时,您不想使用
.data
节。将数据放在
文本
节中代码之后但引导签名之前。如果使用
节数据
NASM将实际将数据放在引导扇区外字节512之后。您将BL设置为0x00。That是黑色对黑色的,所以不会显示输出。尝试0x07可能吗?最后。我想你是想使用
db
而不是
dw
,因为你有一个字符串。将
zeichen dw'hello2'
更改为
zeichen db'hello2'
感谢对其工作的帮助
msg_length dw$-msg
-通常你会nt使用eq常量作为立即数,而不是从内存中实际加载长度。idk但如果它仍然有效,则符合我的目的,因为我肯定不再记得这一点,我花了大量的尝试和错误来制作引导iso并在virtualbox中运行它们,以确保我是诚实的。/但我确信一定有某种方法可以做到这一点equ也是。在本例中,我想借此机会练习使用内存访问,而不会使virtualbox崩溃。是的,它可以工作,但会浪费空间。加载它的指令需要一个2字节的绝对地址,而它也可以直接使用2字节的立即数,如
mov cx,msg_length
from<代码> >代码>代码,运行时不需要改变,所以通常要把它当作C++ +>代码> COSTEXPRESSIEXT LEN SIZEOF(MSG);< /C> >代替<代码>静态siZeLT Le= sieZof(MSG);<代码>