Just Eiler formula, for math addicts :)



.data?
primes dd 41 dup (?)
.code
start:
mov ecx,40
@@: mov eax,ecx
mul ecx
neg ecx
lea eax,[eax][ecx][41]
neg ecx
mov [ecx*4][offset primes],eax
dec ecx
jns @B
Posted on 2002-03-23 05:04:38 by The Svin


primes dd 40 dup(?) ; only 40 primes

mov ecx,40
@@: mov eax,ecx
dec ecx
js @F
mul ecx
add eax,41
mov [ecx*4][offset primes],eax
jmp @B
@@:
There is a small error, but only spent a couple seconds on it. :)
Fixed it.

Svin, doesn't your algo produce the same value when ECX is 0 and 1?

n^2 + n + 41 ; n=[0,39] ; Leonhard Euler formula


f(n) = n (n + 1) + 41

f(m-1) = m (m - 1) + 41

m (m - 1) + 41 ; m=[1, 40] ; m = n + 1
Posted on 2002-03-23 11:44:04 by bitRAKE
Yes, bitRake. It is Euler (I'm not sure for spelling)
n^2-n+41



.data?
primes dd 41 dup (?)
.code
start:
mov ecx,40
@@: mov eax,ecx
mul ecx
neg ecx
lea eax,[eax][ecx][41]
neg ecx
mov [ecx*4][offset primes-4],eax
dec ecx
jne @B
Posted on 2002-03-23 12:30:06 by The Svin
It is a little mathematics on parabolic interpolation.

align 16
entry:
mov ecx,40*40-40+41
mov edx,2*40
mov eax,40-1
nop
@@lp: sub edx,2
mov ,ecx
sub ecx,edx
dec eax
jns @@lp
ret

It in 2,3 times is faster than the last code.
Posted on 2002-03-24 14:42:41 by Nexo