ldrh

Load Register Halfword (A32)

LDRH<c> <Rt>, [<Rn>, #+/-<imm>]

Loads a halfword (Zero extended).

Details

Loads an unsigned halfword (16 bits) from memory and zero-extends it to 32 bits, storing the result in the destination register. The 8-bit immediate (imm4H:imm4L) is shifted left by 1 bit to form a byte offset. The P and W bits control addressing mode. Condition flags are not affected. Execution is conditional; available in A32 only.

Pseudocode Operation

offset ← ZeroExtend(imm4H:imm4L) << 1;
if U == 1 then address ← Rn + offset else address ← Rn - offset;
if P == 1 then address ← address else address ← Rn;
Rt ← ZeroExtend(MemRead(address, 2));
if W == 1 then Rn ← address;

Example

LDRH r3, [r1, #+/-#16]

Encoding

Binary Layout
cond
000
1
U
1
1
1
Rn
Rt
imm4H
1
01
1
imm4L
 
Format Load/Store
Opcode 0x017000B0
Extension A32 (Base)

Operands

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

Reference (Arm AArch32 ISA)

Instruction Forms

Encoding Instruction ISA Bit pattern
0x015000B0 LDRH{<c>}{<q>} <Rt>, [<Rn> {, #{+/-}<imm>}] A32 cond | 000 | 1 | U | 1 | 0 | 1 | Rn | Rt | imm4H | 1 | 01 | 1 | imm4L
0x005000B0 LDRH{<c>}{<q>} <Rt>, [<Rn>], #{+/-}<imm> A32 cond | 000 | 0 | U | 1 | 0 | 1 | Rn | Rt | imm4H | 1 | 01 | 1 | imm4L
0x017000B0 LDRH{<c>}{<q>} <Rt>, [<Rn>, #{+/-}<imm>]! A32 cond | 000 | 1 | U | 1 | 1 | 1 | Rn | Rt | imm4H | 1 | 01 | 1 | imm4L
0x8800 LDRH{<c>}{<q>} <Rt>, [<Rn> {, #{+}<imm>}] T32 1000 | 1 | imm5 | Rn | Rt
0xF8B00000 LDRH{<c>}.W <Rt>, [<Rn> {, #{+}<imm>}] T32 111110001 | 01 | 1 | Rn | Rt | imm12
0xF8300C00 LDRH{<c>}{<q>} <Rt>, [<Rn> {, #-<imm>}] T32 111110000 | 01 | 1 | Rn | Rt | 1 | 1 | 0 | 0 | imm8
0xF8300900 LDRH{<c>}{<q>} <Rt>, [<Rn>], #{+/-}<imm> T32 111110000 | 01 | 1 | Rn | Rt | 1 | 0 | U | 1 | imm8
0xF8300D00 LDRH{<c>}{<q>} <Rt>, [<Rn>, #{+/-}<imm>]! T32 111110000 | 01 | 1 | Rn | Rt | 1 | 1 | U | 1 | imm8
0x005F00B0 LDRH{<c>}{<q>} <Rt>, <label> A32 cond | 000 | P | U | 1 | W | 1 | 1111 | Rt | imm4H | 1 | 01 | 1 | imm4L
0xF83F0000 LDRH{<c>}{<q>} <Rt>, <label> T32 11111000 | U | 01 | 1 | 1111 | Rt | imm12
0x011000B0 LDRH{<c>}{<q>} <Rt>, [<Rn>, {+/-}<Rm>] A32 cond | 000 | 1 | U | 0 | 0 | 1 | Rn | Rt | 0 | 0 | 0 | 0 | 1 | 01 | 1 | Rm
0x001000B0 LDRH{<c>}{<q>} <Rt>, [<Rn>], {+/-}<Rm> A32 cond | 000 | 0 | U | 0 | 0 | 1 | Rn | Rt | 0 | 0 | 0 | 0 | 1 | 01 | 1 | Rm
0x013000B0 LDRH{<c>}{<q>} <Rt>, [<Rn>, {+/-}<Rm>]! A32 cond | 000 | 1 | U | 0 | 1 | 1 | Rn | Rt | 0 | 0 | 0 | 0 | 1 | 01 | 1 | Rm
0x5A00 LDRH{<c>}{<q>} <Rt>, [<Rn>, {+}<Rm>] T32 0101 | 1 | 0 | 1 | Rm | Rn | Rt

Description

Load Register Halfword (immediate) calculates an address from a base register value and an immediate offset, loads a halfword from memory, zero-extends it to form a 32-bit word, 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,2];
        if wback then R[n] = offset_addr;
        R[t] = ZeroExtend(data, 32);
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,2];
        if wback then R[n] = offset_addr;
        R[t] = ZeroExtend(data, 32);