I'm learning MIPS by using QtSpim. In the code below, a remu pseudo-instruction is expanded to include a break instruction. I imagine that the break is to catch a divide by zero, but in this case, it stops the code from functioning regardless:
.text
.globl main
main: li $s0, 113 # $s0 holds n, the number to test.
div $s1, $s0, 2 # $s1 is n / 2, the limit for the loop.
li $s2, 2 # $s2 is the counter starting at 2.
while: beq $s2, $s1, set
nop
remu $s3, $s0, $s2
beq $s3, $0, unset
nop
addiu $s2, $s2, 1
j while
nop
unset: li $s7, 0 # $s7 is unset if n isn't prime.
j end
nop
set: li $s7, 1 # $s7 is set because n is prime.
end:
The remu instruction is expanded to:
[00400040] 16400001 bne $18, $0, 4 ; 10: remu $s3, $s0, $s2
[00400044] 0000000d break
[00400048] 0212001b divu $16, $18
[0040004c] 00009810 mfhi $19
The break instruction is always stopping the code, even if $18 ($s2) is non-zero.