LF: prime number source?


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

LF: prime number source?



I found this Eratosthenes Sieve Prime number program in a m68k
programming guide.  I think that the prime factorization of the 92 fits
my needs fine, and am not going to make this into a fargo program.  If
any one else wants too....go ahead.  This is not a functionably Fargo
program(yet) and will not work with out changing part of the code.  This
is the way I found it in the book(without the fargo headers!)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Down the bus, out the modem, over the line... nothin' but net.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Stephen Grigg         [grigg@juno.com]
	


	@program        prog_code,prog_name
	include         macros.h
prog_code:
	size .equ 8190       
	flags .equ 800h    ;base addresss of the FLAGS array
	iter .equ 10       ;number of iterations of the sieve(10 times)

	jsr     flib[clr_scr]
	move.w  #iter,d1  
	move.w  #size,d6
	movea.w #flags,a0
	bra.s   endil       ;enter the iteration loop at the proper place

startil:                                       ;start of the iteration
loop
	moveq   #1,d0
	move.w  d6,d2    ;load SIZE into D2
	movea.l a0,a1    ;address of element of FLAGS to set
	bra.s   $02

$01     move.b  d0,(a1)+
$02     dbra    d2,$01
	clr.w   d5    ;clear prime counter
	clr.w   d2     ;clear d0 loop counter

doloop:
	btst    #0,0(a0,d2.w)
	beq.s   then   ; if false, skip the true part of IF structure
	move.w  d2,d3
	add.w   d3,d3
	addq.w  #3,d3       ;P=I+I+3
	move.w  d3,d4
	add.w   d2,d4    ;K=P+I
begin:
	cmp.w   d6,d4
	bge.s   $03
	clr.b   0(a0,d4.w)
	add.w   d3,d4
	bra.s   begin
$03     addq.w  #1,d5                    ;update prime counter
then    addq.w  #1,d2
	cmp.w   d6,d2
	blt.s   doloop
endil   dbra    d1,startil    'repeat for requested number of iterations

menu:
	jsr             flib[idle_loop]
	cmp             #264,d0
	beq             done
	bra             menu
done:
	rts

prog_name   dc.b "Prime 1.0",0

	reloc_open
	add_library     flib
	add_library     romlib
	reloc_close
	end


References: