title: MIPS: Calculating Displacement
body: <p>Working through some problems and I am confused by calculating the displacement. </p>
  
  <p>Some examples are:</p>
  
  <pre><code>top:    
  addi    $s2, $s2, -1
  addi    $s1, $s1, 1
  bne $s2, $0, top
  </code></pre>
  
  <p>Assume top has the value of 0x1000 0008.</p>
  
  <pre><code>top:    bne     $s1, $s2, end
  addi    $s1, $s1, 1        
  end:    j   top
  </code></pre>
  
  <p>Assume top has the value of 0x1000 0008.</p>
  
  <p>What is the displacement in the bne instructions?</p>
  
  <p>Can anyone explain how to calculate these? Thanks. </p>