OSDev.org

The Place to Start for Operating System Developers
It is currently Mon Oct 14, 2019 1:07 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: My program works in QEMU, not on real machine
PostPosted: Thu Jul 25, 2019 9:31 am 
Offline

Joined: Thu Jul 25, 2019 8:58 am
Posts: 2
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?


Top
 Profile  
 
 Post subject: Re: My program works in QEMU, not on real machine
PostPosted: Thu Jul 25, 2019 9:52 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 3501
Location: Chichester, UK
You have not initialized the segment registers. You shouldn't assume a particular value for them.


Top
 Profile  
 
 Post subject: Re: My program works in QEMU, not on real machine
PostPosted: Thu Jul 25, 2019 10:05 am 
Offline

Joined: Thu Jul 25, 2019 8:58 am
Posts: 2
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group