1

我正在尝试使文本屏幕打印存储在变量中的“h”。我正在使用 NASM。x86 保护模式,一个从头开始的内核。

显示消息:
        ;mov 字节[颜色], 0xF
        ;mov CFC, EAX;
        ;mov 字节[颜色], 104
        ;推104
        ;mov 字节[esi], 消息
        ;lodsb
        mov ebx, 消息
        添加 ebx, 4
        mov [消息], eax
        移动字节[0xB8000],消息
        ;mov byte[eax], 颜色
        ;弹出字节[0xB8000]
        ;mov byte[0xB8000], 字节颜色
        ;mov 字节[0xB8000], 0xB500000;
        ;现在返回
        ret
结束代码:
消息:分贝 104

它显示的字母永远不会正确。这样做的正确方法是什么?

4

2 回答 2

9
    mov ebx, Msg ; this loads ebx with the address of Msg, OK
    add ebx, 4 ; this increments the address by 4, OK, but why?
    mov [Msg], eax ; this stores eax into the first 4 bytes of Msg, OK, but why?
    mov byte[0xB8000], Msg ; this writes the least significant byte of the
                           ; address of Msg to the screen, not OK.
                           ; Does not make any sense.

为什么不只是?:

mov al, [Msg]
mov [0xB8000], al

Msg这应该在屏幕的左上角写入第一个字符('h' 的 ASCII 码 104,正确),当然,如果您的数据段在其段描述符中的基地址为 0,并且如果你org是正确的。

于 2012-09-30T08:13:35.797 回答
0

VGA 文本模式使用地址0xB8000作为数组,uint16_t高字节用于颜色,低字节为字符代码。当前,您将字符存储在高字节中,而低字节未触及。打印随机字符的可能是随机噪声。尝试这个:

DisplayMessage:
mov al, byte [msg]
mov ah, 0x0F ;White Text on Black Background
mov word [0xB8000], ax
ret
于 2018-04-01T23:15:35.570 回答