; Last change: DTB 27 Mar 98 3:32 pm ; 16/8 PIC16 FIXED POINT DIVIDE ROUTINES VERSION 2.01 ; ; Input: fixed point arguments in AARG and BARG ; ; Output: quotient AARG/BARG followed by remainder in REM ; ; All timings are worst case cycle counts ; ; Routine Clocks Function ; ; FXD1608U 294 16 bit/8 bit -> 16.08 unsigned fixed point divide ; AARGB0 EQU AARG ; LSB of AARG AARGB1 EQU AARG+1 ; MSB of AARG BARGB0 EQU BARG ; LSB of AARG BARGB1 EQU BARG+1 ; MSB of AARG REMB0 EQU REM ; LSB of REM REMB1 EQU REM+1 ; MSB of REM ;********************************************************************************************** ;********************************************************************************************** ; 16/08 BIT Division Macros UDIV1608L macro ; Max Timing: 2+7*12+11+2+7*20+19 = 258 clks ; Min Timing: 2+7*11+10+2+7*15+14 = 210 clks ; PM: 34 DM: 7 MOVLW 8 MOVWF LOOPCOUNT LOOPU1608A RLF AARGB1,W RLF REMB0, F MOVF BARGB0,W SUBWF REMB0, F BTFSC STATUS,C GOTO UOK68A ADDWF REMB0, F BCF STATUS,C UOK68A RLF AARGB1, F DECFSZ LOOPCOUNT, F GOTO LOOPU1608A MOVLW 8 MOVWF LOOPCOUNT LOOPU1608B RLF AARGB0,W RLF REMB0, F RLF REMB1, F MOVF BARGB0,W ; 16 bit subtract BARGB0 from REM SUBW16 REM BTFSC STATUS,C ; if result negative, GOTO UOK68B MOVF BARGB0,W ; 16 bit add BARGB0 to REM ADDW16 REM BCF STATUS,C UOK68B RLF AARGB0, F DECFSZ LOOPCOUNT, F GOTO LOOPU1608B endm ;********************************************************************************************** ;********************************************************************************************** ; 16/8 Bit Unsigned Fixed Point Divide 16/8 -> 16.08 ; Input: 16 bit unsigned fixed point dividend in AARGB1, AARGB0 ; 8 bit unsigned fixed point divisor in BARGB0 ; Use: CALL FXD1608U ; Output: 16 bit unsigned fixed point quotient in AARGB1, AARGB0 ; 8 bit unsigned fixed point remainder in REMB0 ; Result: AARG, REM <-- AARG / BARG ; Max Timing: 2+258+2 = 262 clks ; Min Timing: 2+210+2 = 214 clks ; PM: 2+34+1 = 37 DM: 7 FXD1608U CLR16 REM UDIV1608L RETLW 0x00