Example #1
0
        public List <int> Run()
        {
            List <int> output = _program.ToList();

            int         currentInstructionAddress = 0;
            IExecutable instruction;

            do
            {
                instruction = _instructionFactory.Create(
                    output,
                    _opcodeParser.Opcode(output[currentInstructionAddress]),
                    Parameters(output, currentInstructionAddress));

                instruction.Execute();

                currentInstructionAddress += instruction.ParametersCount + 1;
            }while (!instruction.Halt);

            return(output);
        }
Example #2
0
        public Instruction Resolve(BitArray rawInstruction)
        {
            if (_instructionFactory != null)
            {
                return(_instructionFactory.Create());
            }

            foreach (var resolverConfig in _opSizes)
            {
                var sample = rawInstruction.CopySlice(_offset, (int)resolverConfig.Key);

                if (resolverConfig.Value.TryGetValue(sample.ToUnsignedInt(), out var resolver))
                {
                    var result = resolver.Resolve(rawInstruction);

                    if (result != null)
                    {
                        return(result);
                    }
                }
            }

            return(null);
        }