title: MIPS: Calculating BEQ into Hexadecimal Machine Code
body: <p>I have an assignment where I have to convert MIPS instructions into its hexadecimal machine code. I know how to convert the add, addi, lw, etc. instructions just fine, but when it gets to instructions like beq, I get confused. How would I convert this beq to hex?</p>
  
  <pre><code>0x00400108   beq $t3, $t5, NEXT
  0x0040010C   j END
  </code></pre>
  
  <p>where the address of NEXT is</p>
  
  <pre><code>0x0040011C
  </code></pre>
  
  <p>?</p>
  
  <p>What I've tried:</p>
  
  <p>beq opcode = 4</p>
  
  <p>$t3 = register 11</p>
  
  <p>$t5 = register 13</p>
  
  <p>NEXT = 0x0040011C - 0x0040010C = 10 (hex) =  16 (decimal)</p>
  
  <pre><code>4 11 13 16 (decimal)
  000100 01011 01101 0000 0000 0000 1000 (convert to binary)
  0001 0001 0110 1101 0000 0000 0000 1000 (group into fours)
  1 1 6 D 0 0 0 8 (hexadecimal)
  </code></pre>
  
  <p>but it's wrong...</p>