;======================================================== ; subroutine UDIV16 *** DengMiao 2008-10-21 GuangZhou**** ; 16-Bit / 16-Bit to 16-Bit Unsigned Divide ; ; input: r1:r0 = Dividend X ; DPH:DPL = Divisor Y ; ; output: R5.A = quotient Q of division Q = X / Y ; R7:R6 = remainder ; ; alters: acc, r4, flags ;======================================================= UDIV16: MOV R7, #0 MOV R6, #0 MOV A, R1 ACALL UDIV16A MOV R5, A MOV A, R0 ;--------------------- UDIV16A: MOV R4, #8 UDIV16B: ; R7:R6:A RLC A ;16 XCH A, R6 ;17 RLC A ;1 XCH A, R7 ;2 RLC A ;3 A:R7:R6 JNC UDIV16E ;5 XCH A, R7 ;6 CLR C ;7 SUBB A, DPL;8 XCH A, R7 ;9 SUBB A, DPH;10 CLR C ;11 XCH A, R7 ;12 XCH A, R6 ;13 DJNZ R4, UDIV16B ;15 SJMP UDIV16J ;17
UDIV16C: RLC A ;1 XCH A, R6 ;2 RLC A ;3 XCH A, R7 ;4 RLC A ;5 A:R7:R6
UDIV16E: CJNE A, DPH, UDIV16G ;7 XCH A, R7 ;8 SUBB A, DPL ;9 JC UDIV16F ;11 MOV R7, #0 ;12 SJMP UDIV16I;14 UDIV16F: ADD A, DPL;12 UDIF16F2: XCH A, R6 ;13 DJNZ R4, UDIV16B ;15 SJMP UDIV16J ;17
UDIV16G: XCH A, R7 ;8 JNC UDIV16H ;10 SJMP UDIV16F2 ;12
UDIV16H: SUBB A, DPL;11 XCH A, R7 ;12 SUBB A, DPH;13 XCH A, R7 ;14 UDIV16I: XCH A, R6 ;15 DJNZ R4, UDIV16C ;17 UDIV16J: RLC A ;18 CPL A ;19 RET ;21 ;----------------------------------------- |