ldr

Load Register (A32 Immediate)

LDR<c> <Rt>, [<Rn>, #+/-<imm>]{!}

Loads a word from memory.

Details

Loads a 32-bit word from memory at an address computed from a base register and 12-bit immediate offset, storing the result in the destination register. The P and W bits control addressing mode (offset, pre-indexed, or post-indexed). Condition flags are not affected by this instruction. Execution is conditional based on the 4-bit condition code field; available in A32 only.

Pseudocode Operation

offset ← ZeroExtend(imm12);
if U == 1 then address ← Rn + offset else address ← Rn - offset;
if P == 1 then address ← address else address ← Rn;
Rt ← MemRead(address, 4);
if W == 1 then Rn ← address;

Example

LDR r3, [r1, #+/-#16]!

Encoding

Binary Layout
cond
010
1
U
0
1
1
Rn
Rt
imm12
 
Format Load/Store
Opcode 0x05300000
Extension A32 (Base)

Operands

  • Rt
    Transfer general-purpose register (load/store)
  • Rn
    First source / base general-purpose register
  • imm
    Signed immediate value

Reference (Arm AArch32 ISA)

Instruction Forms

Encoding Instruction ISA Bit pattern
0x05100000 LDR{<c>}{<q>} <Rt>, [<Rn> {, #{+/-}<imm>}] A32 cond | 010 | 1 | U | 0 | 0 | 1 | Rn | Rt | imm12
0x04100000 LDR{<c>}{<q>} <Rt>, [<Rn>], #{+/-}<imm> A32 cond | 010 | 0 | U | 0 | 0 | 1 | Rn | Rt | imm12
0x05300000 LDR{<c>}{<q>} <Rt>, [<Rn>, #{+/-}<imm>]! A32 cond | 010 | 1 | U | 0 | 1 | 1 | Rn | Rt | imm12
0x6800 LDR{<c>}{<q>} <Rt>, [<Rn> {, #{+}<imm>}] T32 011 | 0 | 1 | imm5 | Rn | Rt
0x9800 LDR{<c>}{<q>} <Rt>, [SP{, #{+}<imm>}] T32 1001 | 1 | Rt | imm8
0xF8D00000 LDR{<c>}.W <Rt>, [<Rn> {, #{+}<imm>}] T32 111110001 | 10 | 1 | Rn | Rt | imm12
0xF8500C00 LDR{<c>}{<q>} <Rt>, [<Rn> {, #-<imm>}] T32 111110000 | 10 | 1 | Rn | Rt | 1 | 1 | 0 | 0 | imm8
0xF8500900 LDR{<c>}{<q>} <Rt>, [<Rn>], #{+/-}<imm> T32 111110000 | 10 | 1 | Rn | Rt | 1 | 0 | U | 1 | imm8
0xF8500D00 LDR{<c>}{<q>} <Rt>, [<Rn>, #{+/-}<imm>]! T32 111110000 | 10 | 1 | Rn | Rt | 1 | 1 | U | 1 | imm8
0x041F0000 LDR{<c>}{<q>} <Rt>, <label> A32 cond | 010 | P | U | 0 | W | 1 | 1111 | Rt | imm12
0x4800 LDR{<c>}{<q>} <Rt>, <label> T32 01001 | Rt | imm8
0xF85F0000 LDR{<c>}.W <Rt>, <label> T32 11111000 | U | 10 | 1 | 1111 | Rt | imm12
0x07100000 LDR{<c>}{<q>} <Rt>, [<Rn>, {+/-}<Rm>{, <shift>}] A32 cond | 011 | 1 | U | 0 | 0 | 1 | Rn | Rt | imm5 | stype | 0 | Rm
0x06100000 LDR{<c>}{<q>} <Rt>, [<Rn>], {+/-}<Rm>{, <shift>} A32 cond | 011 | 0 | U | 0 | 0 | 1 | Rn | Rt | imm5 | stype | 0 | Rm

Description

Load Register (immediate) calculates an address from a base register value and an immediate offset, loads a word from memory, and writes it to a register. It can use offset, post-indexed, or pre-indexed addressing. For information about memory accesses see Memory accesses.

Operation

if CurrentInstrSet() == InstrSet_A32 then
    if ConditionPassed() then
        EncodingSpecificOperations();
        offset_addr = if add then (R[n] + imm32) else (R[n] - imm32);
        address = if index then offset_addr else R[n];
        data = MemU[address,4];
        if wback then R[n] = offset_addr;
        if t == 15 then
            if address<1:0> == '00' then
                LoadWritePC(data);
            else
                UNPREDICTABLE;
        else
            R[t] = data;
else
    if ConditionPassed() then
        EncodingSpecificOperations();
        offset_addr = if add then (R[n] + imm32) else (R[n] - imm32);
        address = if index then offset_addr else R[n];
        data = MemU[address,4];
        if wback then R[n] = offset_addr;
        if t == 15 then
            if address<1:0> == '00' then
                LoadWritePC(data);
            else
                UNPREDICTABLE;
        else
            R[t] = data;