Exemplo n.º 1
0
        public void FlowControlOperationsTests_NEQ_AreNotEqual()
        {
            // NEQ Ra, Rb {F1} Cond <- R[Ra] != R[Rb]
            string ra = "010";          // 2
            string rb = "101";          // 5

            string valInA = "00101101"; // 45
            string valInB = "00101101"; // 45

            bool result = false;

            // set data in register
            micro.MicroRegisters.SetRegisterValue(
                UnitConverter.BinaryToByte(ra),
                UnitConverter.BinaryToHex(valInA));

            micro.MicroRegisters.SetRegisterValue(
                UnitConverter.BinaryToByte(rb),
                UnitConverter.BinaryToHex(valInB));

            Console.WriteLine(micro.MicroRegisters);

            Assert.AreEqual($"Registers[0,0,45,0,0,45,0,0]", micro.MicroRegisters.ToString());

            // start instruction
            MCInstructionF1 instructionF1 = new MCInstructionF1(4, "11100", ra, rb);

            Console.WriteLine(instructionF1);

            InstructionSetExe.ExecuteInstruction(instructionF1, micro);

            Console.WriteLine(micro);

            Assert.AreEqual(result, micro.ConditionalBit);
        }
Exemplo n.º 2
0
        public void FlowControlOperationsTests_GRT_Success2()
        {
            // GRT Ra, Rb {F1} Cond <- R[Ra] > R[Rb]
            string ra = "001";          // 1
            string rb = "010";          // 2

            string valInA = "00000101"; // 5
            string valInB = "00000111"; // 7

            bool result = false;

            // set data in register
            micro.MicroRegisters.SetRegisterValue(
                (byte)UnitConverter.BinaryToInt(ra),
                UnitConverter.BinaryToHex(valInA));

            micro.MicroRegisters.SetRegisterValue(
                (byte)UnitConverter.BinaryToInt(rb),
                UnitConverter.BinaryToHex(valInB));

            Console.WriteLine(micro.MicroRegisters);

            Assert.AreEqual($"Registers[0,5,7,0,0,0,0,0]", micro.MicroRegisters.ToString());

            // start instruction
            MCInstructionF1 instructionF1 = new MCInstructionF1(4, "11001", ra, rb);

            Console.WriteLine(instructionF1);

            InstructionSetExe.ExecuteInstruction(instructionF1, micro);

            Console.WriteLine(micro);

            Assert.AreEqual(result, micro.ConditionalBit);
        }
Exemplo n.º 3
0
        public void FlowControlOperationsTests_LOOP_Success()
        {
            // LOOP Ra, address {F2}
            // [R[ra]] <- [R[ra]] – 1
            //If R[Ra] != 0 [pc] <- address

            byte  ra    = 1;
            sbyte value = 100;

            string dataInRaBin = UnitConverter.ByteToBinary(value);

            string addressToGoHex = "AF";

            // set register
            micro.MicroRegisters.SetRegisterValue(ra, UnitConverter.BinaryToHex(dataInRaBin));

            Console.WriteLine(micro.MicroRegisters);

            Assert.AreEqual("Registers[0,100,0,0,0,0,0,0]", micro.MicroRegisters.ToString());

            // start instruction
            MCInstructionF2 i1 = new MCInstructionF2(2, "11000", UnitConverter.ByteToBinary(ra),
                                                     UnitConverter.HexToBinary(addressToGoHex));

            InstructionSetExe.ExecuteInstruction(i1, micro);

            Console.WriteLine($"Expected PC: {UnitConverter.HexToInt(addressToGoHex)}");
            Console.WriteLine(micro);
            Console.WriteLine(micro.MicroRegisters);

            Assert.AreEqual(value - 1, UnitConverter.HexToInt(micro.MicroRegisters.GetRegisterValue(ra)));
            Assert.AreEqual(UnitConverter.HexToInt(addressToGoHex), micro.ProgramCounter);
        }
Exemplo n.º 4
0
        public MCInstructionF3(ushort decimalAddress, string opCodeBinary, string binaryAddress)
        {
            OpCode = UnitConverter.BinaryToByte(opCodeBinary);

            AddressParamHex = UnitConverter.BinaryToHex(binaryAddress);

            InstructionAddressDecimal = decimalAddress;
        }
Exemplo n.º 5
0
        public MCInstructionF2(ushort decimalAddress, string opCodeBinary, string Ra, string binaryAddress)
        {
            OpCode = UnitConverter.BinaryToByte(opCodeBinary);

            this.Ra = Ra == null ? (byte)8 : UnitConverter.BinaryToByte(Ra);

            AddressParamHex = UnitConverter.BinaryToHex(binaryAddress);

            InstructionAddressDecimal = decimalAddress;
        }
