Paul H. Dietz wrote: > I'm usually a lurker, but here's my two cents for someone with > more time than me: > > Consider (A - B)^2 = A^2 + B^2 - 2AB > > so AB = (A^2 + B^2 - [A-B]^2)/2 > > Since 101 > A > B, a small lookup table will suffice for all > the squares. (Note that A - B > 101 too!) > > I'm not sure that this would end up being much faster, but at > least it's different... Phil: Good thinking. Your method's slower than 34 cycles, though... If you consider that a table lookup takes 6 sycles (2 for the "CALL", 2 for the "ADDWF PC", and 2 for the "RETLW xx") and that your routine requires 3 two-byte table lookups, you'll see that the table lookups alone require 36 cycles. Add to that the time required for a two-byte addition and a two-byte subtraction, and the total times comes close to 50 cycles. On the other hand, yours doesn't have the "both values must be even, or both values must be odd" restriction. My 34-cycle method multiplies SMALL*LARGE by using the observation that (a+b) * (a-b) = a*a - b*b. Given two numbers, SMALL and LARGE, it computes: b = (LARGE-SMALL)/2 a = SMALL + b then it looks up a*a and b*b in a big table and subtracts b*b from a*a. In the Challenge rules, I allowed the routine to be restricted to numbers that are both odd or both even, so "b" is guaranteed to be even (and, therefore, b/2 is guaranteed to be an integer), and specified that LARGE is never smaller than SMALL, so I don't have to worry about "b" being negative. Anyway, neither yours nor mine is as good as Scott Dattalo's, so he wins the prize. -Andy === Meet other PICLIST members at the Embedded Systems Conference: === 6:30 pm on Wednesday, 1 October, at Bytecraft Limited's booth. === === For more information on the Embedded Systems Conference, === see: http://www.embedsyscon.com/ === Andrew Warren - fastfwd@ix.netcom.com === Fast Forward Engineering - Vista, California === http://www.geocities.com/SiliconValley/2499