title: How do I decode a machine instruction to assembly in LEGv8?
body: <p>I am having trouble figuring out how a LEGv8 machine instruction is decoded. Assume the following binary:</p>
  
  <p><strong>1000 1011 0000 1111 0000 0000 0001 0011</strong></p>
  
  <p>I have the following chart that is supposed to help me decode:</p>
  
  <p><a href="https://i.stack.imgur.com/BWLrW.png" rel="nofollow"><img src="https://i.stack.imgur.com/BWLrW.png" alt="LEGv8 instruction encoding/decoding chart"></a></p>
  
  <p>The first 11 bits <strong>10001011000</strong> correspond to decimal <strong>1112</strong> and according to the chart this is the <strong>ADD</strong> instruction. So I know how to determine this part of the instruction (unless there is a better approach, maybe this won't work for opcodes that aren't 11 bits?). At this point I am confused on how to proceed.</p>
  
  <p>I know that ADD is of instruction format <strong>R-format</strong> so the bits are layed out as below:</p>
  
  <p>opcode: 11 bits<br>
  Rm: 5 bits<br>
  shamt: 6 bits<br>
  Rn: 5 bits<br>
  Rd: 5 bits</p>
  
  <p>I attempt to lay out the initial binary machine instruction knowing these field sizes...</p>
  
  <p>opcode = <strong>1000 1011 000</strong>0 1111 0000 0000 0001 0011 = <strong>10001011000</strong><br>
  This is the first 11 bits of the initial binary machine instruction.</p>
  
  <p>Rm = 1000 1011 000<strong>0 1111</strong> 0000 0000 0001 0011 = <strong>01111</strong><br>
  This is the next 5 bits after the initial 11 bits for opcode.</p>
  
  <p>shamt = 1000 1011 0000 1111 <strong>0000 00</strong>00 0001 0011 = <strong>000000</strong><br>
  This is the next 6 bits after the 5 bits for Rm.</p>
  
  <p>Rn = 1000 1011 0000 1111 0000 00<strong>00 000</strong>1 0011 = <strong>00000</strong><br>
  This is the next 5 bits after the 6 bits for shamt.</p>
  
  <p>Rd = 1000 1011 0000 1111 0000 0000 000<strong>1 0011</strong> = <strong>10011</strong><br>
  This is the last 5 bits in the binary machine instruction (the 5 bits after the 5 bits for Rn).</p>
  
  <p>Converting binary to decimal for the Rm, Rn and Rd I get:</p>
  
  <p>Rm = 15 = <strong>X15</strong><br>
  Rn = 0 = <strong>X0</strong><br>
  Rd = 19 = <strong>X19</strong><br></p>
  
  <p>Therefore my final answer to decoding the initial binary machine instruction to an assembly statement would be <strong>ADD X19, X0, X15</strong></p>
  
  <p>However the textbook answer where this example is from is <strong>ADD X16, X15, X5</strong>. Where did I go wrong?</p>