首页 > 解决方案 > 引导扇区与 qemu 一起工作正常,但在计算机上引导时不打印任何内容

问题描述

我正在编写一个启动扇区,它会打印一条消息“Hello world”。并进入无限循环。我正在使用 int 0x10 打印消息的字符。

我已经使用 nasm 组装了代码并在 qemu 上对其进行了测试。它工作正常并显示消息。我还使用命令将引导扇区复制到 USB 驱动器

dd if=welcome_message of=/dev/sdb bs=512 count=1

并使用 qemu 从 USB 驱动器启动

qemu-system-x86_64 /dev/sdb

显示消息。但是当我重新启动我的电脑并从 USB 启动时,它启动但没有显示任何内容。光标确实根据消息的长度向前移动,但没有显示任何内容。我错过了什么?似乎显示了字符,但不知何故它们不可见。我附上了代码

;Print a welcome message after booting

[org 0x7c00]    ;BIOS loads this code at 0x7c00

mov ah, 0x0e    ;For Using BIOS to print a character

mov cl, len ;Used as counter inside the loop, so load with length

inc cl

mov si, welcome       ;Used as pointer to the character string

loop:

mov al, [si]    ;get the character in al

int 0x10    ;Print the character

inc si       ;Point to next character

dec cl        ;Decrement counter

jnz loop    ;Keep printing until you reach end of the welcome message

jmp $       ;Loop forever


welcome: db "Hello World ."

len equ $-welcome

times 510 - ($-$$) db 0     ;Put 0s till 510

dw 0xaa55

EDIT 0: 将 DS 设置为 0 开始打印。但有些字符没有打印出来。预期的输出是“Hello World!” 但我得到“Hel orld”。可能是什么问题?

;Print a welcome message after booting
[bits 16]
[org 0x7c00]    ;BIOS loads this code at 0x7c00
mov ax, 0
mov ds, ax  ;Initialize data segment register
mov ah, 0x0e    ;For Using BIOS to print a character
mov cl, len ;Used as counter inside the loop, so load with length
inc cl
mov si, welcome
loop:
mov al, [si]    ;get the character in al
int 0x10    ;Print the character
inc si
dec cl
jnz loop    ;Keep printing until you reach end of the welcome message
jmp $       ;Loop forever

welcome: db "Hello World!"
len equ $-welcome
times 510 - ($-$$) db 0     ;Put 0s till 510
dw 0xaa55

编辑1: 最后我得到了正确的输出。检查评论线程以获取解决方案。

标签: assemblyx86-16bootloaderbiososdev

解决方案


推荐阅读