Assembly Using Variables
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?
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.
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
链接地址: http://www.djcxy.com/p/15896.html
上一篇: 使用div指令的x86 NASM程序集中的浮点异常
下一篇: 装配使用变量