Hi Ry, Here is a divide routine. I obtained the algorithm from Ian Kaplan's web site (http://www.bearcave.com/software/divide.htm). I tried to optimize the code for the PIC when I did the translation, so the code may not seem to follow the algorithm exactly. Kelly Kohls Amateur Radio Callsign: N5TLE Home E-Mail Address: kkohls@juno.com or n5tle@qsl.net Homepage URL: http://www.qsl.net/n5tle ; Divide Test Program ; Input - 8 bit dividend, 8 bit divisor ; Output - 8 bit quotient, 8 bit remainder ; ; Divide algorithm written by Ian Kaplan, Copyright October 1996 ; This algorithm obtained from ; http://www.bearcave.com/software/divide.htm ; ; Ported to the PIC16C76 by Kelly Kohls LIST P=16C76 RADIX DEC INCLUDE Dividend EQU H'20' ; Input variables Divisor EQU H'21' Quotient EQU H'22' ; Output variables Remainder EQU H'23' Num_Bits EQU H'24' ; Variables used by the division routine Temp EQU H'25' ORG H'00' GOTO START ORG H'10' START MOVLW 214 ; Sample test data MOVWF Dividend MOVLW 3 MOVWF Divisor CALL Divide8 Endless_Loop GOTO Endless_Loop Divide8 CLRF Remainder ; Clear our result variables CLRF Quotient MOVF Divisor,W ; Is the divisor 0? BTFSC STATUS,Z GOTO D8_Finish ; Yes XORWF Dividend,W ; Divisor = dividend ? BTFSS STATUS,Z GOTO D8_Divide_Needed ; No INCF Quotient,F ; Yes GOTO D8_Finish D8_Divide_Needed MOVF Dividend,W ; Divisor > dividend? SUBWF Divisor,W BTFSS STATUS,C GOTO D8_Division ; No, do the division MOVF Dividend,W ; Yes, return result MOVWF Remainder GOTO D8_Finish D8_Division MOVLW 8 ; Check 8 bits MOVWF Num_Bits D8_Loop1 MOVF Divisor,W ; Remainder < divisor ? SUBWF Remainder,W BTFSC STATUS,C GOTO D8_Loop1_Finish ; No RLF Dividend,W ; Move high bit of dividend to carry flag RLF Remainder,F ; Move carry flag to low bit of remainder MOVF Dividend,W ; Store a copy of dividend MOVWF Temp BCF STATUS,C RLF Dividend,F ; Move all dividend bits to the left DECF Num_Bits,F GOTO D8_Loop1 D8_Loop1_Finish MOVF Temp,W ; Above procedure went "too far" MOVWF Dividend ; Undo last iteration BCF STATUS,C RRF Remainder,F INCF Num_Bits,F D8_Loop2 MOVF Num_Bits,F BTFSC STATUS,Z GOTO D8_Finish RLF Dividend,W ; Move high bit of dividend to carry flag RLF Remainder,F ; Move carry flag to low bit of remainder MOVF Divisor,W ; temp = remainder - divisor SUBWF Remainder,W MOVWF Temp BCF STATUS,C RLF Dividend,F ; Shift dividend bits over COMF Temp,F ; Need the complement of the high bit of temp RLF Temp,W ; Move complemented bit into the carry flag RLF Quotient,F ; Move to low bit of quotient BTFSS Quotient,0 ; Is low bit a one? GOTO D8_Dec_Num_Bits ; No COMF Temp,W ; Yes, undo our previous complement MOVWF Remainder ; Store into remainder D8_Dec_Num_Bits DECF Num_Bits,F GOTO D8_Loop2 D8_Finish RETURN END ___________________________________________________________________ You don't need to buy Internet access to use free Internet e-mail. Get completely free e-mail from Juno at http://www.juno.com/getjuno.html or call Juno at (800) 654-JUNO [654-5866]