> >Since 0x55 is %01010101 in binary, try the following algorithm: > Hi Rick, It seems an infinite series of algorithms converges. :-) This is about where we got to a week ago. Maybe you missed it. It was probably buried under bovine something or other. All methods posted so far converge on the multiply by 85 method. Here is the code that Scott Dattalo posted, very fast and clean. ----------------- ;Divide by 3 ; 'dividend' is the input ; result is returned in W MOVLW 1 ;255 is a special case ADDWF dividend,F SKPNC RETLW 0x55 CLRF quo_L ; RRF dividend,W ;(C=0) MOVWF quo_H RRF quo_L,F ;quo_H:L = dividend/2 RRF quo_H,W RRF quo_L,F ;quo_H:L = dividend/4 ADDWF dividend,W ; MOVWF quo_H RRF quo_H,F RRF quo_L,F ;quo_H:L = 5*dividend/8 ; note quo_L LSN is zero SWAPF quo_H,W ;divide quo_H by 16 ADDWF quo_L,F ;add upper nibble to quo_L. We ; really are only interested in the carry ANDLW 0x0f ;Remove upper nibble (was lower nibble of quo_H) SKPNC ; ADDLW 1 ;Add in carry from quo_L addition ADDWF quo_H,F ;quo_H = dividend *0x55 / 0x80 RRF quo_H,W ;W = dividend * 0x55 / 0x100 ----------------- Here is one method I posted, slightly slower than Scott Dattalo's but closer to your algorithm. Still the same basic method. Arrived at by going the long way round. ----------------- Here is the code for the above algorithm. No doubt someone can find a few ways to cut a cycle or two. Currently 23 cycles including rounding etc. 21 cycles if you can accept truncation rather than rounding. DIV3 ; Call with 8bit in W , exit with X/3 in W ; ; RAM: uses T and Xh:Xl ; MOVWF Xl ; CLRF Xh ; RLF Xl,F RLF Xh,F ; X*2 RLF Xl,F ; RLF Xh,F ; X*4 ADDWF Xl,F SKPNC INCF Xh,F ; 5*X ; X = 0J:KL SWAPF Xh,W ; W = J0 MOVWF T ; T = J0 SWAPF Xl,W ; W = LK ANDLW 0x0F ; W = 0K ADDWF T,F ; T = JK ; SWAPF Xl,W ; W = LK ANDLW 0xF0 ; W = L0 ** needed? ADDWF Xl,F ; MOVF Xh,W ; SKPNC ; ADDLW 1 ; ADDWF T,W ; BTFSC Xl,7 ; Round up if >128 ADDLW 1 ; ; result in W ----------------- Ray Gardiner (DSP Systems) ray@dsp-systems.com http://www.dsp-systems.com private email to:- ray@netspace.net.au