DIVXU
DIVXU (DIVide eXtend as Unsigned)
Divide
2. Programming solution for DIVXU.W R0, ER1
Example 1: Divide upper 16 bits and lower 16 bits of 32-bit dividend separately and obtain 32-bit
quotient
MOV.W
R0, R0
; R0 = 0? (Zero divisor?)
BEQ
ZERODIV
; Branch to ZERODIV if R0 = 0
MOV.W
E1,E2
; Copy upper 16 bits of dividend to R2 and
EXTU.L
ER2
(*1)
; zero-extend to 32 bits
DIVXU.W
R0, ER2
(*2)
; Divide upper 16 bits of dividend
MOV.W
E2, E1
(*3)
; E2
→
E1 (store partial remainder in E1)
DIVXU.W
R0, ER1
(*4)
; Divide lower 16 bits of dividend (including repeated division of
upper 16 bits)
MOV.W
R2, E2
; Store upper part of quotient in E2
MOV.W
R1, R2
(*5)
; Store lower part of quotient in R2
RTS
ZERODIV:
; Zero-divide handling routine
The resulting operation is 32 bits ÷ 16 bits
→
quotient (32 bits) and remainder (16 bits), and no
overflow occurs. The 32-bit quotient is stored in ER2, the 16-bit remainder in E1.
Remainder
Quotient (low)
Remainder
Quotient (low)
Quotient
ER1
ER2
ER2
ER1
ER1
ER1
ER2
R0
Divisor
Dividend
Sign extension
Dividend (high)
Remainder (part) Quotient (high)
Remainder (part)
Dividend (low)
( 1)
*
( 2)
*
( 3)
*
( 4)
*
( 5)
*
94