title: Encoding instructions in C
body: <p>Very new to this concept, and I've been referencing other instruction sets out there, but I've been trying to create a virtual machine where I actually encode the instructions.</p>
  
  <p>This is what I've got:</p>
  
  <pre><code>enum OPCODE {
      MOV,
  };
  
  enum TARGET {
      A, B,
  };
  
  struct instr {
      unsigned char opcode;
      unsigned char target;
      uint64_t immediate;
  };
  </code></pre>
  
  <p>Basically I have an instruction that has a 1 byte opcode, a 1 byte target, and a 8 byte immediate value. So for instance, a move instruction like: <code>MOV A, 50</code> that moves the value 50 into a will be 0, 0, 50 assuming that mov's opcode is 0, and the A register is 0.</p>
  
  <p>How would I go around encoding this into a single value? The instruction adds up to an 80 bit/10 byte value which, as far as I know, is not a native type in C. What type would I use, and to store this could I use a union to squash it all into a single value?</p>
  
  <p>... am I approaching this correctly at all?</p>