ADDI r31, r0, n ; r31 is 4 less than first address holding data LW r1, 4(r31) ; load into r1 the number we would like to test (n) SLTI r4, r1, #2 ; if the number is less than 2, without going further BNEZ r4, notprm ; we say it is not prime ADDI r2, r0, #2 ; let r2 be the divisor we would like to test (i) nexti: MULT r3, r2, r2 ; let r3 be i squared SGT r4, r3, r1 ; if this is greater than n, then we can stop BNEZ r4, notprm ; since we know n is not prime MOD r3, r1, r2 ; let r3 be the remainder of n divided by i BNEZ r3, nexti ; if it is not zero, go to the next i ADDI r2, r2, #1 ; but we add one to i first (the delay slot) isprm: SW 8(r31), r0 ; n is prime; store 0 in memory TRAP #0 ; end the program notprm: SW 8(r31), r4 ; n is not prime; store 1 in memory TRAP #0 ; end the program data: .word 131 ; the number n to be tested .word -1 ; will be 0 if n is not prime, 1 if it is