Page 93 - ARM 64 Bit Assembly Language
P. 93
78 Chapter 3
3.5.5 Form PC-relative address
These instructions are used to calculate the address associated with a label:
adr Form PC-Relative Address
adrp Form PC-Relative Address to 4 KB Page
They are more efficient than the ldr Rx,=label pseudo instruction, because they can cal-
culate a 64-bit address in one or two instructions without performing a memory access. They
can be used to load any address that is within range. If the label is out of range, then the as-
sembler or linker will emit an error, and the programmer can change their code to use the
ldr Rx,=label syntax.
3.5.5.1 Syntax
<op> Rd, <label>
• <op> is either adr or adrp.
• adr has a range of ±1 MB. (21 bit immediate).
• adrp has a range of ±4 GB to the nearest 4 KB page (4096 bytes). The 21-bit immediate
is shiftedleftby12bits andaddedtothe pc.
• The lower 12 bits of a label’s address can be added to adrp to exactly address a la-
bel.
3.5.5.2 Operations
Name Effect Description
adr Rd ← Address of label Load address with pc-relative imme-
diate addressing.
adrp Rd ← Page address of label Load address of the beginning of
the 4-Kilobyte memory page which
contains the label using pc-relative
immediate addressing.
3.5.5.3 Examples
The adr instruction is helpful for calculating the address of labels at run-time. This is par-
ticularly useful when the address of a label must be passed to a function as an argument, but
the address cannot be determined at compile time. For example, the address of some system
libraries may not be set by the linker, but are set when the program is loaded and prepared
to run. The addresses of labels in these libraries cannot be loaded with the ldr Rx,=label