Error in public test that I don't understand


I used bgez $0 6 and it tells me that the 6 is of wrong type and I don’t understand why because in the lecture it was used just like that.

bgez <registry> <label> is supposed to branch to <label>, if the value in the registry is greater or equal to zero.


	# Load -1 into $a0
	li $a0 -1
	bgez $a0 addone
	b end
	addiu $a0 $a0 1
	b end
	# Print integer in $a0 and quit
	li $v0 1
	li $v0 10

This will not branch into addone, since the value in $a0 is not greater or equal to 0.

But if you would change the first line in main to this:

li $a0 1

the value in $a0 will be greater than 0 and it will branch to addone.

What you are probably looking for, is

sle $t0 $zero 6

This will store in $t0, whether the value of $zero (0) is lower or equal to 6.

1 Like

Ok I actually wanted it to jump 6 lines further, but I now just used labels in front of the line I wanted it to jump to and fixed it thank you very much.

Yes, MARS does not let you write code like this since it’s bad practice, a maintainance/debugging hazard, and will cause problems later on.