我无法打印出汇编中的字符 [英] I can't print out a character in assembly

查看:36
本文介绍了我无法打印出汇编中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习 x86 汇编.我正在尝试制作一个玩具操作系统.我尝试打印出输入的字符,但失败了.输入有问题吗?还是在输出中?我已将 AH 设置为 0x0E 并使用 int 0x10 但它仍然不起作用.为什么它不起作用?

I'm trying to learn x86 assembly. I'm trying to make a toy OS. I tried printing out a character that was inputted but it failed. Is there something wrong in the input? Or in the output? I have set AH to 0x0E and used int 0x10 but it still doesn't work. Why doesn't it work?

注意:我对汇编很陌生,所以如果我在文本或代码中有错误,请不要说我有多笨.

Note: I'm very new to assembly, so if I got something wrong in the text or in the code, please don't say how dumb I am.

char:
    db 0
mov ah, 0
int 0x16

mov ah, 0x0e
mov al, [char]
int 0x10

jmp $

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

推荐答案

char:
    db 0
mov ah, 0

在汇编中,您需要将数据存储在执行代码之外.在此引导加载程序中,执行从您放置数据项的顶部开始.CPU 会尝试将其解释为一条指令,但它会失败(大多数情况下).

In assembly, you need to store the data out of the way of the executing code. In this bootloader, execution started at the top where you placed a data item. The CPU will try to interpret it as an instruction but it will fail (most of the time).

我尝试打印出输入的字符

I tried printing out a character that was inputted

一旦您接收到字符作为输入,您仍然需要将其实际存储在标记为 char 的内存中.如果你不这样做,那么指令 mov al, [char] 将没有任何有用的东西可以获取!

Once you receive the character as input, you still need to actually store it in the memory labeled char. If you don't, then the instruction mov al, [char] won't have anything useful to fetch!

请注意,在引导加载程序中,您负责设置段寄存器.您的代码取决于正确的 DS 段寄存器.因为您没有使用 ORG 指令,所以 DS 的正确值将是 0x07C0.

Please note that in a bootloader, you are responsible to setup the segment registers. Your code depends on a correct DS segment register. Because you didn't use an ORG directive, the correct value for DS will be 0x07C0.

BIOS.Teletype 函数 0x0E 在 BHBL 中有附加参数.不要忽视这些.

And the BIOS.Teletype function 0x0E has additional parameters in BH and BL. Don't ignore these.

mov ax, 0x07C0
mov ds, ax

mov ah, 0       ; BIOS.GetKeyboardKey
int 0x16        ; -> AL charactercode, AH scancode
mov [char], al

mov bx, 0x0007  ; BH is DisplayPage (0), BL is GraphicsColor (White)
mov ah, 0x0E    ; BIOS.Teletype
mov al, [char]
int 0x10

jmp $

char:   db 0

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

这篇关于我无法打印出汇编中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