The alignment directives align the current location in the file to a specified boundary.
This specifies the number of bytes that must be aligned to. This must be a power of 2.
This specifies the alignment boundary as an exponent. The actual alignment boundary is
The value to fill any inserted padding bytes with. This value is optional.
The alignment directives align the current location in the file to a specified boundary. The unused space between the previous and the new current location are filled with:
- Copies of
fill_value, if it is specified. The width of
fill_valuecan be controlled with the
lsuffixes, see below.
- NOP instructions appropriate to the current instruction set, if all the
following conditions are specified:
fill_valueargument is not specified.
lsuffix is not specified.
- The alignment directive follows an instruction.
- Zeroes otherwise.
.balign directive takes an absolute number of bytes as
its first argument, and the
takes a power of 2. For example, the following directives align the current location
to the next multiple of 16 bytes:
l suffixes modify the width of
the padding value that will be inserted.
- By default, the
fill_valueis a 1-byte value.
- If the
wsuffix is specified, the
fill_valueis a 2-byte value.
- If the
lsuffix is specified, the
fill_valueis a 4-byte value.
If either of these suffixes are specified, the padding values are emitted as data (defaulting to a value of zero), even if following an instruction.
.align directive is an alias for
.p2align, but it does not accept the
Alignment is relative to the start of the section in which the directive occurs. If the current alignment of the section is lower than the alignment requested by the directive, the alignment of the section will be increased.
Use the alignment directives to ensure that your data and code is aligned to appropriate boundaries. This is typically required in the following circumstances:
- In T32 code, the ADR instruction and the PC-relative version of the LDR
instruction can only reference addresses that are 4-byte aligned, but a label
within T32 code might only be 2-byte aligned. Use
.balign 4to ensure 4-byte alignment of an address within T32 code.
- Use alignment directives to take advantage of caches on some Arm
processors. For example, many processors have an instruction cache with 16-byte
.balign 16to align function entry points on 16-byte boundaries to maximize the efficiency of the cache.
Aligning a constant pool value to a 4-byte boundary in T32 code:
get_val: ldr r0, value adds r0, #1 bx lr // The above code is 6 bytes in size. // Therefore the data defined by the .word directive below must be manually aligned // to a 4-byte boundary to be able to use the LDR instruction. .p2align 2 value: .word 42
Ensuring that the entry points to functions are on 16-byte boundaries, to better utilize caches:
.p2align 4 .type func1, "function" func1: // code .p2align 4 .type func2, "function" func2: // code