Message board for the users of flat assembler.
> DOS > How to align?
Id like someone to explain to me, why and how we use 'align'. maybe someone could also point me to a place where can find further info on it too.
|23 Feb 2004, 10:32||
The align directive itself is described in 2.2.3 section in FASM Manual. Why to use it? Well... generally speaking, it can be useful in some situations, like when you are optimizing our code, it's good to align it to 16-byte boundary. For more info on optiomizing the code (with aligment) you can refer to Intel Manuals. Also, sometimes you must align some code or data. But this is a rare situation, you just have to put align directive for example when you are creating some executable manually.
|23 Feb 2004, 10:45||
Plz correct me if I'm wrong about any of this, but:
called procedures should be aligned at 16 because
when the proc is called the CPU has to load the address
and if it's aligned there are less steps that the CPU has to go through
to get IP loaded with the address.
Same with words, use align 2,
align 4 for Dwords
bytes don't need to be aligned.
One example I heard went like this:
to load a word that isn't aligned even, the CPU loads a word & gets a byte
then loads a word, and gets the other byte
those two bytes make up the word being fetched.
If the word is aligned, the CPU just loads the word.
Valid alignments are:
When a proc is aligned at 16, Fasm pads to a hex address than ends in zero=0
any hex address that ends in 0 is aligned at 16
NOP = 90h = 144 is the value of the padding inserted,
it's character looks like a capitol E with a ' above it like E'
but it's all one character.
You can view assembled code and see the arrays of NOP padding
these are wasted bytes unless you use them.
Since I align proc's and they are all together,
I can just move my DB or DW data inbetween the procs after I've got my
code working & debugged.
This uses the wasted bytes. I also put
DW 0x0A0D ;=crlf 2 bytes
inbetween the procs, then assemble the .asm
I then can see them all lined up on the left margin.
So they are easy to then utilize.
With todays CPU speed, alignment isn't a necessity,
but I do it anyway, and why not, it's easy.
Just take 5 minutes to use the wasted bytes after the program runs.
|24 Feb 2004, 08:09||
< Last Thread | Next Thread >
Copyright © 1999-2020, Tomasz Grysztar.
Powered by rwasa.