$MOD51
ORG 0
JMP START
START:
MOV R0,#16 ; Start of table
MOV R1,#3 ; Start at number 3
MOV @R0,#2 ; store the first prime number
INC R0 ; next
LOOP: MOV R6,#2 ; count from two
LP: MOV A,R1
MOV B,R6
DIV AB ; modulus number / count
MOV A,B
JZ BLP1 ; zero either divides by count or itself
DEC R1 ;\
MOV A,R6 ; | Test number = count
SUBB A,R1 ; |
INC R1 ;/
INC R6
JNZ LP ; Loop done
BLP1: MOV A,R6 ; Test if a prime
SUBB A,R1 ; by seeing if count run full course
JNZ NPRIME
PRIME: MOV A,R1 ; Primes are lobbed into table
MOV @R0,A
INC R0
NPRIME: MOV A, R1
SUBB A,#99 ; All 99 numbers done??
INC R1
JNZ LOOP
DONE: JMP DONE