Exemplo n.º 6
0
        public void LogicOperationsTests_OR_Success()
        {
            // AND Ra, Rb, Rc {F1} R[Ra]<- R[Rb]*R[Rc]
            string ra = "001"; // 1
            string rb = "011"; // 3
            string rc = "111"; // 7

            string valInB = "00100100";

            string valInC = "11101111";

            string resultA = "11101111";

            // set data in register
            micro.MicroRegisters.SetRegisterValue(
                (byte)UnitConverter.BinaryToInt(rb),
                UnitConverter.BinaryToHex(valInB));

            micro.MicroRegisters.SetRegisterValue(
                (byte)UnitConverter.BinaryToInt(rc),
                UnitConverter.BinaryToHex(valInC));

            Console.WriteLine(micro.MicroRegisters);

            Assert.AreEqual(
                UnitConverter.BinaryToHex(valInB),
                micro.MicroRegisters.GetRegisterValue((byte)UnitConverter.BinaryToInt(rb))
                );

            Assert.AreEqual(
                UnitConverter.BinaryToHex(valInC),
                micro.MicroRegisters.GetRegisterValue((byte)UnitConverter.BinaryToInt(rc))
                );

            MCInstructionF1 i1 = new MCInstructionF1(3, "01100", ra, rb, rc);

            Console.WriteLine(i1);

            // execute instruction
            InstructionSetExe.ExecuteInstruction(i1, micro);

            Console.WriteLine(micro.MicroRegisters);

            Assert.AreEqual(
                UnitConverter.BinaryToHex(resultA),
                micro.MicroRegisters.GetRegisterValue((byte)UnitConverter.BinaryToInt(ra))
                );
        }
Exemplo n.º 7
0
        public void DataMovOperationsTests_LoadConstantValueToRegister_Success()
        {
            string value1 = "00000100";
            string value2 = "00010000";

            // LOADIM R2 02
            MCInstructionF2 i1 = new MCInstructionF2(3, "00001", "010", value1);

            // LOAD R2 03
            MCInstructionF2 i2 = new MCInstructionF2(3, "00001", "011", value2);

            InstructionSetExe.ExecuteInstruction(i1, micro);
            Console.WriteLine($"Registers after Execution #1 -> {micro.MicroRegisters}");

            InstructionSetExe.ExecuteInstruction(i2, micro);
            Console.WriteLine($"Registers after Execution #2 -> {micro.MicroRegisters}");

            Assert.AreEqual(UnitConverter.BinaryToHex(value1), micro.MicroRegisters.GetRegisterValue(2));
            Assert.AreEqual(UnitConverter.BinaryToHex(value2), micro.MicroRegisters.GetRegisterValue(3));
        }
Exemplo n.º 8
0
        public void LogicOperationsTests_NOT_Success()
        {
            // NOT Ra,Rb {F1}   R[Ra] <- Complement(R[Rb])
            string ra = "001"; // 1
            string rb = "011"; // 3

            string valInB = "00100100";

            string resultA = "11011011";

            // set data in register
            micro.MicroRegisters.SetRegisterValue(
                (byte)UnitConverter.BinaryToInt(rb),
                UnitConverter.BinaryToHex(valInB));

            Console.WriteLine(micro.MicroRegisters);

            Assert.AreEqual(
                UnitConverter.BinaryToHex(valInB),
                micro.MicroRegisters.GetRegisterValue((byte)UnitConverter.BinaryToInt(rb))
                );

            MCInstructionF1 i1 = new MCInstructionF1(3, "01110", ra, rb);

            Console.WriteLine(i1);

            // execute instruction
            InstructionSetExe.ExecuteInstruction(i1, micro);

            Console.WriteLine(micro.MicroRegisters);

            Console.WriteLine($"Expected: {UnitConverter.BinaryToHex(resultA)}," +
                              $"Actual: {micro.MicroRegisters.GetRegisterValue((byte)UnitConverter.BinaryToInt(ra))}");

            Assert.AreEqual(
                UnitConverter.BinaryToHex(resultA),
                micro.MicroRegisters.GetRegisterValue((byte)UnitConverter.BinaryToInt(ra))
                );
        }
