protected void Decode(int instruction)
 {
     _instruction    = (Utils.CommandCode)((instruction & 0xF000) >> 12);
     _register1      = (instruction & 0xF00) >> 8;
     _register2      = (instruction & 0xF0) >> 4;
     _register3      = instruction & 0xF;
     _immediateValue = instruction & 0xFF;
 }
Ejemplo n.º 2
0
        private static void CompileThreeRegisterCommand(ref string[] values, Utils.CommandCode command)
        {
            var compiledCommand = command.ToInt() << 12;

            compiledCommand = (CompileRegisterValue(ref values[0]) << 8) | compiledCommand;
            compiledCommand = (CompileRegisterValue(ref values[1]) << 4) | compiledCommand;
            compiledCommand = (CompileRegisterValue(ref values[2])) | compiledCommand;

            FileStream.Add(compiledCommand);
        }
 public VM(int[] programStream)
 {
     /*
      * 1.) operation type
      * 2.) register
      * 3-4.) immediate value or target registers
      */
     _program     = programStream;
     _registers   = new int[NumberOfRegisters];
     _pc          = 0;
     _register1   = _register2 = _register3 = _immediateValue = 0;
     _instruction = Halt;
     _isRunning   = true;
 }