flat assembler
Message board for the users of flat assembler.

 Index > Macroinstructions > Align to Boundary
Author
Tommy

Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy 16 Sep 2005, 19:51
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
and reg,0ffffffffh-(bound-1)
else if reg in <ax,cx,dx,bx,sp,bp,si,di>
; 16-bit
and reg,0ffffh-(bound-1)
else
; 8-bit
and reg,0ffh-(bound-1)
end if
}
16 Sep 2005, 19:51
vid
Verbosity in development

Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 18 Sep 2005, 23:24
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"
18 Sep 2005, 23:24
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 8346
Location: Kraków, Poland
Tomasz Grysztar 18 Sep 2005, 23:30
And why not just:
Code:
macro align reg,bound { add reg,bound-1
and reg,not(bound-1) }

?
18 Sep 2005, 23:30
Tommy

Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy 19 Sep 2005, 06:11
Thnx Tomasz (didn't think of it)...
19 Sep 2005, 06:11
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 20170
revolution 19 Sep 2005, 08:05
Better is one that allows the use of normal align also
Code:
macro align reg,[bound] {
if ~ bound eq
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
and reg,not(1 shl bound-1)
else
align reg
end if
}
19 Sep 2005, 08:05
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum