flat assembler
Message board for the users of flat assembler.

Index > DOS > How to align?

Author
Thread Post new topic Reply to topic
keyoke



Joined: 18 Jun 2003
Posts: 56
Location: London
keyoke 23 Feb 2004, 10:32
hey guys,
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.
thanks alot
Post 23 Feb 2004, 10:32
View user's profile Send private message Visit poster's website Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 23 Feb 2004, 10:45
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.

regards
Post 23 Feb 2004, 10:45
View user's profile Send private message Visit poster's website Reply with quote
Bitdog



Joined: 18 Jan 2004
Posts: 97
Bitdog 24 Feb 2004, 08:09
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:
2,4,16,256,4096

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.

Bitdog
Post 24 Feb 2004, 08:09
View user's profile Send private message 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.