remu

remu

RISC-V Assembly Reference

lyszt.net covers remu and other RISC-V instructions in more detail.

Encoding format

R
31–25funct7
24–20rs2
19–15rs1
14–12funct3
11–7rd
6–0opcode
I
31–20imm[11:0]
19–15rs1
14–12funct3
11–7rd
6–0opcode
S
31–25imm[11:5]
24–20rs2
19–15rs1
14–12funct3
11–7imm[4:0]
6–0opcode
B
31–25imm[12,10:5]
24–20rs2
19–15rs1
14–12funct3
11–7imm[4:1,11]
6–0opcode
U
31–12imm[31:12]
11–7rd
6–0opcode
J
31–12imm[20,10:1,11,19:12]
11–7rd
6–0opcode

Description

Returns the remainder of an unsigned division. In remu rd, rs1, rs2, the remainder is written to rd and never carries a sign. The result always falls between 0 and the divisor minus 1, which wraps a position around a circular buffer and spreads values over a fixed number of slots.

Official definition

RISC-V Instruction Set Manual

DIV and DIVU perform an XLEN bits by XLEN bits signed and unsigned integer division of rs1 by rs2, rounding towards zero. REM and REMU provide the remainder of the corresponding division operation. For REM, the sign of a nonzero result equals the sign of the dividend.

ConditionDividendDivisorDIVU[W]REMU[W]DIV[W]REM[W]
Division by zero Overflow (signed only)x -2^L-10 −12^L-1 -x -−1 -2^L-1x 0