I need to get a MIPS program to print out the first 30 prime numbers and to compute the first 200 (strange, but its the assignment). I can figure out what's wrong with this program. All it does is print 2's out in an infinite loop and I cannot figure out why. We're only supposed to use three procedures (main, testprime, and print) but I'm so bad that I decided to use more. Thank you in advance for helping me.
.text
.globl main
main:
# intialize values
ori $s0, $0, 20
ori $s1, $0, 30
ori $s2, $0, 2
ori $s3, $0, 2
loop:
ori $s3, $0, 2
beq $s0, $0, exit
beq $t0, $s4, print
j testprime
testprime:
beq $s2, $s3, prime
div $s2, $s3
mfhi $t1
beq $t1, $0, noprime
addi $s3, $s3, 1
j testprime
noprime:
ori $t0, $0, 0
addi $s2, $s2, 1
j loop
prime:
ori $t0, $0, 1
sub $s0, $s0, $s4
addi $s2, $s2, 1
j loop
print:
ori $t0, $0, 0
beq $s1, $0, loop
sub $s1, $s1, $s4
li $v0, 1
or $a0, $0, $s2
syscall
li $v0, 4
la $a0, newline
syscall
j loop
exit:
li $v0, 10
syscall
.data
newline: .asciiz "\n"