Home/Instructions/Divide Word
DIVW

RISC-V DIVW Instruction Details

Instruction ManualR-type

Divide lower 32 bits of rs1 by lower 32 bits of rs2 (signed), sign-extend 32-bit quotient to 64 bits

Instruction Syntax

divw 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.
MArithmeticDivision

Instruction Behavior

DIVW is an RV64-only signed division instruction that divides the lower 32 bits of rs1 by the lower 32 bits of rs2 (both signed), rounds toward zero, and sign-extends the 32-bit quotient to 64 bits. Division by zero and overflow behavior mirrors DIV (at 32-bit width).

DIVW 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
divw
,
,
Execution Context
t1(x6)
0x0000000000000014
t2(x7)
0x0000000000000007

This selector chooses only specification-defined division-result branches; it is not an exception, trap, or performance model.

31..25
24..20
19..15
14..12
11..7
6..0
0000001
funct7
00111
rs2
00110
rs1
100
funct3
00101
rd
0111011
opcode
Execution Data Path
instruction
0x027342BB
opcode
0111011 -> OP-32
funct3
100 -> DIVW
funct7
0000001 -> M-extension divide/remainder selector
rd / dividend / divisor
t0(x5) / t1(x6)=20 / t2(x7)=7
signed 32-bit division
20 / 7 -> quotient[31:0]=0x00000002 -> sext.w 0x0000000000000002 (signed 32-bit division rounds toward zero)
x5
t0(x5) = 0x0000000000000002
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: 0x027342BB
syntax : divw t0(x5), t1(x6), t2(x7)
result : t0(x5) = 0x0000000000000002
Architectural Result
t0(x5) = 0x0000000000000002

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

Common Usage Scenarios

Multiplication & Division

Understand this scenario with real code like «divw a0, a1, a2 # a0 = sign-extend(signed(a1[31:0]) / signed(a2[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

32-bit overflow: -2^31 / -1 returns dividend -2^31
Division by zero returns all-1s (-1)
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.