News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

about align

Started by ecube, February 18, 2008, 12:51:29 PM

Previous topic - Next topic

ecube

can someone please explain about align? I see align 16, align 8 etc... the questions I have are

What does align do?
Is align ever a requirement?
How do you know the best number to align by?

hutch--

Cuibe,

Depending on the processor, data is fetched on one grab if the data is aligned by at least 4 bytes. This means it evenly divides by 4. With code its less important but can still play a part at times, usually labels are aligned in code if you test some advantage from doing so.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Tedd

It inserts 'space' (NOP for code, 0 for data) so that the current offset becomes evenly divisible by the given number - so the next instruction/data lies on an 'aligned' address.
It's rarely a requirement, though some instructions (mainly SSE) and certain structures do need it (and they generally cause an exception if you don't play along.)
The appropriate alignment depends on what you're aligning and why. A simple rule is to align by the size of the data you're aligning - so words at align-2, dwords at align-4, qwords at 8, etc - this simply helps the processor access the data in a single operation. There can be certain performance benefits by aligning particular data/functions/jump-destinations, which again just helps the processor and its caches. It's sometimes good to align functions to 16, but in general it won't make noticable difference (unless you call the function a lot) and you shouldn't worry too mcuh about it.
No snowflake in an avalanche feels responsible.