Scott Dattalo wrote: > One of the tricks that this routine does is to simultaneously multiply > and divide. This works well for two operands, but I don't see how to > make it work for three. Also, the 'multiplication' is a bit-by-bit > either-or operation. In other words, at each stage of the > multiplication, the cumulative product is either being increased by > one coefficient or the other. Short of going to trits, I don't see > how to handle three operands at the same time. Could you be more > specific? Easey-peasey! Let me find the original.... twist3: movf y,w movwf num btfsc A,0 movf x,w btfsc B,0 movf z,w addwf num,f rrf num,f movf y,w ;A macro would work well here... btfsc A,1 ;All we're doing is an un-rolled movf x,w ;multiplication. If a bit in 'A' is btfsc B,1 ;set, we add 'y' to the running sum movf z,w ;or if a bit in 'B' is set, we add 'z' addwf num,f ;otherwise we add 'x'. In either case rrf num,f ;we divide by 16 overall. movf y,w btfsc A,2 movf x,w btfsc B,2 movf z,w addwf num,f rrf num,f movf y,w btfsc A,3 movf x,w btfsc B,3 movf z,w addwf num,f rrf num,f return Note that A & B = 0 (although the algorithm won't overflow) Coefficients for x, y and z are (16-A-B)/16, A/16 and B/16 -- Cheers, Paul B.