flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Align to Boundary

Author
Thread Post new topic Reply to topic
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy
align ebx,16 => align value of EBX to the 16th boundary...
Code:
macro align reg,bound {
  if reg in <eax,ecx,edx,ebx,esp,ebp,esi,edi>
    ; 32-bit
    add reg,bound-1
    and reg,0ffffffffh-(bound-1)
  else if reg in <ax,cx,dx,bx,sp,bp,si,di>
    ; 16-bit
    add reg,bound-1
    and reg,0ffffh-(bound-1)
  else
    ; 8-bit
    add reg,bound-1
    and reg,0ffh-(bound-1)
  end if
}    
Post 16 Sep 2005, 19:51
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
this is kind of macro which IMHO isn't very good to use in real coding. you don't align registers often, and "and eax,FFFFFFF0h ;align to 16 bytes" is more readable than searching source for what exactly overloaded align does.
ps: check for [] type of "reg", eg. "align [aaa],16"
Post 18 Sep 2005, 23:24
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: 7756
Location: Kraków, Poland
Tomasz Grysztar
And why not just:
Code:
macro align reg,bound { add reg,bound-1
                        and reg,not(bound-1) }    

?
Post 18 Sep 2005, 23:30
View user's profile Send private message Visit poster's website Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy
Thnx Tomasz (didn't think of it)...
Post 19 Sep 2005, 06:11
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: 17475
Location: In your JS exploiting you and your system
revolution
Better is one that allows the use of normal align also
Code:
macro align reg,[bound] {
if ~ bound eq
add reg,bound-1 
and reg,not(bound-1)
else
align reg
end if
}    
BTW: What happens for this?
Code:
align eax,3    
Perhaps you should also check if the bound is a power of 2?

So now we modify the macro to this.
Code:
macro align reg,[bound] {
if ~ bound eq
add reg,1 shl bound-1 
and reg,not(1 shl bound-1)
else
align reg
end if
}    
Post 19 Sep 2005, 08:05
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.