assembly - 引导扇区与 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: 最后我得到了正确的输出。检查评论线程以获取解决方案。
解决方案
推荐阅读
- python - 如何在不创建本地副本的情况下从在线 gzip 文件中读取数据?
- lambda - 如何为 serverless.yml 中的所有功能设置默认授权人
- html - 根据父 div 更改嵌套子 div
- php - Codeigniter - 不显示任何数据
- arrays - 使用Angular从具有另一组值的数组中查找匹配值的最佳方法
- c# - 如何通过 linq 查询读取所有代码并保存到单个集合中
- android - 在我按下android中的按钮之前如何使任何视图增长。(kotlin或java无关紧要)?
- php - 提交 POST 表单后使用 PHP 顺利重新加载表格
- javascript - 如何在javascript中比较两个日期
- javascript - 捕获匹配的第一个或第二个实例