;******************************************************************* ; Double Precision Division ; ; ( Optimized for Code Size : Looped Code ) ; ;*******************************************************************; ; Division : ACCb(16 bits) / ACCa(16 bits) -> ACCb(16 bits) with ; Remainder in ACCc (16 bits) ; (a) Load the Denominator in location ACCaHI & ACCaLO ( 16 bits ) ; (b) Load the Numerator in location ACCbHI & ACCbLO ( 16 bits ) ; (c) CALL D_div ; (d) The 16 bit result is in location ACCbHI & ACCbLO ; (e) The 16 bit Remainder is in locations ACCcHI & ACCcLO ; ; Performance : ; Program Memory : 037 ; Clock Cycles : 310 ; ; Program: DBL_DIVS.ASM ; Revision Date: ; 1-13-97 Compatibility with MPASMWIN 1.40 ; ;*******************************************************************; ; Double Precision Divide ( 16/16 -> 16 ) ; ; ( ACCb/ACCa -> ACCb with remainder in ACCc ) : 16 bit output ; with Quotiont in ACCb (ACCbHI,ACCbLO) and Remainder in ACCc (ACCcHI,ACCcLO). ; ; NOTE : Before calling this routine, the user should make sure that ; the Numerator(ACCb) is greater than Denominator(ACCa). If ; the case is not true, the user should scale either Numerator ; or Denominator or both such that Numerator is greater than ; the Denominator. ; ; D_divS call setup clrf ACCcHI clrf ACCcLO dloop bcf STATUS,C rlf ACCdLO, F rlf ACCdHI, F rlf ACCcLO, F rlf ACCcHI, F movf ACCaHI,W subwf ACCcHI,W ;check if a>c btfss STATUS,Z goto nochk movf ACCaLO,W subwf ACCcLO,W ;if msb equal then check lsb nochk btfss STATUS,C ;carry set if c>a goto nogo movf ACCaLO,W ;c-a into c subwf ACCcLO, F btfss STATUS,C decf ACCcHI, F movf ACCaHI,W subwf ACCcHI, F bsf STATUS,C ;shift a 1 into b (result) nogo rlf ACCbLO, F rlf ACCbHI, F decfsz temp, F ;loop untill all bits checked goto dloop retlw 0 ; ;******************************************************************* ; setup movlw .16 ; for 16 shifts movwf temp movf ACCbHI,W ;move ACCb to ACCd movwf ACCdHI movf ACCbLO,W movwf ACCdLO clrf ACCbHI clrf ACCbLO retlw 0 ; ;******************************************************************* ; neg_A comf ACCaLO, F ; negate ACCa ( -ACCa -> ACCa ) incf ACCaLO, F btfsc STATUS,Z decf ACCaHI, F comf ACCaHI, F retlw 0