Hi PICLIST group .............I have just tested VERY CAREFULY the 4th = piece of code from your math/divide code section entitled... ;Nikolai Golovchenko shares this = code:=20 and NON of the tested code produces INTELIGEBLE RESULTS. I did test all = similar=20 free code from MICROCHIP math handbook and it all works !!!!!?????????? The code I just finished testing is given below in exact form as tested: AND THE RESULTS ARE NONSENSE!!!! Lou Frias IMC Instruments =20 I can be reached at loui@g2a.net ;Nikolai Golovchenko shares this = code: =20 ;Here is a slightly optimized version - 1 instruction shorter, 24 cycles = faster! ;Inputs: ; Dividend - AARGB0:AARGB1:AARGB2 (0 - most significant!) ; Divisor - BARGB0:BARGB1 ;Temporary: ; Counter - LOOPCOUNT ; Remainder- REMB0:REMB1 ;Output: ; Quotient - AARGB0:AARGB1:AARGB2 ; ; Size: 27 ; Max timing: 4+24*(6+6+4+3+5)-1+3+2=3D584 cycles (with return) ; Min timing: 4+24*(6+6+5+5)-1+3+2=3D536 cycles (with return) ; ;25-Sep-2000 Original version ;20-Oct-2001 Made the loop one instruction shorter, comments ; review. FXD2416U: CLRF REMB0 CLRF REMB1 MOVLW 24 MOVWF LOOPCOUNT LOOPU2416 RLF AARGB2, F ;shift dividend left to move next bit to = remainder RLF AARGB1, F ;and shift in next bit of result RLF AARGB0, F ; RLF REMB1, F ;shift carry (next dividend bit) into = remainder RLF REMB0, F RLF LOOPCOUNT, F ;save carry in counter, since remainder=20 ;can be 17 bit long in some cases (e.g.=20 ;0x800000/0xFFFF) =20 MOVF BARGB1, W ;substract divisor from 16-bit remainder SUBWF REMB1, F ; MOVF BARGB0, W ; BTFSS STATUS, C ; INCFSZ BARGB0, W ; SUBWF REMB0, F ; ;here we also need to take into account the 17th bit of remainder, which ;is in LOOPCOUNT.0. If we don't have a borrow after subtracting from = lower ;16 bits of remainder, then there is no borrow regardless of 17th bit=20 ;value. But, if we have the borrow, then that will depend on 17th bit=20 ;value. If it is 1, then no final borrow will occur. If it is 0, borrow ;will occur. SKPNC ;if no borrow after 16 bit subtraction BSF LOOPCOUNT, 0 ;then no no borrow in result. Overwrite ;LOOPCOUNT.0 with 1 to indicate no ;borrow. ;if borrow did occur, LOOPCOUNT.0 will ;hold the eventual borrow value = (0-borrow, ;1-no borrow) BTFSC LOOPCOUNT, 0 ;if no borrow after 17-bit subtraction GOTO UOK46LL ;skip remainder restoration. ADDWF REMB0, F ;restore higher byte of remainder. (w=20 ;contains the value subtracted from it ;previously) MOVF BARGB1, W ;restore lower byte of remainder ADDWF REMB1, F ; UOK46LL CLRC ;copy bit LOOPCOUNT.0 to carry RRF LOOPCOUNT, F ;and restore counter DECFSZ LOOPCOUNT, f ;decrement counter GOTO LOOPU2416 ;and repeat loop if not zero. carry=20 ;contains next quotient bit (if borrow, ;it is 0, if not, it is 1). =20 RLF AARGB2, F ;shift in last bit of quotient RLF AARGB1, F =20 RLF AARGB0, F RETURN -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body