On Thu, Jun 26, 2003 at 05:13:46PM +0100, Sergio Masci wrote: > From: Daniel Serpell > > Assuming that this is actually giving you what you want and that acc is 16 bits, > the first 3 iterations of the loop can be perfomed on 8 bit acc and the > remainder on 16 bit acc. Also your lookup table will require 256 entries I'm not thinking on using lookup tables. The code will be: ; This code is under the GNU LGPL License, ; see http://www.gnu.org/copyleft/lesser.html cbits MACRO data rrf data,W andlw 0x55 subwf data,F movlw 0x33 andwf data,W addwf data,F rrf data,F addwf data,F rrf data,F swapf data,W addwf data,W andlw 0x0F ENDM add8val: clrf acch cbits data0 movwf accl ; max = 8 cbits data1 rrlf accl,F addwf accl,F ; max = 24 cbits data2 rrlf accl,F addwf accl,F ; max = 56 cbits data3 rrlf accl,F addwf accl,F ; max = 120 cbits data4 rrlf accl,F addwf accl,F ; max = 248 cbits data5 rrlf accl,F rrlf acch,F addwf accl,F btfsc STATUS,C incf acch,F ; max = 504 cbits data6 rrlf accl,F rrlf acch,F addwf accl,F btfsc STATUS,C incf acch,F ; max = 1016 cbits data7 rrlf accl,F rrlf acch,F addwf accl,F btfsc STATUS,C incf acch,F ; max = 2040 That's exactly 121 cycles, and 121 program words. But seeing it writen, I have found an error (try to spot it!), so 7 more instructions are needed (with 128 cycles total). The code can be expanded for more than 8 bits. Daniel. -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads