; Rosemary Francis 2004

; This program calculates the first 1024 primes very inefficiently!
; note - 1 is not a prime!


primes
	movi r5 2 	;current int
	movi r6 0 	;last address
	movi r7 0 	;current addres
	
 	st r5 r6
	addi r5 1

	movi r3 1
	lsli r3 10 	;r3 = 1024

found	addi r6 2
	st r5 r6
rejected
	addi r5 2
	movi r7 2

	cmp r5 r3
	ifs cc_gt
	br endprimes
	nop

test	ld r1 r7
	bsr mod
	mov r0 r5
	cmpi r0 0
	ifs cc_eq
	br rejected	
	cmp r7 r6
	ifs cc_ne
	br test
	addi r7 2
	br found
	nop

#include mod.s 	;r0 = r0 mod r1

endprimes nop
