ldrh

Load Register Halfword (Immediate)

LDRH <Wt>, [<Xn|SP>, #<pimm>]

Loads a halfword from memory (zero-extended).

Details

Loads an unsigned halfword from memory using immediate offset and zero-extends it to 32 bits. No condition flags are affected. This is an AArch64 Base instruction that executes in all privilege levels.

Pseudocode Operation

address ← Xn + (pimm << 1);
Wt ← ZeroExtend(Mem[address, 2], 32);

Example

LDRH w3, [x1, #16]

Encoding

Binary Layout
01
111
0
01
01
imm12
Rn
Rt
 
Format Load/Store
Opcode 0x79400000
Extension Base

Operands

  • Wt
    Transfer 32-bit integer register (load/store)
  • Xn
    First source / base 64-bit integer register
  • pimm
    Positive immediate offset

Reference (Arm A64 ISA)

Instruction Forms

Encoding Instruction ISA Bit pattern
0x78400400 LDRH <Wt>, [<Xn|SP>], #<simm> A64 01 | 111 | 0 | 00 | 01 | 0 | imm9 | 01 | Rn | Rt
0x78400C00 LDRH <Wt>, [<Xn|SP>, #<simm>]! A64 01 | 111 | 0 | 00 | 01 | 0 | imm9 | 11 | Rn | Rt
0x79400000 LDRH <Wt>, [<Xn|SP>{, #<pimm>}] A64 01 | 111 | 0 | 01 | 01 | imm12 | Rn | Rt
0x78600800 LDRH <Wt>, [<Xn|SP>, (<Wm>|<Xm>){, <extend> {<amount>}}] A64 01 | 111 | 0 | 00 | 01 | 1 | Rm | option | S | 10 | Rn | Rt

Description

Load Register Halfword (immediate) loads a halfword from memory, zero-extends it, and writes the result to a register. The address that is used for the load is calculated from a base register and an immediate offset. For information about memory accesses, see Load/Store addressing modes.

Operation

bits(64) address;
bits(16) data;

boolean privileged = PSTATE.EL != EL0;
AccessDescriptor accdesc = CreateAccDescGPR(MemOp_LOAD, FALSE, privileged, tagchecked);

if n == 31 then
    CheckSPAlignment();
    address = SP[];
else
    address = X[n, 64];

if !postindex then
    address = GenerateAddress(address, offset, accdesc);

data = Mem[address, 2, accdesc];
X[t, 32] = ZeroExtend(data, 32);

if wback then
    if wb_unknown then
        address = bits(64) UNKNOWN;
    elsif postindex then
        address = GenerateAddress(address, offset, accdesc);
    if n == 31 then
        SP[] = address;
    else
        X[n, 64] = address;