3 ;; This function also computes the remainder and stores it in er3.
6 mov.w A1E,A1E ; denominator top word 0?
9 ; do it the easy way, see page 107 in manual
27 #ifdef CONFIG_CPU_H8300H
30 shlr.l er2 ; make divisor < 2^16
34 shlr.l #2,er2 ; make divisor < 2^16
40 shlr.l #2,er2 ; make divisor < 2^16
54 ;; er0 contains shifted dividend
55 ;; er1 contains divisor
56 ;; er2 contains shifted divisor
57 ;; er3 contains dividend, later remainder
58 divxu.w r2,er0 ; r0 now contains the approximate quotient (AQ)
61 subs #1,er0 ; er0 = AQ - 1
63 mulxu.w r0,er2 ; er2 = upper (AQ - 1) * divisor
64 sub.w r2,e3 ; dividend - 65536 * er2
66 mulxu.w r0,er2 ; compute er3 = remainder (tentative)
67 sub.l er2,er3 ; er3 = dividend - (AQ - 1) * divisor
69 cmp.l er1,er3 ; is divisor < remainder?
72 sub.l er1,er3 ; correct the remainder