> > > Is there scope to break it down into three simpler multiplications? > > > > > > (a+b)^2 = a^2 + b^2 + 2ab > hmmmm ...methinks I need an intuition implant... > my gut feel was that something like Andy W's "straight line" > solution would be a bit quicker than a few smaller calculations > whose results are combined. My gut feel isn't the most reliable > indication of anything, though :-) I'm working on improving it. > > Thanks to Keith, Andy and Scott for excellent suggestions > and examples... looks like I've got a few routines to > write! If I'm brave enough, I'll post the fastest one I can > come up with this week. Something like this? [warning: untested] clrf DstH clrf DstM clrf DstL movf SrcL,w andlw $0F btfss Src,4 addwf DstM rrf DstM rrf DstL btfss Src,5 addwf DstM rrf DstM rrf DstL btfss Src,6 addwf DstM rrf DstM rrf DstL btfss Src,7 addwf DstM call Sqr4 addwf DstL swapf SrcL andlw $0F call Sqr4 addwf DstM ; At this point, 16-bit result is in DstM:DstH ; 25 words of code prior to this point (plus a ; 17-word table-lookup). Total execution time: ; 35 cycles up to this point. btfss SrcH,0 goto NoBit8 movf SrcL,w btfsc C incf DstH addwf DstM btfsc C incf DstH incf DstH ; Another 9 words for bit 8; 3 or 9 cycles to exec. NoBit8: btfss SrcH,1 goto NoBit9 movlw 4 btfss SrcH,0 movlw 8 addwf DstH rlf SrcL,w btfsc C incf DstH btfsc C incf DstH addwf DstM btfsc C incf DstH addwf DstM btfsc C incf DstH ; Another 17 words for bit 9; 3 or 17 cycles to execute ; Total worst-case time: 35+26 = 61 cycles. NoBit9: retlw 0 ; All done! Sqr4: addwf PC db 0,1,4,9,16,25,36,49,64,81,100,121,144,169,196,225