title: Trying to understand this MIPS function that branches if its input is negative
body: <p>I'm reading the following excerpt about assembly language code:</p>
  
  <p>"Labels can be used in assembly in replace[sic] of calculating exact values for branch and jump instructions. The following is an example."</p>
  
  <pre><code>int isNeg(int a0) {
    if (a0 &lt; 0) {
      return 1;
    } else {
      return 0;
    }
  }
  
  isNeg:
    slt  $t0 $a0 $0
    beq $t0 $0 isPos
    jr $ra
  isPos:
    add $v0 $0 $0
    jr $ra
  </code></pre>
  
  <p>Here's how I'm interpreting this (please correct me on any wrong assumptions I've made):</p>
  
  <pre><code>isNeg:
    slt $t0 $a0 $0 // store ($a0 &lt; 0) in $t0
    beq $t0 $0 isPos // if ($t0 == 0) branch by 0 bytes
    jr  $ra
  isPos:
    add $v0 $0 $0 // store 0+0=0 in $v0
    jr  $ra
  </code></pre>
  
  <p>So if my assumptions here are correct, then if $a is negative, we do nothing, and if $a is positive, then we branch by 0, which is the equivalent of doing nothing. Can anyone shed some light on this?</p>