; This program takes the number to be tested from the memory location ; located at `n' and places the result in the memory location located at ; `out'. ; ; When I ran the program, it appeared that the DLX assembler requires ; TABs between the opcode (like slti) and the arguments (r4, r1, #2). ; It also appears to insist on lower-case letters. lw r1, n ; 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: mul 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 out, r0 ; n is prime; store 0 in memory trap #0 ; end the program notprm: sw out, r4 ; n is not prime; store 1 in memory trap #0 ; end the program data: .data n: .word 131 out: .word -1