以16位实模式打印字符串

时间:2019-05-06 15:58:03

标签: assembly nasm x86-16 real-mode

我正在学习如何在16位实模式下工作。我目前正在尝试打印字符串。当前,我的print函数输出一个空字符。有人在这里看到问题吗?

clearscreenmovecursor函数正常工作。

boot_sect.asm

[bits 16]
[global _start]

; globals
msg: db "Hello, World!", 0

_start:
  call clearscreen

  push 0x0
  call movecursor

  push msg
  call print

  jmp $

; includes
%include "boot/16bit/console.asm"

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

console.asm


clearscreen:
    push bp
    mov bp, sp
    pusha

    mov ah, 0x07        ; tells BIOS to scroll down window
    mov al, 0x00        ; clear entire window
    mov bh, 0x07        ; white on black
    mov cx, 0x00        ; specifies top left of screen as (0,0)
    mov dh, 0x18        ; 18h = 24 rows of chars
    mov dl, 0x4f        ; 4fh = 79 cols of chars
    int 0x10            ; calls video interrupt

    popa
    mov sp, bp
    pop bp
    ret

movecursor:
    push bp
    mov bp, sp
    pusha

    mov dx, [bp+4]      ; get the argument from the stack. |bp| = 2, |arg| = 2
    mov ah, 0x02        ; set cursor position
    mov bh, 0x00        ; page 0 - doesn't matter, we're not using double-buffering
    int 0x10

    popa
    mov sp, bp
    pop bp
    ret

print:
    push bp
    mov bp, sp
    pusha
    mov si, [bp+4]      ; grab the pointer to the data
    mov bh, 0x00        ; page number, 0 again
    mov bl, 0x00        ; foreground color, irrelevant - in text mode
    mov ah, 0x0E        ; print character to TTY
.char:
    mov al, [si]        ; get the current char from our pointer position
    add si, 1           ; keep incrementing si until we see a null char
    or al, 0
    je .return          ; end if the string is done
    int 0x10            ; print the character if we're not done
    jmp .char           ; keep looping
.return:
    popa
    mov sp, bp
    pop bp
    ret



我希望输出“ Hello,World!”,但是我目前正在得到这个:

output

0 个答案:

没有答案