用于将字符串打印到屏幕的汇编程序

问题描述 投票:0回答:1

我有这个程序,想要将字符串写到屏幕上,但是输出为空,我在每一行都添加了注释。

[org 0x7c00] ; Tell the assember the place to load this code

    mov bx, HELLO_MSG ; move the data to the bx register
    pusha             ; push all register values to stack?
    call printstr     ; call printstr routine

printstr:
    mov ah, 0x0e ; BIOS teletype output
    pop bx       ; pop to bx
    mov al, bl   ; put low byte of bx to al
    int 0x10     ; print it.
    cmp al, 0    ; Compare if its a string termination character?
    jne printstr ; if not go back to top
    ret          ; return to the caller?


; Data
HELLO_MSG:
    db 'Hello world!', 0

jmp $

times  510-($-$$) db 0
dw  0xaa55
assembly nasm
1个回答
0
投票

POP BX指令没有执行您似乎假定的操作。它从堆栈中获取一个值并将其存储在BX中。它不访问BX指向的内存。您需要类似MOV AL, [BX]的内容来检索由BX指向的字符,然后是使BX指向下一个字符的指令。

© www.soinside.com 2019 - 2024. All rights reserved.