flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > align directive not working correct for big values ?

Author
Thread Post new topic Reply to topic
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
I found some problem with the align directive.

Following discription found in docs:

Quote:

align directive aligns code or data to the speci ed boundary. It should be
followed by a numerical expression specifying the number of bytes, to the
multiply of which the current address has to be aligned. The boundary value
has to be the power of two.



Quote:

virtual
align 16
a = $ - $$
end virtual
db a dup 0


I write cdr boot layout with FASM and have to fill some sectors, sectorsize 2048 bytes (800h). When I try to fill the sectors with following function align does not fill sector complete. I don't know why. Maybe this is a bug.

My own macro function is:

Quote:

macro fillsector modval,fill
{
virtual
align modval
a=$-$$
end virtual
db a dup fill
}


The following workaround code fills sector correct.

Quote:

macro fillsector2 begaddr,endaddr,modval,fill
{
db (modval-((endaddr-begaddr) mod modval)) dup fill
}


Here I use labels begadr (begin of code) end endaddr (end of code) for calculation.
fillsector2 works fine, fillsector has a functional bug.

Just for discussion, maybe somebody has an idea whats wrong.

Has align any dependencies from org directive ?
In my code I use directive org 7c00h+50h

When calling fillsector the sector fill is missing exact 50h bytes.
So sector is filled up to 7af not up to 7ff.

I dont understand why align references to org (if my suspicion is true).
Align 800h should be 800h in all cases and should not fail when org directive is 100h for example.

Maybe somebody can bring some light in my confusion.
Could live with workaround in fillsector2 but want to understand align in general.
Shocked
Post 03 Apr 2010, 23:25
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16861
Location: In your JS exploiting you and your system
revolution
By using org 7c50h you are telling the assembler that the code will be loaded at that address in memory. So later when you use align 800h you are telling the assembler to align the next byte at that next 2kB boundary. The next 2kB boundary is 0x8000h.
Code:
org 0x7c50
db 1
align 0x800 ;0x3af bytes of padding
db 2    
Post 04 Apr 2010, 02:08
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7438
Location: Kraków, Poland
Tomasz Grysztar
fasm's ALIGN is by definition memory-wise, thus it is affected by ORG and family. Perhaps it's not stated clearly enough in the manual, I may correct it.
Post 06 Apr 2010, 14:54
View user's profile Send private message Visit poster's website Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
Well sometime it helps to ask a question in the forum to find the answer myself. So in the night after writing my post it got clear to me. Building a general question helps finding the answer sometimes.

Sure ORG has to affect align, what else ???

I thought of a possible error but then I found that i missed exact 50h bytes. This corresponds to my offset ORG xxxx+50h.

I wrote first a bootloader and because it's getting to big for putting on a hard disk including partition table I wrote a preloader to load the rest. And loaded it +50h bytes and then made a relocation of code. That caused the problem because the second code has ORG +50h but was loaded in a new sector at address "0". So I missed exact 50h bytes. I correct this with a manual fill "db 50h dup 0".

Sorry for disturbing community with this bad question.
Embarassed
Post 06 Apr 2010, 21:47
View user's profile Send private message Send e-mail Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 490
Location: Belarus
zhak
there are no stupid (bad) questions - there are lost (unclear) points. Wink
Post 06 Apr 2010, 22:44
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-2019, Tomasz Grysztar.

Powered by rwasa.