lhz
Load Halfword and Zero
Loads a halfword (16 bits) from memory and clears the upper 48 bits.
Details
Loads a 16-bit halfword from memory at address (RA + sign_extend(D)) and places it into RT with the upper 48 bits cleared to zero. The base register may be R0 if RA is zero in the instruction, in which case the displacement is used as an absolute address. No condition or status registers are affected.
Pseudocode Operation
if RA = 0 then
EA ← sign_extend(D)
else
EA ← (RA) + sign_extend(D)
RT ← (0 || [EA+1:EA])
// Load halfword at EA, zero-extend to 64 bits
Programming Note
The lhz instruction is commonly used for loading halfword values from memory into a register while ensuring the upper 16 bits are zeroed. Ensure that the effective address (EA) is properly aligned to avoid unaligned access exceptions. This instruction operates at user privilege level and will raise an exception if the EA is invalid or if there's a protection fault.
Example
// Load unsigned 16-bit value.
Encoding
Operands
-
RT
Target Register -
D
Displacement -
RA
Base Register