Пример #1
0
        public int[] GetPipelineValues()
        {
            int[] pipelineValues = new int[30];

            int currentAddress = (currentIndex * 4) + startAddress;

            pipelineValues[0] = currentIndex != -1 ? currentAddress + 4 : pcReg;
            pipelineValues[1] = currentIndex != -1 ? currentAddress + 8 : pcReg + 4;

            if (branchGUI)
            {
                pipelineValues[0] -= 4;
                pipelineValues[1] -= 4;
                branchGUI          = false;
            }

            if (IFID != "0")
            {
                String[] instruction = IFID.Split(' ');
                pipelineValues[2]  = int.Parse(instruction[7]);                                                   // RS
                pipelineValues[3]  = int.Parse(instruction[3]);                                                   // RT
                pipelineValues[4]  = int.Parse(instruction[1]);                                                   // Read data 1
                pipelineValues[5]  = int.Parse(instruction[2]);                                                   // Read data 2
                pipelineValues[6]  = instruction[0] == "0" ? int.Parse(instruction[4]) : -1;                      // Write Register
                pipelineValues[7]  = instruction[0] == "0" ? mipsRegisters[int.Parse(instruction[4])] : -1;       // Write Data
                pipelineValues[8]  = instruction[0] == "0" ? -1 : int.Parse(instruction[4]);                      // Immediate
                pipelineValues[9]  = instruction[0] == "0" ? int.Parse(instruction[3]) : -1;                      // RT
                pipelineValues[10] = instruction[0] == "0" ? int.Parse(instruction[4]) : -1;                      // RD
            }

            else
            {
                pipelineValues[2]  = -1;
                pipelineValues[3]  = -1;
                pipelineValues[4]  = -1;
                pipelineValues[5]  = -1;
                pipelineValues[6]  = -1;
                pipelineValues[7]  = -1;
                pipelineValues[8]  = -1;
                pipelineValues[9]  = -1;
                pipelineValues[10] = -1;
            }



            if (IDEX != "0")
            {
                String[] instruction = IDEX.Split(' ');
                pipelineValues[11] = pipelineValues[4];                                                     // RS
                pipelineValues[12] = pipelineValues[5];                                                     // RT
                pipelineValues[13] = pipelineValues[8];                                                     // RT
                pipelineValues[14] = instruction[0] == "0" ? pipelineValues[12] : pipelineValues[13];       // Mux Value                                              // RT
                pipelineValues[15] = int.Parse(instruction[1]);                                             // ALU value
                pipelineValues[16] = pipelineValues[9];                                                     // RT
                pipelineValues[17] = pipelineValues[10];                                                    // RD
                pipelineValues[18] = instruction[0] == "0" ? pipelineValues[16] : -1;                       // RT
                pipelineValues[19] = pcReg - 4;                                                             // PC Reg
                pipelineValues[20] = instruction[0] == "0" ? -1 : int.Parse(instruction[4]);                // Adder value
            }

            else
            {
                pipelineValues[11] = -1;
                pipelineValues[12] = -1;
                pipelineValues[13] = -1;
                pipelineValues[14] = -1;
                pipelineValues[15] = -1;
                pipelineValues[16] = -1;
                pipelineValues[17] = -1;
                pipelineValues[18] = -1;
                pipelineValues[19] = -1;
                pipelineValues[20] = -1;
            }


            if (EXMEM != "0")
            {
                String[] instruction = EXMEM.Split(' ');
                pipelineValues[21] = pipelineValues[20];                                                      // Adder Value
                pipelineValues[22] = pipelineValues[15];                                                      // ALU Value
                pipelineValues[23] = pipelineValues[12];                                                      // Read Data 2
                pipelineValues[24] = pipelineValues[23];                                                      // Read Data 2
                pipelineValues[25] = pipelineValues[18];                                                      // Mux Value
            }

            else
            {
                pipelineValues[21] = -1;
                pipelineValues[22] = -1;
                pipelineValues[23] = -1;
                pipelineValues[24] = -1;
                pipelineValues[25] = -1;
            }


            if (MEMWB != "0")
            {
                String[] instruction = MEMWB.Split(' ');
                pipelineValues[26] = pipelineValues[24];                                                      // Read Data 2
                pipelineValues[27] = pipelineValues[22];                                                      // ALU Value
                pipelineValues[28] = instruction[0] == "0" ? pipelineValues[27] : -1;                         // ALU Value
                pipelineValues[29] = pipelineValues[25];                                                      // RD
            }

            else
            {
                pipelineValues[26] = -1;
                pipelineValues[27] = -1;
                pipelineValues[28] = -1;
                pipelineValues[29] = -1;
            }


            return(pipelineValues);
        }
Пример #2
0
        public void Decode()
        {
            if (IDEX == "0")
            {
                return;
            }

            String[] instruction = IDEX.Split(' ');
            char     op          = instruction[0] == "0" ? 'r' : 'i';

            ControlUnit(op);

            int val1     = int.Parse(instruction[2]);
            int val2     = int.Parse(instruction[4]);
            int muxValue = Mux2x1(val1, val2, aluSrc);

            String operation;

            switch (instruction[6])
            {
            case "32":
                operation = "add";
                break;

            case "34":
                operation = "sub";
                break;

            case "36":
                operation = "and";
                break;

            case "37":
                operation = "or";
                break;

            default:
                operation = "add";
                break;
            }
            operation = op != 'r' ? "beq" : operation;


            int aluValue = ALU(int.Parse(instruction[1]), muxValue, operation);

            val1     = int.Parse(instruction[3]);
            val2     = int.Parse(instruction[4]);
            muxValue = Mux2x1(val1, val2, regDst);


            IDEX = instruction[0].ToString() + " "            // 0 - Op Code
                   + aluValue.ToString() + " "                // 1 - ALU Result
                   + instruction[2].ToString() + " "          // 2 - Read Data 2
                   + muxValue.ToString() + " ";               // 3 - Mux Result

            int addValue;

            if (operation == "beq")
            {
                val1     = int.Parse(instruction[4]) * 4;
                val2     = int.Parse(instruction[5]);
                addValue = Adder(val1, val2);

                IDEX += addValue.ToString();                // 4 - Adder Value
            }
        }