| |||
| Home > Directives Reference > Miscellaneous directives > ALIGN | |||
The ALIGN directive aligns the current location
to a specified boundary by padding with zeros.
ALIGN{expr{,offset{,pad}}}
where:
expris a numeric expression evaluating to any power of 2 from 20 to 231.
offsetcan be any numeric expression.
padcan be any numeric expression.
The current location is aligned to the next address of the form:
offset + n * expr
If is
not specified, exprALIGN sets the current location to the
next word (four byte) boundary.
The unused bytes between the previous and the new current
location are filled with copies of the least significant byte of ,
or zeros if pad is
not specified.pad
Use ALIGN to ensure that your data and code is
aligned to appropriate boundaries. This is typically required in
the following circumstances:
The ADR Thumb
pseudo-instruction can only load addresses that are word aligned, but
a label within Thumb code might not be word aligned. Use ALIGN
4 to ensure four-byte alignment of an address within Thumb
code.
Use ALIGN to take advantage of caches
on some ARM processors. For example, the ARM926EJ-S™ has
a cache with 16-byte lines. Use ALIGN 16 to align function entries
on 16-byte boundaries and maximize the efficiency of the cache.
LDRD and STRD doubleword
data transfers must be eight-byte aligned. Use ALIGN 8 before
memory allocation directives such as DCQ (see Data definition directives) if the data
is to be accessed using LDRD or STRD.
A label on a line by itself can be arbitrarily aligned.
Following ARM code is word-aligned (Thumb code is halfword aligned).
The label therefore does not address the code correctly. Use ALIGN
4 (or ALIGN 2 for Thumb) before the label.
Alignment is relative to the start of the ELF section where
the routine is located. The section must be aligned to the same,
or coarser, boundaries. The ALIGN attribute on
the AREA directive is specified differently (see AREA and Examples).
AREA cacheable, CODE, ALIGN=3
rout1 ; code ; aligned on 8-byte boundary
; code
MOV pc,lr ; aligned only on 4-byte boundary
ALIGN 8 ; now aligned on 8-byte boundary
rout2 ; code
AREA OffsetExample, CODE
DCB 1 ; This example places the two
ALIGN 4,3 ; bytes in the first and fourth
DCB 1 ; bytes of the same word.
AREA Example, CODE, READONLY
start LDR r6,=label1
; code
MOV pc,lr
label1 DCB 1 ; pc now misaligned
ALIGN ; ensures that subroutine1 addresses
subroutine1 ; the following instruction.
MOV r5,#0x5