Exemplo n.º 1
0
 public LessThanInstruction(InstructionCode instructionCode, int instructionPointer, int relativeBase)
 {
     _instructionPointer = instructionPointer;
     _first  = new RetrieveParameter(instructionCode.FirstParameterMode, instructionPointer + 1, relativeBase);
     _second = new RetrieveParameter(instructionCode.SecondParameterMode, instructionPointer + 2, relativeBase);
     _third  = new StoreParameter(instructionCode.ThirdParameterMode, instructionPointer + 3, relativeBase);
 }
        public IInstruction CreateInstruction(long code, int instructionPointer, int relativeBase)
        {
            var instructionCode = new InstructionCode(code.ToString());

            if (instructionCode.OpCode == OpCode.Add)
            {
                return(new AdditionInstruction(instructionCode, instructionPointer, relativeBase));
            }
            if (instructionCode.OpCode == OpCode.Multiply)
            {
                return(new MultiplyInstruction(instructionCode, instructionPointer, relativeBase));
            }
            if (instructionCode.OpCode == OpCode.Input)
            {
                return(new InputInstruction(instructionCode, instructionPointer, relativeBase, _inputQueue.Dequeue()));
            }
            if (instructionCode.OpCode == OpCode.Output)
            {
                return(new OutputInstruction(instructionCode, instructionPointer, relativeBase));
            }
            if (instructionCode.OpCode == OpCode.JumpIfTrue)
            {
                return(new JumpIfTrueInstruction(instructionCode, instructionPointer, relativeBase));
            }
            if (instructionCode.OpCode == OpCode.JumpIfFalse)
            {
                return(new JumpIfFalseInstruction(instructionCode, instructionPointer, relativeBase));
            }
            if (instructionCode.OpCode == OpCode.LessThan)
            {
                return(new LessThanInstruction(instructionCode, instructionPointer, relativeBase));
            }
            if (instructionCode.OpCode == OpCode.Equals)
            {
                return(new EqualsInstruction(instructionCode, instructionPointer, relativeBase));
            }
            if (instructionCode.OpCode == OpCode.RelativeBaseOffset)
            {
                return(new RelativeBaseOffsetInstruction(instructionCode, instructionPointer, relativeBase));
            }
            if (instructionCode.OpCode == OpCode.Stop)
            {
                return(new StopInstruction());
            }

            return(null);
        }
Exemplo n.º 3
0
 public JumpIfFalseInstruction(InstructionCode instructionCode, int instructionPointer, int relativeBase)
 {
     _instructionPointer = instructionPointer;
     _first  = new RetrieveParameter(instructionCode.FirstParameterMode, instructionPointer + 1, relativeBase);
     _second = new RetrieveParameter(instructionCode.SecondParameterMode, instructionPointer + 2, relativeBase);
 }
Exemplo n.º 4
0
 public OutputInstruction(InstructionCode instructionCode, int instructionPointer, int relativeBase)
 {
     _instructionPointer = instructionPointer;
     _first = new RetrieveParameter(instructionCode.FirstParameterMode, instructionPointer + 1, relativeBase);
 }
Exemplo n.º 5
0
 public InputInstruction(InstructionCode instructionCode, int instructionPointer, int relativeBase, long?input)
 {
     _instructionPointer = instructionPointer;
     _input = input;
     _first = new StoreParameter(instructionCode.FirstParameterMode, instructionPointer + 1, relativeBase);
 }