flat assembler
Message board for the users of flat assembler.

Index > Main > Amount of output so far ?

Author
Thread Post new topic Reply to topic
pini



Joined: 04 Jul 2005
Posts: 14
pini 06 Sep 2011, 12:09
Hi folks,

After years of silence, I'm back to fasm and it still rocks.

I'm trying to write an MBR so I need my code to relocate itself before loading the bootsector of the active partition.
Basically, I'd like to do it by having the following layout :

Code:
format binary
use16

org A
; copy MBR to whatever
; jmp to whatever:B

org B
; chainload    


As it works well, what I'd like to ask is more a feature request : as I need to pad my code until offset 0x1be (from the beginning of the file, this is where the partition table is to be located), I need to define labels at the beginning and end of the first part (because $$ refers to the second org), so that I can pad with

Code:
times 0x1be - ($ - $$) - (A.end - A.start) db 0    


Basically, I'd like to write something like

Code:
times 0x1be - ($$$) db 0    


With $$$ (or whatever) being the number of bytes written to output so far, in all address spaces.

How hard would it be to add such a special value ?
And if it's easy, could it be considered for inclusion in fasm ?

Thanks a lot.
Post 06 Sep 2011, 12:09
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8392
Location: Kraków, Poland
Tomasz Grysztar 06 Sep 2011, 12:28
Code:
format binary
use16 

_$$ = 0
_$ equ (_$$+$-$$)
macro org address { _$$ = _$
                    org address }

org A
; copy MBR to whatever 
; jmp to whatever:B 

org B 
; chainload

times 0x1be - _$ db 0
    
Post 06 Sep 2011, 12:28
View user's profile Send private message Visit poster's website Reply with quote
pini



Joined: 04 Jul 2005
Posts: 14
pini 06 Sep 2011, 13:07
Oh sweet !

Thanks.

/EDIT/ It could be a good idea to evaluate the address before updating _$$ in the macro definition just in case it's based on _$, as in
Code:
macro org address {
   local a
   a = address
   _$$ = _$
   org a
}    
Post 06 Sep 2011, 13:07
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.