flat assembler
Message board for the users of flat assembler.

 flat assembler > Test Area > Producing Sequential Primes (without a cache miss)...
Author
bitRAKE

Joined: 21 Jul 2003
Posts: 2672
Location: dank orb
Do you think there is an algorithm to produce the primes sequentially? Using no multiplication/division? Well here it is...
Code:
```    mov ecx,1
mov ebx,1
mov rax,1
mov edx,25
FindPrimes:
add rcx,2           ; next odd number
add rbx,1           ; next integer
add rax,rcx         ; next square
.Check:
cmp rax,rdx
jz .Prime
jc .notPrime
jmp .Check
.Prime:
push rbx ; output RBX as prime, or (RCX+1)/2 is prime
.notPrime:
jmp FindPrimes    ```

_________________
21 Nov 2018, 05:59
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 16128
Location: Hyperborea
I assume you mean no Icache miss?

Does it produce all primes from 2 onwards? I can't see how it outputs 2.
21 Nov 2018, 06:45
tthsqe

Joined: 20 May 2009
Posts: 720
This code outputs numbers > 1 that have no factor in common with 24. This is the same as the sequence of primes only in the first few cases.
It also does so rather inefficiently, rdx is on the order of rbx squared.
In summary a big disappointment
21 Nov 2018, 21:36
redsock

Joined: 09 Oct 2009
Posts: 293
Location: Australia
Agreed, useless ... 25 is not prime

Not to mention, even if the algorithm were correct, a naive increment+trial by division is better than this ...

I had fun taking a few moments and headscratching it anyway, thanks bitRAKE, the fact that you put it in "Test Area" would normally have been a red flag for me not to bother but the code looked plausible hahah

_________________
2 Ton Digital - https://2ton.com.au/
21 Nov 2018, 21:58
bitRAKE

Joined: 21 Jul 2003
Posts: 2672
Location: dank orb
Just testing...

Number theory would fall apart if it were possible.
Hopefully, the disappointment was not too big.
22 Nov 2018, 01:21
tthsqe

Joined: 20 May 2009
Posts: 720
I'm sure I'm not the only one who though your fasm account got hijacked. Usually these types of things are saved for April.
22 Nov 2018, 15:40
bitRAKE

Joined: 21 Jul 2003
Posts: 2672
Location: dank orb
It is only a matter of time (for the hacking). Sorry, for the confusion then.
26 Nov 2018, 10:58
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------Blog General----------------MainDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsCompiler InternalsIDE DevelopmentOS ConstructionNon-x86 architecturesHigh Level LanguagesProgramming Language DesignProjects and IdeasExamples and Tutorials Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum