title: Parsing hex into an LC3 ADD instruction
body: <p>I am writing a program in C to convert a hex file compiled for <a href="http://en.wikipedia.org/wiki/LC-3" rel="nofollow">the LC3 processor</a> back into assembly language. </p>
  
  <p>Currently, I am trying to decode the <code>ADD</code> instruction.</p>
  
  <p>There are two types of <code>ADD</code>s in LC3 assembly language:</p>
  
  <ul>
  <li><strong>add by reference</strong>: adding two registers</li>
  <li><strong>add immediate</strong>: adding a register to a hard-coded value</li>
  </ul>
  
  <p>For example, the hex code <code>164F</code> would be converted to: <code>ADD R3, R1, R7</code>. this is an add by reference. Conversely, the hex code for <code>153F</code> would be converted to: <code>ADD R2, R4, #-1</code>. This is an add immediate.</p>
  
  <p>The function should decode both as appropriate.</p>