divu
Unsigned divide
The default word form divides an unsigned 32-bit dividend by an unsigned 16-bit divisor.
- Arithmetic, logic and bitsM68K assembly
- Exceptions and the vector tableM68K assembly
- Multiply and divide, with the remainderM68K assembly
- A subroutine with its arguments in registersM68K assembly
- A jump tableM68K assembly
- Convert a number to a string in any baseM68K assembly
- A bouncing ballM68K assembly
- The snake gameM68K assembly
- Flappy ASMM68K assembly
- Arithmetic, logic and bitsAssembly basics
- ● depends on the result
- 0 always 0
- ? undefined (do not rely on it)
- – not changed
- After a division that does not overflow, N and Z describe the quotient.
Forms
68020 only
These forms require the 68020. Select opt p=68020 before any code or data.
Operands
<ea>- An operand using one of the addressing modes listed for this form. The list determines whether it can be a register, memory or an immediate value. With
opt p=68020, an allowedd(An,Xn)ord(PC,Xn)mode also permits the corresponding 68020 indexed and memory indirect forms. See 68020 addressing. More Dn- A data register,
d0tod7. More Dr:Dq- A remainder register followed by a quotient register, for example
d2:d1. Fordivs.landdivu.l, both supply the 64-bit dividend, high long first. Fordivsl.landdivul.l, onlyDqsupplies the 32-bit dividend. The quotient replacesDqand the remainder replacesDr. More #imm- An immediate value written after
#: a number, character or label, such as#10,#$FFor#'a'. It must fit the operation’s size: byte-128to255, word-32768to65535, or long-2147483648to4294967295; signed and unsigned spellings are accepted. More
The destination data register supplies the dividend. The source supplies the divisor. The quotient replaces the destination’s low word, and the remainder replaces its high word.
A zero divisor raises a division-by-zero exception through vector 5 at $14, leaving the destination unchanged. Without a handler, the program ends at divu. See writing a handler. A quotient above 65535 sets V and leaves the destination unchanged. Test V with bvs before using the result.
On the 68020, divu.l uses a 32-bit divisor. divu.l d0, d1 divides the 32-bit value in d1 by d0 and keeps only the quotient. divu.l d0, d2:d1 divides a 64-bit value, with its high long in d2 and low long in d1, by d0. It writes the quotient to d1 and the remainder to d2. A quotient too large for 32 bits sets V and leaves the registers unchanged. After a successful division, N and Z describe the quotient. Use different registers to keep both results. If both names refer to the same register, only the quotient remains.
divul divides a 32-bit value and keeps the remainder too.
* --- Result: quotient in low word, remainder in high word ---
move.l #21, d0
divu #4, d0
move.w d0, d1 ; d1 = quotient (5)
swap d0
move.w d0, d2 ; d2 = remainder (1)
* --- Large unsigned value ---
move.l #$FFFE, d3
divu #$FFFF, d3
move.w d3, d4 ; d4 = quotient (0)
swap d3
move.w d3, d5 ; d5 = remainder ($FFFE)