flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > zeroalign directive

Author
Thread Post new topic Reply to topic
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
http://board.flatassembler.net/topic.php?t=1570 Jibz "align with 00h bytes?"
http://board.flatassembler.net/topic.php?t=8632 Grom PE "Raw PE format again"

Any chance for the zeroalign directive in FASM 1.70 ?
Post 23 Oct 2010, 07:59
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji

Fasm by default uses "nop" to align.
It's true that it would be nice to be able to choose the value of padding byte.

align x,y : align 4,0 - align 10h,0CCh


(Yes, i agree, we can do this with a macro)


and without the second parameter, the default form.

align x == align x(,90h)

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 23 Oct 2010, 09:27
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
fasm manual, section 2.2.5:
Quote:
If you need to fill the alignment area with some other values, you can combine align with virtual to get the size of alignment needed and then create the alignment yourself, like:
Code:
    virtual
        align 16
        a = $ - $$
    end virtual
    db a dup 0    


And it's easy to make it into macro (I leave it as an exercise to the reader). Wink You may also need to replace "0" with "?" if you plan to use that align in reserved data space as well.
Post 23 Oct 2010, 10:38
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17287
Location: In your JS exploiting you and your system
revolution
Here you go:
Code:
macro align ment*,dat {
     local a
     if ~ dat eq
         virtual
                     align ment
                  a=$-$$
              end virtual
         db a dup dat
        else
                align ment
  end if
}    
Works with ? for dat also.


Last edited by revolution on 23 Oct 2010, 11:29; edited 1 time in total
Post 23 Oct 2010, 11:20
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
But it fails to emulate the standard "align" directive properly. You should just make it fall back to default "align" directive when "dat" is empty.
Post 23 Oct 2010, 11:27
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17287
Location: In your JS exploiting you and your system
revolution
Tomasz Grysztar wrote:
But it fails to emulate the standard "align" directive properly. You should just make it fall back to default "align" directive when "dat" is empty.
Thank you. I edited it.
Post 23 Oct 2010, 11:30
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Tomasz Grysztar wrote:
If you need to fill
the alignment area with some other values, you can combine align
with virtual to get the size of alignment needed and then create the alignment yourself, like:
Code:
 virtual
 align 16
 a = $ - $$
 end virtual
    


Thanks, I've been aware of this
(see many of my examples),
still, an "internal" solution
would be cool.

PS: of course it could be even
worse:

http://www.bttr-software.de/forum/forum_entry.php?id=8979
Shocked
Post 24 Oct 2010, 00:49
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
http://www.bttr-software.de/forum/forum_entry.php?id=8979 wrote:
> 2. There are some aligns inside the binary and they contain random garbage
> rather than ZERO's. Is it documented anywhere that the aligns are expected
> and how they are supposed to work ?

Yes. These may be filler bytes used for segment alignment. They aren't written, there's just a file positioning, so the values may be OS-dependent.

This is expected behavior.

Ugh, that's NASTY - I once had pieces of source code show up in an executable because the compiler didn't zero out allocated memory...
Post 24 Oct 2010, 16:05
View user's profile Send private message Visit poster's website Reply with quote
Japheth



Joined: 26 Oct 2004
Posts: 151
Japheth
f0dder wrote:
http://www.bttr-software.de/forum/forum_entry.php?id=8979 wrote:
> 2. There are some aligns inside the binary and they contain random garbage
> rather than ZERO's. Is it documented anywhere that the aligns are expected
> and how they are supposed to work ?

Yes. These may be filler bytes used for segment alignment. They aren't written, there's just a file positioning, so the values may be OS-dependent.

This is expected behavior.

Ugh, that's NASTY - I once had pieces of source code show up in an executable because the compiler didn't zero out allocated memory...


It works ok, because there are no "random" values under Windows, Linux or MS-DOS. It's just a few wannabee-DOS-compatible OSes like FreeDOS or EDR-DOS which - once more - take this opportunity to prove that they are toys.
Post 25 Oct 2010, 05:43
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.