title: MIPS label addressing?
body: <p>This is all related, and I tried to piece it all together as logically as I could, so please bear with me.</p>
  
  <p>I'm really confused as to how to properly address labels. For example, in the following bit of code, "bne" translates to "00010101001001010000000000000001", and the label address of loopend is 0x00000020 (32)</p>
  
  <pre><code>.text
      la $a0, opOne   
      lw $a0, 0($a0)
      la $a1, opTwo
      lw $a1, 0($a1)
      add $t0, $zero, $a0
      addi $t1, $zero, 1
      bne $t1, $a1, loopend
      addi $t1, $t1, 1
  loopend:
  </code></pre>
  
  <p>When I move loopend up, "bne" becomes "00010101001001011111111111111011" and the address of loopend becomes 0x00000008 (8)</p>
  
  <pre><code>.text
      la $a0, opOne   
      lw $a0, 0($a0)
  loopend:
      la $a1, opTwo
      lw $a1, 0($a1)
      add $t0, $zero, $a0
      addi $t1, $zero, 1
      bne $t1, $a1, loopend
      addi $t1, $t1, 1
  </code></pre>
  
  <p>So from what I understand, in the first bit of code, <code>loopend</code> is after eight instructions, so its address is 4*8=32=0x00000020. In the second bit of code, <code>loopend</code> is after two instructions, so its address is 4*2, or 0x00000008.</p>
  
  <p>What I don't understand, however, are the label addresses. Correct me if I am wrong: the label address depends on where the label is in relation to the instruction calling it. So in the first bit of code, <code>loopend</code> is two lines later than <code>bne</code> so you do not flip the signs, and its address is "0000000000000001". On the second <code>loopend</code> comes before <code>bne</code> so you flip the sign and its address becomes "1111111111111011".</p>
  
  <p>I know you shift the addresses to the left 2 bits, but I'm still pretty confused. Do you only shift left if there are not two 0s at the end, like the second <code>loopend</code>?</p>
  
  <p>My most pressing question is this: where does 0000000000000001, the address of <code>loopend</code>, even come from in the first bne machine language translation? I thought that address of label <code>loopend</code> would be 0000000000100000.</p>