ARM ADRP and ADRL pseudo-instruction
ADRL
is similar to the ADR
instruction, except ADRL
can load a wider range of addresses because it generates two data processing instructions.
- In A32, the
ADRL
pseudo-instruction calculates an offset using two separateADD
orSUB
operations. - In A64, on the other hand,
ADRL
assembles to two instructions, anADRP
followed by anADD
.
ADRP (A64)#
Arm A-profile A64 Instruction Set Architecture | ADRP
ARM Compiler armasm Reference Guide | 5: A64 General Instructions - 5.13 ADRP
Arm Compiler armasm User Guide | 17. A64 General Instructions - 17.13 ADRP (A64): Form PC-relative address to 4KB page.
Load register (PC-relative literal).
Syntax
label
is the program label whose 4KB page address is to be calculated. An offset from the page address of this instruction, in the range ±4GB.
Instruction
Form PC-relative address to 4KB page adds an immediate value that is shifted left by 12 bits, to the PC value to form a PC-relative address, with the bottom 12 bits masked out, and writes the result to the destination register.
<label>
is the program label whose 4KB page address is to be calculated. Its offset from the page address of this instruction, in the range ±4GB, is encoded as "immhi:immlo"((23:5)<<2 | 30:29) times 4096.
221<<12 = 233 = 2*232 = ±4GB.
Usage
Load Register (literal) calculates an address from the PC value and an immediate offset, loads a word from memory, and writes it to a register. For information about memory accesses, see Load/Store addressing modes in the Arm Architecture Reference Manual Armv8, for Armv8-A architecture profile.
ADRL pseudo-instruction#
A32#
ARM Compiler armasm Reference Guide | 3: A32 and T32 Instructions - 3.21 ADRL pseudo-instruction
Arm Compiler armasm User Guide | 14. A32 and T32 Instructions - 14.12 ADRL pseudo-instruction
Load a PC-relative or register-relative address into a register.
Syntax
label
is a PC-relative or register-relative expression.
Usage
-
ADRL
always assembles to two 32-bit instructions. Even if the address can be reached in a single instruction, a second, redundant instruction is produced. -
If the assembler cannot construct the address in two instructions, it generates an error message and the assembly fails. You can use the
LDR
pseudo-instruction for loading a wider range of addresses. -
ADRL
is similar to theADR
instruction, exceptADRL
can load a wider range of addresses because it generates two data processing instructions. -
ADRL
produces position-independent code, because the address is PC-relative or register-relative. -
If label is PC-relative, it must evaluate to an address in the same assembler area(code section) as the
ADRL
pseudo-instruction.
Architectures and range
The available range depends on the instruction set in use:
A32
The range of the instruction is any value that can be generated by twoADD
or twoSUB
instructions. That is, any value that can be produced by the addition of two values, each of which is 8 bits rotated right by any even number of bits within a 32-bit word. See Operand2 as a constant for more information.T32
, 32-bit encoding ±1MB bytes to a byte, halfword, or word-aligned address.T32
, 16-bit encodingADRL
is not available.
The given range is relative to a point four bytes (in T32 code) or two words (in A32 code) after the address of the current instruction.
A64#
ARM Compiler armasm Reference Guide | 5: A64 General Instructions - 5.12 ADRL pseudo-instruction
Arm Compiler armasm User Guide | 17. A64 General Instructions - 17.12 ADRL pseudo-instruction
Load a PC-relative address into a register. It is similar to the ADR
instruction but ADRL
can load a wider range of addresses than ADR
because it generates two data processing instructions.
Syntax
Usage
-
ADRL
assembles to two instructions, anADRP
followed byADD
. -
If the assembler cannot construct the address in two instructions, it generates a relocation. The linker then generates the correct offsets.
-
ADRL
produces position-independent code, because the address is calculated relative to PC.
Examples
references#
ARM Compiler armasm Reference Guide
- 3: A32 and T32 Instructions - 3.3 Memory access instructions
ARM Cortex-A Series Programmer's Guide for ARMv8-A
- 5: An Introduction to the ARMv8 Instruction Sets - 5.1 The ARMv8 instruction sets - 5.1.2 Addressing - Increased PC-relative offset addressing