예제 #1
0
        public void TestOpCodeInstructionParse(int startVal, int[] expectedResults)
        {
            OpCodeInstruction curInst = new OpCodeInstruction(startVal);

            // parammodes, then instruction
            Assert.Equal(expectedResults[0], (int)curInst.GetParamMode(0));
            Assert.Equal(expectedResults[1], (int)curInst.GetParamMode(1));
            Assert.Equal(expectedResults[2], (int)curInst.GetParamMode(2));
            Assert.Equal(expectedResults[3], (int)curInst.GetInstruction());
        }
예제 #2
0
        public static OpCode ReadNextOpCode(IntComputer computer)
        {
            // 1002
            //ABCDE
            //01002 = DE = opcode, c = mode for op 1, b mode for op 2 a, mode for op 3

            long opCodeData = computer.ReadNextMemoryAddress();
            OpCodeInstruction newInstruction = new OpCodeInstruction(opCodeData);

            switch (newInstruction.GetInstruction())
            {
            case OpCodeInstruction.OPCODE_TYPES.ADD:
                return(new AddOpCode(newInstruction));

            case OpCodeInstruction.OPCODE_TYPES.MUL:
                return(new MulOpcode(newInstruction));

            case OpCodeInstruction.OPCODE_TYPES.EXIT:
                return(new ExitOpCode(newInstruction));

            case OpCodeInstruction.OPCODE_TYPES.INPUT:
                return(new InputOpCode(newInstruction));

            case OpCodeInstruction.OPCODE_TYPES.OUTPUT:
                return(new OutputOpCode(newInstruction));

            case OpCodeInstruction.OPCODE_TYPES.JUMP_IF_TRUE:
                return(new JumpIfTrueOpCode(newInstruction));

            case OpCodeInstruction.OPCODE_TYPES.JUMP_IF_FALSE:
                return(new JumpIfFalseOpCode(newInstruction));

            case OpCodeInstruction.OPCODE_TYPES.LESS_THAN:
                return(new LessThanOpCode(newInstruction));

            case OpCodeInstruction.OPCODE_TYPES.EQUALS:
                return(new EqualsOpCode(newInstruction));

            case OpCodeInstruction.OPCODE_TYPES.ADJUST_RELATIVE_BASE:
                return(new AdjustRelativeBaseOpCode(newInstruction));

            default:
                Console.WriteLine("DER FARK?");
                return(null);
            }
        }
예제 #3
0
 public OpCode(OpCodeInstruction newInstruction)
 {
     curInstruction = newInstruction;
 }
예제 #4
0
 public MulOpcode(OpCodeInstruction newInstruction) : base(newInstruction)
 {
 }
예제 #5
0
 public EqualsOpCode(OpCodeInstruction newInstruction) : base(newInstruction)
 {
 }
예제 #6
0
 public AdjustRelativeBaseOpCode(OpCodeInstruction newInstruction) : base(newInstruction)
 {
 }
예제 #7
0
 public LessThanOpCode(OpCodeInstruction newInstruction) : base(newInstruction)
 {
 }
예제 #8
0
 public JumpIfFalseOpCode(OpCodeInstruction newInstruction) : base(newInstruction)
 {
 }
예제 #9
0
 public OutputOpCode(OpCodeInstruction newInstruction) : base(newInstruction)
 {
 }
예제 #10
0
 public ExitOpCode(OpCodeInstruction newInstruction) : base(newInstruction)
 {
 }
예제 #11
0
 public AddOpCode(OpCodeInstruction newInstruction) : base(newInstruction)
 {
 }