title: MIPS Branch Instruction - Getting Branch Location
body: <p>I was wondering how to find the branch location of an instruction such as 
  <code>bne $s1, $s0, label_name</code>. From what I understand the 16-bit immediate value is a relative offset that should be added to the PC to branch. </p>
  
  <p>What I want to know is how the branch address is calculated as I am finding multiple, contradicting answers for the same thing.</p>
  
  <p>What I have found so far:</p>
  
  <ol>
  <li>Increment current PC by four.</li>
  <li>Shift immediate value (16-bit) left by two (multiply by four).</li>
  <li>Sign extend immediate value to 32-bits.</li>
  <li>Add the PC and immediate value.</li>
  </ol>
  
  <p>Is this correct? And if so, how would I sign extend this value in C? </p>