flat assembler
Message board for the users of flat assembler.

Index > Main > org $ & bootsectors

Author
Thread Post new topic Reply to topic
anthill



Joined: 22 Jun 2004
Posts: 2
anthill 23 Jun 2004, 01:34
I have been trying to write a boot sector, and the most confusing problem I have had is how to get the boot signature- 0AA55h
- to offset 510 in the output.
In various forums I found this--

org 7c00h
bootstart:

Some code......
more code..
ditto
ditto

times 510-($-bootstart) db 0h
dw 0AA55h

---Which works, but seemed needlessly complex.
This--times 510-$ db 0h
---did not work, and I could not find a reasonable explanation for it.
And because I like to understand my code, I did some playing and came up with this explanation.....

The org directive simply resets the output location counter- $ to its argument, in this case--
7c00h
--which is equivalent to the more self explanatory--
$=7c00h
.
This--times 510-$ db 0h-- does not work because $, is at this point, equal to 7c00h plus the length of the already compiled code--
Some code......
more code..
ditto
ditto
--
Thus $ is obviously a larger value than 510, 510-$ will be negative, and you cannot repeat someting (times 510-$ db 0h)
a negative number of times.

To sum up, a more self explanatory piece of code would look something like--
$= 7c00h

Some code......
more code..
ditto
ditto

times 510-($-7c00h) db 0h
dw 0AA55h
Post 23 Jun 2004, 01:34
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 23 Jun 2004, 10:53
Quote:

To sum up, a more self explanatory piece of code would look something like--
$= 7c00h

Some code......
more code..
ditto
ditto

times 510-($-7c00h) db 0h
dw 0AA55h


What about this:
Code:
org 7c00h
. . . . Some code . . . . 
times (7c00h+510)-$ db 0
db 0AA55h 
    


It will fail to compile if the boot sector code is >510 bytes, but otherwise works perfectly.

_________________
Charles Childers, Programmer
Post 23 Jun 2004, 10:53
View user's profile Send private message Visit poster's website Reply with quote
neonz



Joined: 02 Aug 2003
Posts: 62
Location: Latvia
neonz 26 Jun 2004, 20:31
I'm using:

Code:
org 7C00h
. . . .  some code . . . .
rb 7C00h+512-2-$
dw 0AA55h
    
Post 26 Jun 2004, 20:31
View user's profile Send private message Visit poster's website Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 27 Jun 2004, 00:43
Quote:

I'm using:

org 7C00h
. . . . some code . . . .
rb 7C00h+512-2-$
dw 0AA55h


Why the 512-2? Wouldn't the following code also work?

Code:
    org 7C00h
    . . . .  some code . . . .
    rb 7C00h+510-$
    dw 0AA55h 
    

_________________
Charles Childers, Programmer
Post 27 Jun 2004, 00:43
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 27 Jun 2004, 06:58
Also, if you make the one more step to the simplification:

Code:
    org 7C00h
    . . . .  some code . . . .
    rb 7DFEh-$
    dw 0AA55h 
    
Post 27 Jun 2004, 06:58
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
neonz



Joined: 02 Aug 2003
Posts: 62
Location: Latvia
neonz 27 Jun 2004, 13:19
crc wrote:
Why the 512-2? Wouldn't the following code also work?


512-2 looks better IMHO Smile

Yes, theoretically it slows down compile time Wink, but I like to have readable source code.
Post 27 Jun 2004, 13:19
View user's profile Send private message Visit poster's website 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.