5.6.2. LDR Thumb pseudo-instruction

The LDR pseudo-instruction loads a low register with either:

Note

This section describes the LDR pseudo-instruction only. See Thumb memory access instructions for information on the LDR instruction.

Syntax

LDR register, =[expr | label-exp]

where:

register

is the register to be loaded. LDR canaccess the low registers (r0-r7) only.

expr

evaluates to a numeric constant:

  • if the value of expr is within range of a MOV instruction, the assembler generates the instruction

  • if the value of expr is not within range of a MOV instruction, the assembler places the constant in a literal pool and generates a program-relative LDR instruction that reads the constant from the literal pool.

label-exp

is a program-relative or external expression. The assembler places the value of label-exp in a literal pool and generates a program-relative LDR instruction that loads the value from the literal pool.

If label-exp is an external expression, or is not contained in the current section, the assembler places a linker relocation directive in the object file. The linker ensures that the correct address is generated at link time.

The offset from the pc to the value in the literal pool must be positive and less than 1KB. You are responsible for ensuring that there is a literal pool within range. See LTORG for more information.

Usage

The LDR pseudo-instruction is used for two main purposes:

  • To generate literal constants when an immediate value cannot be moved into a register because it is out of range of the MOV instruction.

  • To load a program-relative or external address into a register. The address remains valid regardless of where the linker places the ELF section containing the LDR.

Example

        LDR     r1, =0xfff      ; loads 0xfff into r1
        LDR     r2, =labelname  ; loads the address of labelname into r2
Copyright © 2000, 2001 ARM Limited. All rights reserved.ARM DUI 0068B
Non-Confidential