flat assembler
Message board for the users of flat assembler.

Index > Main > align filler like in NASM's "align 2, db 0"

Author
Thread Post new topic Reply to topic
alexfru



Joined: 23 Mar 2014
Posts: 80
alexfru 01 Feb 2020, 06:20
Is there an equivalent to the NASM's
Code:
align 2, db 0    

?

This fills the alignment padding with a specified byte value. I don't want the default 0x90 (NOP) in the data section.

There's this example in the documentation:
Code:
    virtual
        align 16
        a = $ - $$
    end virtual
    db a dup 0
    

but I'd really appreciate a one liner (or hide the above behind a macro), so I can use it many times as easily as the regular align directive.

How do I do that?
Post 01 Feb 2020, 06:20
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 817
Location: Russian Federation, Sochi
ProMiNick 01 Feb 2020, 06:46
in https://board.flatassembler.net/topic.php?t=21339 I already post it
Code:
macro align boundary,value:? { db (boundary-1)-($+boundary-1) mod boundary dup value }    
I grab it from https://board.flatassembler.net/topic.php?t=20690 where it realized in fasmg syntax
use case
align 2 ; same as "align 2, db ?" i think "db ?" more convinient then "db 0"
align 2,0 ; same as "align 2, db 0"
align 2,$90 ; same as "align 2, db $90"

b.t.w. nice work - https://github.com/alexfru/Win16asm
Post 01 Feb 2020, 06:46
View user's profile Send private message Send e-mail Reply with quote
alexfru



Joined: 23 Mar 2014
Posts: 80
alexfru 01 Feb 2020, 07:30
ProMiNick wrote:
in https://board.flatassembler.net/topic.php?t=21339 I already post it
Code:
macro align boundary,value:? { db (boundary-1)-($+boundary-1) mod boundary dup value }    
I grab it from https://board.flatassembler.net/topic.php?t=20690 where it realized in fasmg syntax
use case
align 2 ; same as "align 2, db ?" i think "db ?" more convinient then "db 0"
align 2,0 ; same as "align 2, db 0"
align 2,$90 ; same as "align 2, db $90"


Something isn't quite right:

Code:
format elf

macro xyzalign boundary,value:? { db (boundary-1)-($+boundary-1) mod boundary dup value }

section ".data"

public datum
datum:
  db 0x41
;  align 2
xyzalign 2,0
    


Code:
>fasm align.asm
flat assembler  version 1.71.64  (16384 kilobytes memory)
align.asm [11]:
xyzalign 2,0
align.asm [3] xyzalign [0]:
macro xyzalign boundary,value:? { db (boundary-1)-($+boundary-1) mod boundary dup value }
processed: db(2-1)-($+2-1)mod 2 dup 0
error: invalid use of symbol.
    


or

Code:
flat assembler  version 1.71.22  (1048576 kilobytes memory)
align.asm [3]:
macro xyzalign boundary,value:? { db (boundary-1)-($+boundary-1) mod boundary dup value }
error: invalid macro arguments.
    


ProMiNick wrote:
b.t.w. nice work - https://github.com/alexfru/Win16asm


Thanks.
Post 01 Feb 2020, 07:30
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 817
Location: Russian Federation, Sochi
ProMiNick 01 Feb 2020, 07:40
looks like fasm 1.71 dosn`t know default values for macro parameters ":?".
Use fasm 1.73.21

From educational side unzeroed bytes for alignment is more correct - it separate bytes that are part of some data constructions from realy alignment bytes.
Post 01 Feb 2020, 07:40
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 01 Feb 2020, 07:56
If you use fasmg's formatters, the ALIGN macro supports second argument (filler) as a standard.

Also, please take a look here and here for more advanced ones. But they are all for fasmg - if you need to stick to fasm 1, please look at some old ones.
Post 01 Feb 2020, 07:56
View user's profile Send private message Visit poster's website Reply with quote
alexfru



Joined: 23 Mar 2014
Posts: 80
alexfru 01 Feb 2020, 08:01
ProMiNick wrote:
looks like fasm 1.71 dosn`t know default values for macro parameters "Confused".
Use fasm 1.73.21


Well, that didn't help:
Code:
>fasm align.asm
flat assembler  version 1.73.21  (1048576 kilobytes memory)
align.asm [11]:
xyzalign 2,0
align.asm [3] xyzalign [0]:
macro xyzalign boundary,value:? { db (boundary-1)-($+boundary-1) mod boundary dup value }
processed: db(2-1)-($+2-1)mod 2 dup 0
error: invalid use of symbol.
    


ProMiNick wrote:
From educational side unzeroed bytes for alignment is more correct - it separate bytes that are part of some data constructions from realy alignment bytes.

The PE format wants imported function names start on 2-byte boundary and have zero bytes as trailing and padding. In theory I could manually add enough zeroes, but I don't want to.
Post 01 Feb 2020, 08:01
View user's profile Send private message Reply with quote
alexfru



Joined: 23 Mar 2014
Posts: 80
alexfru 01 Feb 2020, 08:25
Tomasz Grysztar wrote:
if you need to stick to fasm 1, please look at some old ones.


At first glance .balign from there seems to be working...
Post 01 Feb 2020, 08:25
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 817
Location: Russian Federation, Sochi
ProMiNick 01 Feb 2020, 10:21
alexfru wrote:

Well, that didn't help:
strange
Code:
C:\Documents and Settings\Administrator>\..\fasmw17321COMFRIENDLY\fasm.exe "C:\fasmw17321COMFRIENDLY\EXAMPLES\WIN16\1.ASM"
flat assembler version 1.73.21 (1048576 kilobytes memory)
3 passes, 74356 bytes.

C:\Documents and Settings\Administrator>pause
Press any key to continue . . .    

I used same align macro in my sample.

_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.
Post 01 Feb 2020, 10:21
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 01 Feb 2020, 10:26
ProMiNick wrote:
strange
It does not work when address value ($) is not absolute (in other words when it is relocatable, as in object formats or PE with fixups). And this is discussed in section 1.2 (Adding relocations) of the tutorial you mentioned as a source of this macro.
Post 01 Feb 2020, 10:26
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 817
Location: Russian Federation, Sochi
ProMiNick 01 Feb 2020, 11:24
for elf: macro xyzalign boundary,value:? { db (boundary-1)-($-$$+boundary-1) mod boundary dup value }
Post 01 Feb 2020, 11:24
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 01 Feb 2020, 11:37
ProMiNick wrote:
for elf: macro xyzalign boundary,value:? { db (boundary-1)-($-$$+boundary-1) mod boundary dup value }
Remember about the section alignment!
Post 01 Feb 2020, 11:37
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.