News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Sieve of Eratosthenes several variations

Started by zedd151, February 23, 2025, 01:45:36 AM

Previous topic - Next topic

NoCforMe

Fixed it (problem was in display code, not the actual sieve code).
Now the display separator character is in an EQUate @ top of code, so easily changed.
One might want to write #s to a file instead.
Assembly language programming should be fun. That's why I do it.

zedd151

Quote from: NoCforMe on February 24, 2025, 07:29:11 AMOne might want to write #s to a file instead.
SieveOfErastothenes 1000>out.txt

'1' shouldn't be there. Yes I know it does not sound logical, given it is only divisible by itself or 1. But that's the way it is.

Prime numbers to 100, plus many, many other sources.
¯\_(ツ)_/¯   :azn:

'As we don't do "requests", show us your code first.'  -  hutch—

NoCforMe

You're correct, of course.
Will fix it later ...
Assembly language programming should be fun. That's why I do it.

zedd151

¯\_(ツ)_/¯   :azn:

'As we don't do "requests", show us your code first.'  -  hutch—

FORTRANS

Hi,

Quote from: zedd151 on February 24, 2025, 01:35:43 AMHi Steve. Interesting. I am sure that daydreamer would like to see that code, if it is still available.

   Located the code.  Sieve code; 16-bit and I hardly recognize it.  Display code;
16-bit and VESA, mostly looks okay?.  Varying line length/picture width code;
nothing.  Save image code; nothing.  Some executables if you can run DOS plus
VESA Modes 103, 105, or 107?

Regards,

Steve

zedd151

Hi Steve. I only mentioned it because I thought that daydreamer (Magnus) might be interested in it. Not for me, I don't speak DOS, and certainly not VESA. I will let Magnus weigh in... he might want to see it. Thanks for digging through your archives though, Steve.
¯\_(ツ)_/¯   :azn:

'As we don't do "requests", show us your code first.'  -  hutch—

sinsi

I would make one change to your original code
  done1:
    mov     eax,curnumber
  @10:
    inc     eax
    cmp     eax,arrsize
    jae     done2
    cmp     byte ptr [esi+eax],0
    jz      @10
    mov     curnumber,eax
    jmp     @b
   
  done2:
You don't need to chek every number. If you've marked off all multiples of 2 there's no need to do the same for 4, 6 ...

With a bigger buffer it runs noticeably quicker.

NoCforMe

Yes. In my sieve code, after marking out all the even #s I start at 3 to eliminate multiples as non-primes, and advance my current # by 2 to skip all the even #s.
Assembly language programming should be fun. That's why I do it.

sinsi

The same logic goes for 3s. If you've marked off 3, 6, 9... then no need to do 9, 18, 27... since the 3 takes care of them.
You mark off multiples of the next unmarked number.

zedd151

Quote from: sinsi on February 24, 2025, 11:14:18 AMYou don't need to chek every number. If you've marked off all multiples of 2 there's no need to do the same for 4, 6 ...

With a bigger buffer it runs noticeably quicker.
okay.  :smiley:  I *might* revisit the code at some point. But I am not young anymore. Time is something I do not have an abundance of, and I have many other projects that need to get finished, and fully working. This code at least, already does exactly what it is intended to do. Now if you were to tell me that the results contain errors, or the program crashes, then most likely  I would take care of that ASAP.  :smiley:
You can think of my code as a starting point, if you or anyone else would like to optimize it further, I would not complain.  :biggrin:
¯\_(ツ)_/¯   :azn:

'As we don't do "requests", show us your code first.'  -  hutch—

sinsi

Quote from: zedd151 on February 24, 2025, 01:05:55 PMNow if you were to tell me that the results contain errors
I can't count that high :badgrin:

zedd151

¯\_(ツ)_/¯   :azn:

'As we don't do "requests", show us your code first.'  -  hutch—

daydreamer

Quote from: zedd151 on February 24, 2025, 07:30:26 AM
Quote from: NoCforMe on February 24, 2025, 07:29:11 AMOne might want to write #s to a file instead.
SieveOfErastothenes 1000>out.txt

'1' shouldn't be there. Yes I know it does not sound logical, given it is only divisible by itself or 1. But that's the way it is.

Prime numbers to 100, plus many, many other sources.
I have a primes.inc file with all primes between 0-65536 ,using DW in my 128 bit random generator thread
https://masm32.com/board/index.php?topic=7938.msg103022#msg103022
So you could include it into your program and cmp if its correct
@Steve I want to see your code ,its probably possible to port to 32 bit ,output BMP

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

daydreamer

Sinsi ,nocforme
https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
Look at animated gif and see in which order it multiplies to understand its mul 2,3,5,7,11,13...

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

TimoVJL

May the source be with you