My program works in QEMU, not on real machine

Programming, for all ages and all languages.
Post Reply
Tomaspecl
Posts: 2
Joined: Thu Jul 25, 2019 8:58 am

My program works in QEMU, not on real machine

Post by Tomaspecl »

I have made a simple program in asm:

Code: Select all

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: Select all

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: Select all

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?
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: My program works in QEMU, not on real machine

Post by iansjack »

You have not initialized the segment registers. You shouldn't assume a particular value for them.
Tomaspecl
Posts: 2
Joined: Thu Jul 25, 2019 8:58 am

Re: My program works in QEMU, not on real machine

Post by Tomaspecl »

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.
Post Reply