SUB_DIV16: ;-------------------------------------- ; ************************ DengMiao Guangzhou 2009-1 ; 32 bits / 16 bits 无符号 ; Input: DPTR --- 16 BITS ; [R0]:[R0-1]:[R0-2]:[R0-3] ---32 BITS ; OUTPUT: [R1]:[R1-1]:[R1-2]:[R1-3] ---32 BITS ; R7:R6 -- MOD 16 bits ; use: R4, ACC, PSW ;------------------------------------------- MOV R4, #4 MOV R6, #0 MOV R7, #0
DIV16LP32: MOV A, @R0 DEC R0 ACALL DIV16A MOV @R1, A DEC R1 DJNZ R4, DIV16LP32 RET ;------------------------ DIV16A: MOV R5, #8 DIV16A1: RLC A ;R7:R6:A ;16 XCH A, R6 ;17
RLC A ;1 XCH A, R7 ; A:R7:R6;2 RLC A ;3 JNC DIV16A3 ;5 XCH A, R7 ;6 CLR C ;7 SUBB A, DPL ;8 XCH A, R7 ;9 SUBB A, DPH ; 10 A:R7:R6 XCH A, R7 ;11 XCH A, R6 ;12 CLR C ;13 DJNZ R5, DIV16A1;15 SJMP DIV16A9 ;17
DIV16A2: RLC A ;1 R7:R6:A XCH A, R6 ;2 RLC A ;3 XCH A, R7 ;4 A:R7:R6 RLC A ;5
DIV16A3: CJNE A, DPH, DIV16A7 ; 7 XCH A, R7 ;8 SUBB A, DPL ;9 JNC DIV16A5 ;11 ADD A, DPL ;12 DIV16A4: XCH A, R6 ;13 DJNZ R5, DIV16A1 ;15 SJMP DIV16A9 ;17
DIV16A5: MOV R7, #0 ;12 SJMP DIV16A8 ;14 DIV16A6: SJMP DIV16A4 ;12 DIV16A7: XCH A, R7 ;8 JC DIV16A6 ;10 SUBB A, DPL ;11 XCH A, R7 ;12 SUBB A, DPH ;13 XCH A, R7 ;14 DIV16A8: XCH A, R6 ;15 DJNZ R5, DIV16A2 ;17 DIV16A9: RLC A ;18 CPL A ;19 RET ;21 ;=========================== |