What offset range does LH use?
Base load instructions use a sign-extended 12-bit byte offset, typically -2048 through 2047.
Load a 16-bit halfword from memory, sign-extend to 32 bits, and write to rd
LH uses opcode 0000011 (0x03), funct3 001. The rs1 field selects the source register, the 12-bit immediate provides the second operand, and rd selects the destination.
LH (I-type, opcode=0000011, funct3=001) loads a 16-bit halfword from memory at the effective address (rs1 + sign-extended 12-bit offset), sign-extends it to 32 bits, and writes to rd. Naturally aligned halfword addresses are multiples of 2. Misaligned behavior is EEI-defined.
LH reads a 16-bit halfword from the effective address formed by rs1 plus a signed 12-bit offset, then sign-extends the value into rd.
Understand this scenario with real code like «lh x6, 4(x10) # x6 = sign_ext(mem[x10+4][15:0])».
Understand this scenario with real code like «lh x6, 4(x10) # x6 = sign_ext(mem[x10+4][15:0])».
Base load instructions use a sign-extended 12-bit byte offset, typically -2048 through 2047.
LB/LH/LW sign-extend the loaded value to XLEN; LBU/LHU zero-extend. On RV64, use LWU when a 32-bit word should be zero-extended.