Exemplo n.º 9
0
        public void LogicOperationsTests_ROTAL_Success()
        {
            // ROTAL Ra, Rb, Rc {F1} R[Ra]<- R[Rb] rtl R[Rc]
            string ra1 = "001"; // 1
            string rb1 = "010"; // 2
            string rc1 = "011"; // 3

            string ra2 = "101"; // 5
            string rb2 = "110"; // 6
            string rc2 = "111"; // 7


            MCInstructionF1 i1 = new MCInstructionF1(3, "10011", ra1, rb1, rc1);
            MCInstructionF1 i2 = new MCInstructionF1(3, "10011", ra2, rb2, rc2);

            string valInB1  = "10111100";
            string valInC1  = UnitConverter.ByteToBinary(2);
            string resultA1 = "11110010";

            string valInB2  = "10011100";
            string valInC2  = UnitConverter.ByteToBinary(2);
            string resultA2 = "01110010";


            // set data in register
            ////////////
            /// Test 1
            micro.MicroRegisters.SetRegisterValue(
                (byte)UnitConverter.BinaryToInt(rb1),
                UnitConverter.BinaryToHex(valInB1));

            micro.MicroRegisters.SetRegisterValue(
                (byte)UnitConverter.BinaryToInt(rc1),
                UnitConverter.BinaryToHex(valInC1));
            ////////////

            ////////////
            /// Test 2
            micro.MicroRegisters.SetRegisterValue(
                (byte)UnitConverter.BinaryToInt(rb2),
                UnitConverter.BinaryToHex(valInB2));

            micro.MicroRegisters.SetRegisterValue(
                (byte)UnitConverter.BinaryToInt(rc2),
                UnitConverter.BinaryToHex(valInC2));
            ///////////

            Console.WriteLine(micro.MicroRegisters);

            // Assert Registers
            Assert.AreEqual("Registers[0,0,-68,2,0,0,-100,2]",
                            micro.MicroRegisters.ToString());
            Console.WriteLine(i1);
            Console.WriteLine(i2);

            // execute instruction
            InstructionSetExe.ExecuteInstruction(i1, micro);
            InstructionSetExe.ExecuteInstruction(i2, micro);

            Console.WriteLine(micro.MicroRegisters);

            Console.WriteLine($"Expected1: {UnitConverter.BinaryToHex(resultA1)}," +
                              $"Actual: {micro.MicroRegisters.GetRegisterValue(UnitConverter.BinaryToByte(ra1))}");
            Console.WriteLine($"Expected1: {UnitConverter.HexToBinary(micro.MicroRegisters.GetRegisterValue(UnitConverter.BinaryToByte(ra1)))}");

            Console.WriteLine($"Expected2: {UnitConverter.BinaryToHex(resultA2)}," +
                              $"Actual: {micro.MicroRegisters.GetRegisterValue(UnitConverter.BinaryToByte(ra2))}");
            Console.WriteLine($"Expected2: {UnitConverter.HexToBinary(micro.MicroRegisters.GetRegisterValue(UnitConverter.BinaryToByte(ra2)))}");

            Assert.AreEqual(
                UnitConverter.BinaryToHex(resultA1),
                micro.MicroRegisters.GetRegisterValue(UnitConverter.BinaryToByte(ra1))
                );

            Assert.AreEqual(
                UnitConverter.BinaryToHex(resultA2),
                micro.MicroRegisters.GetRegisterValue(UnitConverter.BinaryToByte(ra2))
                );
        }
Exemplo n.º 10
0
        public void LogicOperationsTests_NEG_Success()
        {
            // NEG Ra,Rb {F1} R[Ra]<- - R[Rb]
            string ra1 = "001"; // 1
            string rb1 = "011"; // 3

            string ra2 = "110"; // 6
            string rb2 = "111"; // 7


            string valInB1  = UnitConverter.ByteToBinary(-13);
            string resultA1 = UnitConverter.ByteToBinary(13);

            string valInB2  = UnitConverter.ByteToBinary(-45);
            string resultA2 = UnitConverter.ByteToBinary(45);


            // set data in register
            micro.MicroRegisters.SetRegisterValue(
                (byte)UnitConverter.BinaryToInt(rb1),
                UnitConverter.BinaryToHex(valInB1));

            micro.MicroRegisters.SetRegisterValue(
                (byte)UnitConverter.BinaryToInt(rb2),
                UnitConverter.BinaryToHex(valInB2));

            Console.WriteLine(micro.MicroRegisters);

            Assert.AreEqual(
                UnitConverter.BinaryToHex(valInB1),
                micro.MicroRegisters.GetRegisterValue((byte)UnitConverter.BinaryToInt(rb1))
                );

            Assert.AreEqual(
                UnitConverter.BinaryToHex(valInB2),
                micro.MicroRegisters.GetRegisterValue((byte)UnitConverter.BinaryToInt(rb2))
                );

            MCInstructionF1 i1 = new MCInstructionF1(3, "01111", ra1, rb1);
            MCInstructionF1 i2 = new MCInstructionF1(3, "01111", ra2, rb2);

            Console.WriteLine(i1);
            Console.WriteLine(i2);

            // execute instruction
            InstructionSetExe.ExecuteInstruction(i1, micro);
            InstructionSetExe.ExecuteInstruction(i2, micro);

            Console.WriteLine(micro.MicroRegisters);

            Console.WriteLine($"Expected1: {UnitConverter.BinaryToHex(resultA1)}," +
                              $"Actual: {micro.MicroRegisters.GetRegisterValue((byte)UnitConverter.BinaryToInt(ra1))}");
            Console.WriteLine($"Expected2: {UnitConverter.BinaryToHex(resultA2)}," +
                              $"Actual: {micro.MicroRegisters.GetRegisterValue((byte)UnitConverter.BinaryToInt(ra2))}");

            Assert.AreEqual(
                UnitConverter.BinaryToHex(resultA1),
                micro.MicroRegisters.GetRegisterValue((byte)UnitConverter.BinaryToInt(ra1))
                );

            Assert.AreEqual(
                UnitConverter.BinaryToHex(resultA2),
                micro.MicroRegisters.GetRegisterValue((byte)UnitConverter.BinaryToInt(ra2))
                );
        }