首页 文章

使用变量进行装配

提问于
浏览
1

我试图让文本屏幕打印'h',它存储在一个变量中 . 我正在使用NASM . x86保护模式,一种从头开始的内核 .

DisplayMessage:
        ;mov byte[Color], 0xF
        ;mov CFC, EAX;
        ;mov byte[Color], 104
        ;push 104
        ;mov byte[esi], Msg
        ;lodsb
        mov ebx, Msg
        add ebx, 4
        mov [Msg], eax
        mov byte[0xB8000], Msg
        ;mov byte[eax], Color
        ;pop byte[0xB8000]
        ;mov byte[0xB8000], byte Color
        ;mov byte[0xB8000], 0xB500000;
        ;Now return
        ret
EndCode:
Msg: db 104

它显示的字母永远不对 . 什么是正确的方法来做到这一点?

2 回答

  • 0
    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 是对的 .

  • 9

    VGA文本模式使用地址 0xB8000 作为 uint16_t 的数组 . 上部字节用于颜色,下部字节是字符代码 . 目前,您将字符存储在高位字节中,而低位字节则不受影响 . 可能是随机噪声打印随机字符 . 试试这个:

    DisplayMessage:
    mov al, byte [msg]
    mov ah, 0x0F ;White Text on Black Background
    mov word [0xB8000], ax
    ret
    

相关问题