Home/Instructions/Remainder Word
REMW

RISC-V REMW Instruction Details

Instruction ManualR-type

Signed remainder of 32-bit division, sign-extended to 64 bits

Instruction Syntax

remw rd, rs1, rs2
Operand Breakdown
rd: receives the result; source/destination overlap uses old source values, and rd=x0 discards writeback.
rs1 is the dividend and rs2 the divisor; compute the remainder using signed low 32-bit values.
Requires RV64 M; always sign-extend the 32-bit remainder to 64 bits, including with a zero divisor.
MArithmeticDivision

Instruction Behavior

REMW is an RV64 M-extension signed remainder instruction. It uses the low 32 bits of both rs1 and rs2 and always sign-extends the 32-bit remainder to 64 bits. A zero divisor returns the low 32-bit dividend, sign-extended to 64 bits. A nonzero remainder has the dividend sign; only -2147483648 divided by -1 overflows, yielding a zero remainder.

REMW 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
remw
,
,
Execution Context

This example uses fixed initial register values and PC=0x2000; instruction fetch succeeds, with no asynchronous interrupt or extra extension checks. Exception branches stop ordinary commit; post-trap PC and handler state are EEI-dependent.

t1(x6)
0x0000000000000014
t2(x7)
0x0000000000000007

This selector chooses specification-defined division-result branches. Division presets set the displayed t1/t2 initial values; editing a source register restores normal mode. It is not a trap or performance model.

31..25
24..20
19..15
14..12
11..7
6..0
0000001
funct7
00111
rs2
00110
rs1
110
funct3
00101
rd
0111011
opcode
Execution Data Path
instruction
0x027362BB
opcode
0111011 -> OP-32
funct3
110 -> REMW
funct7
0000001 -> M-extension divide/remainder selector
rd / dividend / divisor
t0(x5) / t1(x6)=20 / t2(x7)=7
signed 32-bit remainder
Not computed
x5
t0(x5) = 0x0000000000003001; pc = 0x0000000000002000
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: 0x027362BB
syntax : remw t0(x5), t1(x6), t2(x7)
Pending result: Not computed
Current architectural state
t0(x5) = 0x0000000000003001; pc = 0x0000000000002000

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

Quick Understanding & Search Notes

REMW is RV64-only: it takes a signed remainder from the low 32 bits of both sources, then sign-extends that 32-bit result to 64 bits in rd.

The fixed OP-32 R-type encoding is opcode=0111011, funct3=110, and funct7=0000001; REMW is an RV64M instruction.
With a zero divisor, the low 32-bit remainder equals the low 32-bit dividend and is still sign-extended; most-negative 32-bit divided by -1 returns zero.

Common Usage Scenarios

Integer remainder

RV64 plus M, x6=20 and x7=7: remw x5, x6, x7 gives x5=6, using only the low 32 bits and sign-extending the remainder to 64 bits.

Pre-Use Checklist

Syntax Check
  • rd, rs1 and rs2 select x0–x31 or ABI aliases, with no immediate or rs3.
Semantic Check
  • REMW is RV64-only: it takes a signed remainder from the low 32 bits of both sources, then sign-extends that 32-bit result to 64 bits in rd.
  • Destination/source overlap uses old source values; x0 is always zero and writes to it are discarded.

Pitfalls / Common Confusions

A zero divisor raises no integer divide-by-zero arithmetic exception; the remainder equals the low 32-bit dividend, sign-extended to 64 bits.
A nonzero remainder has the dividend sign; most-negative divided by -1 returns a zero remainder.
Requires RV64 M: use only the low 32-bit sources and always sign-extend the result to 64 bits; unavailable on RV32.

FAQ

Does REMW use the complete 64-bit source operands?

No. REMW uses only the low 32 bits of rs1 and rs2 as signed operands, then sign-extends the final 32-bit remainder to 64 bits.