public ControlUnitOutput Do(Byte2 data, bool clock)
        {
            var decodedInstruction = InstructionDecoder.Decode(data);

            var selectedSourceMemory =
                Select16.Do(decodedInstruction.SourceMemory,
                            _memoryOutput.Ram,
                            _memoryOutput.A);

            _aluOutput =
                ArithmeticLogicUnit.Do(decodedInstruction.Operation,
                                       _memoryOutput.D,
                                       selectedSourceMemory);

            _selectedBasedOnComputationInstruction =
                Select16.Do(decodedInstruction.ComputationInstruction,
                            _aluOutput,
                            decodedInstruction.w);

            _memoryOutput = _memory.Do(decodedInstruction.Destination,
                                       _selectedBasedOnComputationInstruction,
                                       clock);

            var isCondition =
                ArithmeticLogicUnit.Evaluate(decodedInstruction.Condition,
                                             _aluOutput);

            return(new ControlUnitOutput(isCondition, _memoryOutput.A));
        }
示例#2
0
        public void X_should_return_X()
        {
            // Arrange
            var opcodeX = Opcodes.X();

            // Act
            var output = ArithmeticLogicUnit.Do(opcodeX, new Byte2(42), new Byte2(127));

            // Assert
            output.ToInt16().Should().Be(42);
        }
示例#3
0
        public void Add_should_return_x_plus_y()
        {
            // Arrange
            var opcode = Opcodes.Add();

            // Act
            var output = ArithmeticLogicUnit.Do(opcode, new Byte2(27), new Byte2(45));

            // Assert
            output.ToInt16().Should().Be(72);
        }
示例#4
0
        public void Bitwise_complement_y_should_return_negative_y_minus_1()
        {
            // Arrange
            var opcode = Opcodes.ComplementY();

            // Act
            var output = ArithmeticLogicUnit.Do(opcode, new Byte2(27), new Byte2(42));

            // Assert
            output.ToInt16().Should().Be(-43);
        }
示例#5
0
        public void XorY_should_return_bitwise_or()
        {
            // Arrange
            var opcodeX = Opcodes.XorY();

            // Act
            var output = ArithmeticLogicUnit.Do(opcodeX, new Byte2("1000000000000001"), new Byte2("0100000000000011"));

            // Assert
            output.ToString().Should().Be("1100000000000011");
        }
示例#6
0
        public void Test6()
        {
            // Arrange
            var byte2X    = new Byte2(27);
            var byte2Y    = new Byte2(-16);
            var operation = new InstructionDecoder.Operation(false, false, true, true, false, true);

            // Act
            var output = ArithmeticLogicUnit.Do(operation, byte2X, byte2Y);

            // Assert
            output.ToUInt16().Should().Be(65508);
        }