RISC-V ADDIW Instruction Details
Instruction ManualI-typeAdd a sign-extended 12-bit immediate to rs1, then sign-extend the low 32-bit result to 64 bits in rd.
Instruction Syntax
Instruction Encoding
ADDIW uses opcode 0011011 (0x1b), funct3 000. The rs1 field selects the source register, the 12-bit immediate provides the second operand, and rd selects the destination.
Instruction Behavior
ADDIW (I-type, opcode=0011011, funct3=000) adds the sign-extended 12-bit immediate to rs1, ignores overflow, and writes the sign-extended low 32-bit result to rd. With an immediate of 0 it is the SEXT.W pseudoinstruction. Exists only in RV64I.
Common Usage Scenarios
Understand this scenario with real code like «addiw x10, x11, 42 # x10 = sign-extend((x11 + 42)[31:0])».
Understand this scenario with real code like «addiw x10, x11, 42 # x10 = sign-extend((x11 + 42)[31:0])».
Understand this scenario with real code like «addiw x10, x11, 42 # x10 = sign-extend((x11 + 42)[31:0])».
Pre-Use Checklist
- Confirm the current instruction format is I-type.
- Confirm the operand order matches the example.
- Ensure the destination register usage is compatible with the calling convention.
- Confirm this is not the lower-level form of a pseudo-instruction expansion.