I've been trying to increase my baseline knowledge of Intel x86 Nasm by working on outputting a hardcoded text string in an OS/Kernel real mode environment using BIOS interrupts.
Here's my code:
top:
[BITS 16]
[ORG 7C00h]
resb 56 ; Just for testing
outStr db "This is a test string!", 10, 0
resb 56
.main:
main:
mov edi, outStr
again:
mov BYTE al, [edi]
mov ah,0Eh
int 10h
inc edi
cmp BYTE [edi], 0
jg again
leaving:
mov ah, 0Eh
mov al,13
int 10h
mov al,10
int 10h
mov al,'Q' ; Using the distinct character Q to show that the code executed to this point
int 10h
complete:
hlt
times (510-($-top)) db 0 ; Pad the executable to act as the boot sector
dw 0xAA55
I have actually gotten it to work, but only with certain strings. Changing the contents of outStr
will sometimes cause the code to not execute at all. At first I thought it was the length, but this proved not to be a determining factor; a small handful of random characters, "Gfd" for example, outputs fine, but "Gfd is awesome!" mysteriously does not work. On the other hand, "ABCDEFGH...Z" (the full capitalized alphabet) did work. To make things even weirder, the full lowercase alphabet did not work.
Anytime it doesn't work, the confirmation character at the end ("Q") is not outputted, and non of the other expected behavior is observed, further leading me to believe that this has nothing to do with my executable code, but with something else.
Important: I've been doing my testing using QEMU. It seems to be a pretty commonly used tool and works for me (with the above exceptions), but I'll be interested to see if this could have some effect on the output.