0

I am trying to see if a variable ($a2) from my main method is greater than 0. If it is greater, $v1 should become 7 and if it is less than or equal $v1 should become 10 and the function will return the respective number. When I run the code, it always return 10 no matter what. Any suggestions to what I am doing wrong?

fme:
addi $t0, $zero, 0 #setting $t0 equal to 0

bgt $a2, $t0, GREATER
ble $a2, $t0, NOTGREATER

GREATER:
addi $v1, $zero, 7

NOTGREATER:
addi $v1, $zero, 10

jr $ra
Austin
  • 41
  • 2
  • 2
    Put a `jr $ra` before `NOTGREATER`. Also, one branch suffices with the right layout. – Margaret Bloom Feb 13 '18 at 21:34
  • 1
    `bgt $a2, $t0, GREATER` - you can use the `$zero` directly, like `bgt $a2, $zero, GREATER`, it's almost normal register, except all writes to it are ignored, and it will always read as zero value back. – Ped7g Feb 13 '18 at 21:57

0 Answers0