lha
Load Halfword Algebraic
lha RT, D(RA)
Loads a halfword (16 bits) from memory and sign-extends it to 64 bits.
Encoding
Binary Layout
42
0:5
RT
6:10
RA
11:15
D
16:31
Operands
-
RT
Target Register -
D
Displacement -
RA
Base Register
Example
lha r3, 0(r4)
// Load signed 16-bit value.
Related
More in Base
Reference
View in PowerISA v3.1C Specification ↗
OPF Power ISA v3.1C
Description
Loads a 16-bit halfword from memory at address (RA + sign_extend(D)) and places it into RT with sign extension to the full 64-bit width. The base register may be R0 if RA is zero in the instruction. No condition or status registers are affected.
Operation
if RA = 0 then
EA ← sign_extend(D)
else
EA ← (RA) + sign_extend(D)
RT ← sign_extend([EA+1:EA])
// Load halfword at EA and sign-extend to 64 bits
Programming Note
The lha instruction is commonly used for loading signed halfword values from memory into a register, ensuring proper sign extension. Ensure that the effective address (EA) is properly aligned to avoid alignment faults. This instruction operates at user privilege level and will raise an exception if the EA is invalid or if there are insufficient privileges.