flat assembler
Message board for the users of flat assembler.

Index > Main > align macro (or algorithm)

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
hi, can't find good old align macro.

i just need to formula to calculate, how many bytes to fill to align something to some given value Smile
Post 07 Jun 2006, 13:36
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
bytesToFill = $ mod alignValue ?
Post 07 Jun 2006, 13:44
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
no, byt maybe alignval - ($ mod alignval) seems a little better, except case when $ mod alignval is 0. I want that elegant form from old align macro Smile
Post 07 Jun 2006, 13:54
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Quantum



Joined: 24 Jun 2005
Posts: 122
Quantum
(($ + alignval - 1) and -alignval) - $

BTW, what happened to good old align directive?
Post 07 Jun 2006, 14:20
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
it's not for FASM coding. i just needed algorithm.

good not-that-old align directive is still working
Post 07 Jun 2006, 14:22
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
it's not for FASM coding. i just needed algorithm.

good not-that-old align directive is still working

thanks
Post 07 Jun 2006, 14:28
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Quantum



Joined: 24 Jun 2005
Posts: 122
Quantum
And not-that-good (unless I'm the only one missing howto insert a custom byte value instead of the predefined 90h). Nops look kind of weird inside a data block.
Post 07 Jun 2006, 15:19
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
And using NOPs in code is not too much efficient neither, anyway you can override align with your own macro
Code:
macro align alignval {rb (($ + alignval - 1) and -alignval) - $}    


However make sure of use it on data sections because it reserves and initialize with zeroes if more data follows the align (which is the most probable).

[edit]
Code:
macro align alignval, customval
{
if customval eq
  align alignval
else
  times (($ + alignval - 1) and -alignval) - $ db customval
end if
}    
But note this one if you use align but then no more data comes the customval will be written anyway while the original align works in the same way that the first align macro but initializes with 90h instead.[/edit]
Post 07 Jun 2006, 16:03
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
Section 2.2.5 contains of fasm's manual an example how you can customize the alignment in any way you want. It's quite easy to make into macro.

And the so-called "good old align macro" you can find as one of the first examples in the 2.3.3 section.

I know, nobody reads it, but it still contains a few useful things, you know. Wink
Post 07 Jun 2006, 16:50
View user's profile Send private message Visit poster's website Reply with quote
Quantum



Joined: 24 Jun 2005
Posts: 122
Quantum
2 locodelassembly and Tomasz Grysztar:
I already knew that, but thanks anyway. The point is I never asked for a macro solution. align is a directive, not a macro. I don't like macros at all. But that's only my very humble personal opinion.

2 locodelassembly:
Quote:

However make sure of use it on data sections because it reserves and initialize with zeroes if more data follows the align (which is the most probable)

People usually store uninitialized data in a block storage space section (BSS) or any other virtually extended (bss-like) place of another section (data/text). So, I'm not sure I understand your tip.
Post 07 Jun 2006, 19:52
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
I know, nobody reads it, but it still contains a few useful things, you know. Wink

because we don't know what remained and what has changed. i don't want to read entire 200kb pure text file to find 0.05% of new things...
Post 07 Jun 2006, 20:10
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
Actually the "align" macro was there for all the time, even in the previous manual.
Post 07 Jun 2006, 20:13
View user's profile Send private message Visit poster's website Reply with quote
amcl



Joined: 08 May 2006
Posts: 5
amcl
Quantum wrote:

People usually store uninitialized data in a block storage space section (BSS) or any other virtually extended (bss-like) place of another section (data/text).


Sorry my response is offtopic, useless and pedantic, but BSS stands for 'Block Started by Symbol'.

http://en.wikipedia.org/wiki/.bss
Post 07 Jun 2006, 20:29
View user's profile Send private message Reply with quote
Quantum



Joined: 24 Jun 2005
Posts: 122
Quantum
2 amcl:
Quote:

BSS stands for 'Block Started by Symbol'

That's what many people believe (including D. Ritchie). But I prefer the former definition (mentioned somewhere by M. Pietrek). Oh, and never trust a wiki Wink
Post 07 Jun 2006, 21:18
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:

So, I'm not sure I understand your tip.

That is because my english is terrible. I'd tried to say that never use my align macro on code sections because it will pad with zeroes which is a problem if those zeroes gets executed. And about the second macro (which has the same problem with code section unless you use a valid single byte opcode as customval or not pass a customval), the problem is if you have a source like this:
Code:
macro align alignval, customval
{ 
if customval eq 
  align alignval 
else 
  times (($ + alignval - 1) and -alignval) - $ db customval 
end if 
}

db 1
align 16, 0    
Will produce a 16 byte binary file while the original align (the directive) will be only a 1 byte binary file.
Post 08 Jun 2006, 01:59
View user's profile Send private message Reply with quote
Quantum



Joined: 24 Jun 2005
Posts: 122
Quantum
2 locodelassembly:
Quote:

I'd tried to say that never use my align macro on code sections because it will pad with zeroes which is a problem if those zeroes gets executed

I see know. Well, a piece of padding code not intended to be executed should be filled with 0xCC bytes instead of 0x90's. At least MS VC guys think so.

Quote:

And about the second macro

That was clear from the beginning. Another little minus goes to macros Wink

Quote:

That is because my english is terrible.

I whouldn't say that. Mine is worse. Mi español es un poco mejor. What really matters is that we finally understood each other.
Post 08 Jun 2006, 02:36
View user's profile Send private message Reply with quote
shism2



Joined: 14 Sep 2005
Posts: 248
shism2
There was someone on this forum who made a macro which calculates the necessary alignment. I don't remember who and how to find it. But it was on here before.
Post 08 Jun 2006, 02:53
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Yep but the problem is that align is normally used to align loops where the preceding bytes will normally get executed.
Code:
mov ecx, someValue
align 16
.loop:
dec .loop
jnz .loop    

The bytes between "mov ecx, someVal" and .loop (if any) will be executed so apropiate opcodes are requiered here. Anyway good point about $CC, it could be used when you align PROCs.

Si no has entendido dime y seguimos por PM en español así no te confundo más Wink

Regards
Post 08 Jun 2006, 03:18
View user's profile Send private message Reply with quote
shism2



Joined: 14 Sep 2005
Posts: 248
shism2
ta hablodo a mi ?
Post 08 Jun 2006, 04:34
View user's profile Send private message Reply with quote
Quantum



Joined: 24 Jun 2005
Posts: 122
Quantum
2 locodelassembly:
Quote:

Yep but the problem is that align is normally used to align loops where the preceding bytes will normally get executed.

In case of loops, nops ain't always the best solution. For example, instead of 2 consecutive nops it's more efficient to place a mov eax,eax.
Post 08 Jun 2006, 16:10
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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 GitHub, YouTube, Twitter.

Website powered by rwasa.