When you need values of arrays like X^2; (X+1)^2;(X+2)^2... or X^2;(X+2)^2... etc.
for example 144^2;148^2;152^2
If you know X and X^2 you may calculate any X+n ^2 or X-n ^ 2 if n is reasonably small in 1 or 2 clocks.
It based on very simple eqution that (X+n)^2 = X^2+nX + n^2
So sq. of near bigger number will be (X+1)^2 = X^2+2X+1
let we have
eax = X^2
ecx = X
lea edx,[1] ;edx = (X+1)^2 1 clock

(X+2)^2 = X^2+4X+4
lea edx,[4] ;edx = (X+2)^2 1 clock

(X+3)^2 = X^2+6X+9
lea edx,
lea edx,[9] ;edx = (X+3)^2 2 clocks

(X+4)^2 = X^2+8X+16
lea edx,[16] ;edx = ^2 1clock

And so on
The same calculations might be performed if we need (X-n)^2
we need negate ecx and do the same command 'cause (X-n) = X^2-Xn+n^2
neg ecx
lea edx,[1] ;edx = (X-1)^2
Posted on 2001-11-27 22:52:29 by The Svin