What does the .align directive do?
I am learning x86 and I am trying to understand what the .align directive does and how it might be useful.
The Oracle Reference Manual says:
The .align directive causes the following data to be aligned modulo integer bytes. The integer must be a positive integer expression and must be a cardinality of 2. If specified, pad is the integer value of the byte used for padding. Default value for pad for text section is 0x90 (nop); for other sections, the default value for the pad is zero (0).
But I'm not sure what that means. Could you please refer to where I can learn more about this or explain it briefly with an example?
source to share
The key to understanding what he's doing is to understand why he's there.
All computers have a natural border known as collocation. This boundary is usually 4 bytes or 8 bytes.
The processor can load and save from memory faster and avoid wasting cache space when 4 and 8 bytes are at these boundaries. Some CPU types cannot receive values that do not match.
Thus, there must be a mechanism in assembler that skips the next boundary so that the label directive and storage allocation directives can start at a more efficient address.
For instructions, odd boundaries work on most computers, but they still have performance implications and waste cache space.
.string "ab\0"
; this next address is 3
against
.string "ab\0"
.align 4 # sometimes interpreted as 2**n, so, .align 2
; this next address is 4, and would still be 4 if the string was just "a"
source to share