Exemplo n.º 1
0
        private void WriteBack()
        {
            if (PipelineRegistersList.MEMWB.Count == 0)
            {
                foreach (DataGridViewRow row in PipelineRegistersDataGridView.Rows)
                {
                    if (row.Cells["Register"].Value.ToString() != "MEM/WB")
                    {
                        continue;
                    }
                    PipelineRegistersDataGridView[1, row.Index].Value = "-";
                    return;
                }
            }

            var opCode = PipelineRegistersList.MEMWB.Dequeue();

            ControlUnit.SetAluControls(opCode.ToString());

            Muxs.MemToRegMux           = new uint[2];
            Muxs.MemToRegMux[1]        = uint.Parse(PipelineRegistersList.MEMWB.Dequeue().ToString());
            Muxs.MemToRegMux[0]        = uint.Parse(PipelineRegistersList.MEMWB.Dequeue().ToString());
            RegisterFile.WriteData     = Muxs.GetMemToRegMuxVal(ControlUnit.MemToReg);
            RegisterFile.WriteRegister = uint.Parse(PipelineRegistersList.MEMWB.Dequeue().ToString());

            if (ControlUnit.RegWrite != 1)
            {
                return;
            }
            {
                RegisterFile.PerformRegisterWrite();
                foreach (DataGridViewRow row in MipsRegistersDataGrid.Rows)
                {
                    if (row.Cells["Register"].Value.ToString() != string.Concat("$", RegisterFile.WriteRegister.ToString()))
                    {
                        continue;
                    }
                    MipsRegistersDataGrid[1, row.Index].Value = RegisterFile.WriteData;
                    var dt = (DataTable)MipsRegistersDataGrid.DataSource;
                    MipsRegisters = GetDict(dt);
                    break;
                }
            }
        }
Exemplo n.º 2
0
        private void Execute()
        {
            if (PipelineRegistersList.IDEX.Count == 0)
            {
                foreach (DataGridViewRow row in PipelineRegistersDataGridView.Rows)
                {
                    if (row.Cells["Register"].Value.ToString() != "ID/EX")
                    {
                        continue;
                    }
                    PipelineRegistersDataGridView[1, row.Index].Value = "-";
                    return;
                }
            }

            var opCode = PipelineRegistersList.IDEX.Dequeue();

            ControlUnit.SetAluControls(opCode.ToString());
            var readDataOne   = PipelineRegistersList.IDEX.Dequeue();
            var readDataTwo   = PipelineRegistersList.IDEX.Dequeue();
            var signExtension = PipelineRegistersList.IDEX.Dequeue();
            var rt            = PipelineRegistersList.IDEX.Dequeue();
            var rd            = PipelineRegistersList.IDEX.Dequeue();

            Muxs.AluSrcMux    = new uint[2];
            Muxs.AluSrcMux[0] = uint.Parse(readDataTwo.ToString());
            Muxs.AluSrcMux[1] = uint.Parse(signExtension.ToString());

            var aluValueTwo = Muxs.GetAluSrcMuxVal(ControlUnit.AluSrc);

            ALUControlBlock.ComputeOperation();

            // Perform ALU Operation
            ALU.ValueOne  = (uint)readDataOne;
            ALU.ValueTwo  = aluValueTwo;
            ALU.Operation = ALUControlBlock.Operation;
            ALU.ComputeResult();

            Muxs.RegDstMux    = new uint[2];
            Muxs.RegDstMux[0] = (uint)rt;
            Muxs.RegDstMux[1] = (uint)rd;

            // Enqueue in EX/MEM
            PipelineRegistersList.EXMEM.Enqueue(opCode);
            PipelineRegistersList.EXMEM.Enqueue(ALU.Result);
            PipelineRegistersList.EXMEM.Enqueue(readDataTwo);
            PipelineRegistersList.EXMEM.Enqueue(Muxs.GetRegDstMuxVal(ControlUnit.RegDst));

            // Add to Pipeline DataGridView
            foreach (DataGridViewRow row in PipelineRegistersDataGridView.Rows)
            {
                if (row.Cells["Register"].Value.ToString() != "EX/MEM")
                {
                    continue;
                }
                PipelineRegistersDataGridView[1, row.Index].Value = string.Concat(
                    ALU.Result.ToString(), "\n",
                    readDataTwo.ToString(), "\n",
                    Muxs.GetRegDstMuxVal(ControlUnit.RegDst).ToString());
                break;
            }
        }