Hi! El Wed, Mar 10, 2004 at 09:40:28PM +0100, Wouter van Ooijen escribio: > Someone asked me for a fast yet not extremely large code snipped to > divide a one-byte value in memory by 7 (on a 14-bit core). I think I > have a straight-line (no loop) code that uses 33 instructions (2 less if > the source can be destroyed). Looping version would be 12 instructions, > but of course somewhat longer execution. Can anyone do it faster, > preferrably with fewer instructions? I know a table lookup will be > faster, but I think the 256+ size would be classified as 'extremely > large'. You could try coding: div = (x*8 + x + x/4 - x/16 - x/64)/64 It gives correct results up to x=285. But it needs an 11-bit acumulator. I think that it's faster coding using 12bit acumulator: div = (x*16 + x*2 + x/2 - x/8 )/128 (acurate only up to 201) or div = (x*16 + x*2 + x/2 - x/8 - x/16) / 128 (acurate up to 663) The later has x*16 and x/16, that are easily obtained by swap's. Other formulas can be derived easily... Daniel. -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu