i made this code, this should be simple OS, that should print "Hello world!".
msg: db "Hello world!",0
times 510-($-$$) db 0
I assembled that on NASM.
When i run it on QEMU, it prints one strange character, and 'S'.
I ran QEMU with those arguments
"qemu-system-x86_64 ost.bin" where "ost.bin" is that file.
Does anybody know solution?
There are several problems in your code:
bits 16 mov bx, msg
msg now contains only offset of your message from start of output binary. You can solve this problem by either adding
msg or setting program origin (start in memory,
call printstr printstr: mov al,byte[bx]
BX is not good register for indexing strung characters, as it contains color (lower byte) and page (higher byte) information.
mov ah,0Eh int 10h
You don't have to set
0x0E everytime you print a character. It can be done on the start of code.
inc bx cmp byte[bx], 0
In this kind of loops, you should first check value, and then process it. What would you do if character on
BX+0 was equal to
0? You would miss that fact and that would cause wrong output or even endless loop.
je end jmp printstr
This will surely cause endless loop, as you already are in that procedure.
end: jmp end
Prefered syntax is
jmp $ (where dollar sign means "here").
msg: db "Hello world!",0 times 510-($-$$) db 0 dw 0xaa55
You have to insert "org 7c00h" at the beginning of the code.
And also, you have to stop the program after printing, or else it will fall into printstr procedure once again.
Maybe something like:
sleep: hlt jmp sleep
The main problem seems to be that the segment registers (DS and ES) are not initialized.
The "org 7C00h" is not required; the program may also start at address 100h (ideal for DOS .COM files) or 0h. Depending on the start address the segment registers must be initialized to 7C0h (org 0h), 7B0H (org 100h) or 0 (org 7C00h).
The "jmp sleep" instruction at the end is sufficient; a "HLT" instruction is definitely not needed.