I've been looking into OS development, and have been working on a bootsector, trying to get it to print to the screen.
[org 0x7c00]
; Print 'Hello World' to the screen
mov bx, MSG
call print_string
; Hang
jmp $
; Includes
%include "boot_sect_print.asm"
; Global Variables
MSG: db "Hello World", 0
; Padding
times 510-($-$$) db 0
; Magic Number
dw 0xaa55
And here's the print function code:
; Print a string from bx
print_string:
pusha
; Loop through and print each character
start:
mov al, [bx]
cmp al, 0
je done
mov ah, 0x0e
int 0x10
add bx, 1
jmp start
done:
popa
ret
It's working perfectly when I run it on an emulator (qemu), but when I put the code on a usb and boot my PC from it some strange behavior is occurring. I've confirmed that printing works, because if I move a single character into 'al' then call 'int 0x10' it prints fine on my PC. However, when accessing a string from memory, 'MSG' in this case, rather than loading the correct values from memory, it's loading something different, and thus not printing correctly. I did some testing and it appears to be getting 255 (0xff) from the first byte at 'MSG' rather than 'H'. I don't really know what to do it at this point, because it seems to work on fine on qemu but not on an actual PC.