lha
Load Halfword Algebraic
Loads a halfword (16 bits) from memory and sign-extends it to 64 bits.
Details
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.
Pseudocode 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.
Example
// Load signed 16-bit value.
Encoding
Operands
-
RT
Target Register -
D
Displacement -
RA
Base Register