ADDW

RISC-V ADDW Instruction Details

Instruction ManualR-type

Add lower 32 bits of rs1 and rs2, producing 32-bit result sign-extended to 64 bits

Instruction Syntax

addw rd, rs1, rs2
Operand Breakdown
Destination rd: register receiving the operation result.
Source rs1: register holding the first operand.
Source rs2: register holding the second operand.
RV64IArithmetic32-bit Operational

Instruction Behavior

ADDW (R-type, opcode=0111011, funct7=0000000, funct3=000) adds the lower 32 bits of rs1 and rs2, ignores overflow, sign-extends the 32-bit result to 64 bits, and writes it to rd. Unlike ADD (full 64-bit operation), ADDW operates only on the lower 32 bits and sign-extends.

ADDW Decode And Execute Animation

Starts with machine-code field decoding, then shows operand reads, instruction-specific execution, and ISA-visible state update.

rd
rs1
rs2
addw
,
,
Execution Context
t1(x6)
0x0000000000000014
t2(x7)
0x0000000000000007
31..25
24..20
19..15
14..12
11..7
6..0
0000000
funct7
00111
rs2
00110
rs1
000
funct3
00101
rd
0111011
opcode
Execution Data Path
instruction
0x007302BB
opcode
0111011 -> OP-32
funct3
000 -> ADDW
funct7
0000000 -> base ALU op
rd / rs1 / rs2
t0(x5) / t1(x6) / t2(x7)
32-bit add
0x0000000000000014 + 0x0000000000000007 -> low 32 bits 0x0000001B -> sext.w 0x000000000000001B
x5
t0(x5) = 0x000000000000001B
Current Step

Concept Step: receive the 32-bit instruction encoding

The machine code is split by the current instruction format; the animation starts from encoding/decode.

encoding: 0x007302BB
syntax : addw t0(x5), t1(x6), t2(x7)
result : t0(x5) = 0x000000000000001B
Architectural Result
t0(x5) = 0x000000000000001B

This animation shows ISA-visible decode and state changes, not any specific CPU pipeline, cache, prediction, or timing implementation.

Common Usage Scenarios

Address & Pointer

Understand this scenario with real code like «addw x10, x11, x12 # x10 = sign-extend((x11[31:0] + x12[31:0])[31:0])».

Basic Arithmetic

Understand this scenario with real code like «addw x10, x11, x12 # x10 = sign-extend((x11[31:0] + x12[31:0])[31:0])».

Pre-Use Checklist

Syntax Check
  • Verify rd, rs1, rs2 (and rs3) are valid GPRs.
  • Confirm funct3 and funct7 encoding is correct.
Semantic Check
  • Check if the result affects subsequent branches or address calculations.
  • Ensure the rd register is not overwritten by another instruction.

Pitfalls / Common Confusions

Overflow is silently ignored
Result is always 32-bit sign-extended
W-suffix instructions produce a 32-bit result and sign-extend bit 31 to XLEN; do not treat them as ordinary 64-bit operations.
These W-suffix forms belong to RV64I or RV64 extension instructions; RV32 has no corresponding forms.