flat assembler
Message board for the users of flat assembler.

Index > OS Construction > SI explanation please

Author
Thread Post new topic Reply to topic
ring0



Joined: 14 Mar 2005
Posts: 15
Location: Australia
ring0
Hi,
I am trying to learn ass by writing a boot sector & am confused by the results i get from using SI. Some code to illustrate:

Code:
use16
org 0x7C00

start16: jmp near begin

 -----------------
      BPB here
 -----------------

begin: 

cli
xor   ax, ax
mov  ds, ax
mov  ss, ax
mov  sp, 0x7C00
mov  [driveNo], dl
sti

mov  si, prompt
mov  ax, prompt

more code here

prompt   db  '>', 0    



My questions:
1/ The value i get for si and ax is different - why? (I believe ax is correct)
2/ Given that the bios will always load this code at 7C00 what is the effect of ORG?

TIA

moderator: please use [ code ] tags.
Post 14 Mar 2005, 11:18
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7756
Location: Kraków, Poland
Tomasz Grysztar
ring0 wrote:
1/ The value i get for si and ax is different - why? (I believe ax is correct)

It is the same when you write it like this. Probably you've got some mistake elsewhere.

ring0 wrote:
2/ Given that the bios will always load this code at 7C00 what is the effect of ORG?

When you define some labels in your source, the assembler needs to know where the resulting code will be loaded into memory to give them the correct values, and you use the ORG directive to tell the right base address to the assembler. You would use ORG 100h for the .COM program binary, for example.
See also the section 2.2.3 of the fasm's manual.
Post 14 Mar 2005, 13:32
View user's profile Send private message Visit poster's website Reply with quote
Scanner



Joined: 14 May 2005
Posts: 7
Scanner
Yip, the 'more code' sections is probably the problem.

As for the ORG. Change it and have a look at the resulting list file, you will notice that the 'mov ax,prompt' lines will refer to different addresses because the origin of the code has been changed. The assembler needs to know the origin of the code for instructions such as the mov mentioned because it refers to an address that is dependant on the location of the code.
Post 14 May 2005, 12:09
View user's profile Send private message Yahoo Messenger Reply with quote
bubach



Joined: 17 Sep 2004
Posts: 341
Location: Trollhättan, Sweden
bubach
When you use org 0x7c00 and do something like: "mov ax, prompt" it's "translated" to "mov ax, prompt + 0x7c00" since both CS and DS points to zero.
If you where to use ORG 0, you would have to point both CS and DS to 0x07C0 instead (for it to work)...
Post 16 May 2005, 10:58
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.