Re: LF: Prime Number Generator


[Prev][Next][Index][Thread]

Re: LF: Prime Number Generator



In a message dated 96-12-22 13:41:42 EST, you write:

<< I am going to writing a prime number generator for 68k assembly.  I have
 written a generator for BASIC, and I'm about to translate it into assembly.
  Does anyone have ANY ideas on how to make this program more efficient. 
 (Just make some changes to the code, and send them back to me.)  One more
 thing, this generator gets all the prime numbers from 3 and up.  It skips
 the number 2 for the sake of speed...
 
 CLS
 OPEN "PRIME.DOC" FOR OUTPUT AS #1
 Counter = 1
 1 Counter = Counter + 2
 Divider = 3
 DO
  Divided = Counter / Divider
  IF FIX(Divided) - Divided = 0 THEN GOTO 1
  IF Divider >= SQR(Counter) THEN GOTO 2
  Divider = Divider + 2
 LOOP
 2 PRINT #1, Counter
 SEEK (1), LOF(1) - 2
 LOCATE 1, 1: PRINT Counter
 GOTO 1
 
 The only way to stop this program in BASIC is with the CTRL-BRK sequence.
 
 When you send the code back to me (with changes you have made), send the
 whole program.
 
 Jonathan Oliver
 daemon1@napanet.net
  >>
nope. as far as I know, that's as effecient as it can get. in the 68K
version, do a DIVU (divide unsigned) instruction. then SWAP the result, and
the lower word is the remainder. if it is not zero, etc...

Tilde,
Jeffrey :j
JBridge21@aol.com
***ROM 1.2***