divu

divu

RISC-V Assembly Reference

lyszt.net covers divu 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

Divides the value of one register by another, reading both as unsigned numbers. In divu rd, rs1, rs2, the quotient of rs1 and rs2 goes to rd. The unsigned reading counts the 32 bits from 0 to about 4 billion and serves addresses, sizes, counts and pixel coordinates, where signed div returns wrong results once a value passes about 2 billion with its top bit set. A zero divisor also differs from the signed case, yielding the largest unsigned value with every bit set.

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