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. Refer to the ARM Architectural Reference Manual for information on the LDR instruction.

Syntax

The syntax of LDR is:

LDR register, =[expression | label-expression]

where:

register

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

expression

evaluates to a numeric constant:

  • If the value of expression is within range of a MOV instruction, the assembler generates the instruction.

  • If the value of expression 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.

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

label-expression

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

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 directive for more information.

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

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 AOF area containing the LDR.

Refer to Chapter 5 Basic Assembly Language Programming in the ARM Software Development Toolkit User Guide for a more detailed explanation of how to use LDR, and for more information on MOV.

Example

		LDR		r1, =0xfff				; loads 0xfff into r1
								; 
		LDR		r2, =labelname				; loads the address of
								;	labelname into r2
Copyright © 1997, 1998 ARM Limited. All rights reserved.ARM DUI 0041C
Non-Confidential