Esempio n. 1
0
        public IMCInstruction NextInstruction()
        {
            IMCInstruction instructionToExecute = GetNextInstruction();

            InstructionSetExe.ExecuteInstruction(instructionToExecute, _simulator);

            return(instructionToExecute);
        }
Esempio n. 2
0
        public static bool ExecuteInstruction(IMCInstruction instruction, MicroSimulator microSimulator)
        {
            string opCode = UnitConverter.IntToBinary(instruction.OpCode, defaultWidth: 5);

            if (!operatorFunctions.ContainsKey(opCode))
            {
                return(false);
            }

            return(operatorFunctions[opCode](instruction, microSimulator));
        }
Esempio n. 3
0
        public void MCLoaderTests_ExecuteOneInstruction_Success()
        {
            string expected = "MCInstructionF3[InstructionAddressDecimal: (decimal)'0', opcode:'21', AddressParamHex:'06']";

            VirtualMemory vm = new VirtualMemory(new string[] { "A8 06" });

            MCLoader l = new MCLoader(vm, new MicroSimulator(vm));

            IMCInstruction i = l.NextInstruction();

            Console.WriteLine(i);

            Assert.AreEqual(expected, i.ToString());
        }
Esempio n. 4
0
        private string GetPrettyInstruction(IMCInstruction instruction)
        {
            if (instruction == null)
            {
                return("");
            }

            string addressHex = UnitConverter.IntToHex(instruction.InstructionAddressDecimal, defaultWidth: 3);

            string contentHex = VirtualMemory.GetContentsInHex(instruction.InstructionAddressDecimal) +
                                VirtualMemory.GetContentsInHex(instruction.InstructionAddressDecimal + 1);

            return($"{addressHex}: {contentHex}: {instruction.ToString()}");
        }
Esempio n. 5
0
        public void MCLoaderTests_LoadObjectFile_Success()
        {
            string[] lines = FileManager.Instance.ToReadFile(machineCodeFile);

            Assert.IsNotNull(lines);

            string[] expected =
            {
                "MCInstructionF3[InstructionAddressDecimal: (decimal)'0', opcode:'21', AddressParamHex:'06']",
                "MCInstructionF2[InstructionAddressDecimal: (decimal)'6', opcode:'0', Ra:'1', AddressParamHex:'02']",
                "MCInstructionF2[InstructionAddressDecimal: (decimal)'8', opcode:'0', Ra:'2', AddressParamHex:'03']",
                "MCInstructionF1[InstructionAddressDecimal: (decimal)'10', opcode:'25', Ra:'1', Rb:'2', Rc:'0']",
                "MCInstructionF3[InstructionAddressDecimal: (decimal)'12', opcode:'21', AddressParamHex:'12']",
                "MCInstructionF2[InstructionAddressDecimal: (decimal)'18', opcode:'3', Ra:'1', AddressParamHex:'04']",
                "MCInstructionF2[InstructionAddressDecimal: (decimal)'20', opcode:'1', Ra:'3', AddressParamHex:'08']",
                "MCInstructionF3[InstructionAddressDecimal: (decimal)'22', opcode:'21', AddressParamHex:'16']",
                "MCInstructionF3[InstructionAddressDecimal: (decimal)'22', opcode:'21', AddressParamHex:'16']",
                "MCInstructionF3[InstructionAddressDecimal: (decimal)'22', opcode:'21', AddressParamHex:'16']"
            };

            VirtualMemory vm = new VirtualMemory(lines);

            Console.WriteLine(vm);

            MicroSimulator micro = new MicroSimulator(vm);

            MCLoader l = new MCLoader(vm, micro);

            int i = 0;

            while (i < 10)
            {
                IMCInstruction instruction = l.NextInstruction();

                Console.WriteLine(instruction);

                Assert.AreEqual(expected[i], instruction.ToString());

                i++;
            }
        }
Esempio n. 6
0
        private IMCInstruction GetNextInstruction()
        {
            ushort currProgramCounter = _simulator.ProgramCounter;

            // even block containing the instruction
            string evenBlock = _vm.GetContentsInBin(currProgramCounter);
            // odd block with data and other params
            string oddBlock = _vm.GetContentsInBin(currProgramCounter + 1);

            // 16-bit instruction block
            string completeBlock = evenBlock + oddBlock;

            // get first 5-bits to use as OpCode
            string opcode = evenBlock.Substring(0, 5);

            // instruction format
            byte instructionFormat = OpCodesInfo.GetInstructionFormat(opcode);
            byte numberOfParams    = OpCodesInfo.GetNumberOfParams(opcode);

            byte count = 0;

            string[] paramList = new string[3];

            IMCInstruction instructionToExecute = null;

            switch (instructionFormat)
            {
            case 1:
                while (count < numberOfParams)
                {
                    paramList[count] = completeBlock.Substring(count * 3 + 5, 3);
                    count++;
                }

                instructionToExecute = new MCInstructionF1(
                    decimalAddress: currProgramCounter,
                    opCodeBinary: opcode,
                    Ra: paramList[0],
                    Rb: paramList[1],
                    Rc: paramList[2]
                    );
                break;

            case 2:
                while (count < numberOfParams)
                {
                    if (count == 0)
                    {
                        // get 'Ra'
                        paramList[count] = completeBlock.Substring(5, 3);
                    }
                    else if (count == 1)
                    {
                        paramList[count] = oddBlock;
                    }

                    count++;
                }

                instructionToExecute = new MCInstructionF2(
                    decimalAddress: currProgramCounter,
                    opCodeBinary: opcode,
                    Ra: paramList[0],
                    binaryAddress: paramList[1]
                    );

                break;

            case 3:
                instructionToExecute = new MCInstructionF3(
                    decimalAddress: currProgramCounter,
                    opCodeBinary: opcode,
                    binaryAddress: completeBlock.Substring(6, 10)
                    );
                break;
            }

            return(instructionToExecute);
        }