OSDev.org
https://forum.osdev.org/

My program works in QEMU, not on real machine
https://forum.osdev.org/viewtopic.php?f=13&t=33788
Page 1 of 1

Author:  Tomaspecl [ Thu Jul 25, 2019 9:31 am ]
Post subject:  My program works in QEMU, not on real machine

I have made a simple program in asm:

Code:
bits 16
org 0x7C00

start:
mov ah, 0xE
mov al, "a"
int 0x10

stop:
jmp stop

times 510-($-$$) db 0
dw 0xAA55


I compiled it with NASM (nasm test1.txt), then I used program HexWorkshop to copy it to my flash drive at sector 0 (boot sector). Then I plugged the flash drive to my computer and booted from it. It printed
Code:
a

just as I expected.

Then I tried to make some more complicated programs. For those I needed to store some data in memory. These programs did not work at all, only in QEMU. (I will not post them here becouse they are quite long). Later I found that problems were caused when I was using data from RAM (like storing and reading variables). I have made a simple modification of the program at the top of this post:

Code:
bits 16
org 0x7C00

start:

mov [letter], byte "a"
mov ah, 0xE
mov al, [letter]
int 0x10

stop:
jmp stop

letter:   db 0

times 510-($-$$) db 0
dw 0xAA55


I compiled it with NASM (nasm test2.txt), then I tested it with QEMU-it worked. It printed same as test1. But when I tried to run it on real computer it did not work-it just moved cursor (looked like it printed space). I have no idea why it works like that. Can you explain me why it does this?

Author:  iansjack [ Thu Jul 25, 2019 9:52 am ]
Post subject:  Re: My program works in QEMU, not on real machine

You have not initialized the segment registers. You shouldn't assume a particular value for them.

Author:  Tomaspecl [ Thu Jul 25, 2019 10:05 am ]
Post subject:  Re: My program works in QEMU, not on real machine

iansjack wrote:
You have not initialized the segment registers. You shouldn't assume a particular value for them.

Thanks! All of my programs work now.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/