1
votes

I am trying to make the text screen print 'h' which is stored in a variable. I am using NASM. x86 Protected Mode, a from scratch kernel.

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

The letter it displays is never right. Whats the proper way to do this?

2
Mine. Its x86 Protected mode, from scratch.civilwarrock
so we have to assume that your OS has the text video page mapped to address 0xB8000? And we have to assume that the video card is in text mode?dthorpe
what's the point of including all the commented out code? it just makes it harder to understand what you're trying to do.dthorpe
It was just code that doesn't work. Just left it there for reference. I will remove it once I get this working. =)civilwarrock

2 Answers

9
votes
    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.

Why not just?:

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

This should write the very first character of Msg ('h' has ASCII code 104, correct) at the top-left corner of the screen, if, of course, your data segment has the base address of 0 in its segment descriptor, and if your org is correct.

0
votes

VGA text mode uses address 0xB8000 as an array of uint16_t With the upper byte being used for color, and the lower byte being the character code. Currently you are storing the character in the upper byte and the lower byte is untouched. It may be random noise that is printing a random character. Try this:

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