Пример #1
0
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            int index = e.ColumnIndex;

            if (index != 3)
            {
                return;
            }
            string inputPath = System.Environment.CurrentDirectory;

            inputPath = inputPath + "\\source.txt";
            string outputPath = System.Environment.CurrentDirectory;

            outputPath = outputPath + "\\report.txt";
            if (File.Exists(inputPath))
            {
                File.Delete(inputPath);
            }
            if (File.Exists(outputPath))
            {
                File.Delete(outputPath);
            }

            string source = "";

            for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
            {
                source = this.dataGridView1.Rows[i].Cells[3].Value.ToString() + "\r\n";
                MipsSimulator.Tools.FileControl.WriteFile(inputPath, source);
            }
            MipsSimulator.Cmd.cmdMode cmdMode = new Cmd.cmdMode();
            if (!cmdMode.doAssembler(inputPath, outputPath, false))
            {
                string error = MipsSimulator.Tools.FileControl.ReadFile(outputPath);
                RunTimeCode.Clear();
                textBox2.Text += error;
                this.tabControl3.SelectedTab = this.tabPage5;
                return;
            }
            dataGridView1.Refresh();
            codeColor(indexFinal, colorFinal);
            for (int i = 0; i < breakpoints.Count; i++)
            {
                int point = breakpoints[i];
                dataGridView1.Rows[point].Cells[0].Value = true;
            }
            this.tabControl1.SelectedTab = this.tabPage2;
            return;
        }
Пример #2
0
        //分析代码
        private void toolStripButton1_Click_1(object sender, EventArgs e)
        {
            textBox2.Text = "";
            if (this.txtContent.Text == null || this.txtContent.Text == "")
            {
                MessageBox.Show("代码不可以为空!");
                return;
            }
            string[] codes = this.txtContent.Text.Split(new string[1] {
                "\r\n"
            }, StringSplitOptions.RemoveEmptyEntries);
            if (codes == null || codes.Length <= 0)
            {
                MessageBox.Show("代码不可以为空!");
                return;
            }

            Reset();
            RunTimeCode.Clear();
            string inputPath = System.Environment.CurrentDirectory;

            inputPath = inputPath + "\\source.txt";
            string outputPath = System.Environment.CurrentDirectory;

            outputPath = outputPath + "\\report.txt";
            if (File.Exists(inputPath))
            {
                File.Delete(inputPath);
            }
            if (File.Exists(outputPath))
            {
                File.Delete(outputPath);
            }
            MipsSimulator.Tools.FileControl.WriteFile(inputPath, this.txtContent.Text);

            MipsSimulator.Cmd.cmdMode cmdMode = new Cmd.cmdMode();
            if (!cmdMode.doAssembler(inputPath, outputPath, true))
            {
                string error = MipsSimulator.Tools.FileControl.ReadFile(outputPath);
                RunTimeCode.Clear();
                textBox2.Text += error;
                this.tabControl3.SelectedTab = this.tabPage5;
                return;
            }
            dataGridView1.Refresh();
            this.tabControl1.SelectedTab = this.tabPage2;
        }
Пример #3
0
        public Form1()
        {
            InitializeComponent();
            this.toolStripButton2.Enabled = false;
            this.toolStripButton3.Enabled = false;
            this.toolStripButton2.Visible = false;
            this.toolStripButton3.Visible = false;

            this.txtContent.MouseWheel += new MouseEventHandler(txtContect_MouseWheel);

            textBox2.Font = new Font(textBox2.Font.FontFamily, 15, textBox2.Font.Style);

            //寄存器表格
            Register.ResInitialize();
            this.dataGridView2.DataSource            = Register.Res;
            this.dataGridView2.Columns[0].FillWeight = 30;
            this.dataGridView2.Columns[1].FillWeight = 70;
            this.dataGridView2.Columns[0].ReadOnly   = true;

            this.dataGridView2.Font = new Font("宋体", 10, FontStyle.Bold);
            // this.dataGridView2.ReadOnly = false;


            //内存表格
            Memory.MemInitialize();
            this.dataGridView3.DataSource          = Memory.Mem;
            this.dataGridView3.Columns[0].ReadOnly = true;
            //this.dataGridView3.ReadOnly= false;
            this.dataGridView3.Font = new Font("宋体", 10, FontStyle.Bold);


            //Execute表格
            RunTimeCode.CodeTInitial();
            this.dataGridView1.DataSource            = RunTimeCode.CodeT;
            this.dataGridView1.Columns[0].FillWeight = 20;
            this.dataGridView1.Columns[1].FillWeight = 20;
            this.dataGridView1.Columns[2].FillWeight = 20;
            this.dataGridView1.Columns[3].FillWeight = 40;
            this.dataGridView1.Columns[1].ReadOnly   = true;
            this.dataGridView1.Columns[2].ReadOnly   = true;
            this.dataGridView1.Columns[3].ReadOnly   = false;
            this.dataGridView1.Font = new Font("宋体", 10, FontStyle.Bold);
            // this.dataGridView1.ReadOnly = false;
            this.dataGridView1.CellValueChanged += new DataGridViewCellEventHandler(dataGridView1_CellValueChanged);
        }
Пример #4
0
        //复位
        static public void Reset()
        {
            isStep  = false;
            isStep2 = false;
            isBreak = false;
            breakpoints.Clear();

            Register.Clear();
            RunTimeCode.Clear();

            //MasterSwitch.Initialize();
            //MasterSwitch.Close();

            // IFStage.Close();
            //DEStage.Close();
            //EXEStage.Close();
            // MEMStage.Close();
            // WBStage.Close();

            mMasterSwitch.Initialize();
            mMasterSwitch.Close();
        }
Пример #5
0
        public void start(string inputPath, string outputPath)
        {
            outPath = outputPath;
            MipsSimulator.Devices.Register.ResInitialize();
            MipsSimulator.Devices.Memory.MemInitialize();
            RunTimeCode.CodeTInitial();
            if (doAssembler(inputPath, outputPath, true))
            {
                if (File.Exists(outputPath))
                {
                    File.Delete(outputPath);
                }

                for (int k = 0; k < RunTimeCode.codeList.Count; k++)
                {
                    try
                    {
                        mMasterSwitch.StepInto();
                    }
                    catch (Exception e)
                    {
                        MipsSimulator.Tools.FileControl.WriteFile(outputPath, e.Message);
                        return;
                    }
                    string codeStr = RunTimeCode.codeList[k].codeStr;
                    MipsSimulator.Tools.FileControl.WriteFile(outputPath, codeStr + "\r\n");
                    for (int i = 0; i <= 31; i++)
                    {
                        string registerName = "$" + i;
                        string value        = MipsSimulator.Devices.Register.GetRegisterValue(registerName) + " ";
                        MipsSimulator.Tools.FileControl.WriteFile(outputPath, value);
                    }

                    MipsSimulator.Tools.FileControl.WriteFile(outputPath, "\r\n");
                }
            }
        }
Пример #6
0
        public bool doAssembler(string inputPath, string outputPath, bool reset)
        {
            assembler = new MIPS246.Core.Assembler.Assembler(inputPath, outputPath);
            if (reset)
            {
                Form1.Reset();
            }
            else
            {
                RunTimeCode.Clear();
            }
            if (assembler.DoAssemble() == true)
            {
                List <String[]> sourceList = assembler.SourceList;
                lineTable = assembler.Linetable;
                List <Instruction> codeList = assembler.CodeList;

                if (MipsSimulator.Program.mode != 1)
                {
                    RunTimeCode.CodeTInitial();
                }

                for (int i = 0; i < codeList.Count; i++)
                {
                    CodeType codeType    = convertToCodeType(codeList[i].Mnemonic.ToString());
                    string   machineCode = convertToMachineCode(codeList[i].Machine_Code);

                    int    p       = (int)lineTable[i];
                    string codeStr = sourceList[p][0] + " ";
                    for (int s = 1; s < sourceList[p].Count(); s++)
                    {
                        codeStr += sourceList[p][s] + ",";
                    }
                    if (codeStr.Substring(codeStr.Length - 1, 1) == ",")
                    {
                        codeStr = codeStr.Substring(0, codeStr.Length - 1);
                    }
                    Code code = new Assembler.Code(codeType, null, codeStr, machineCode);
                    code.index   = i;
                    code.address = codeList[i].Address;
                    RunTimeCode.codeList.Add(code);
                }

                for (int i = 0; i < sourceList.Count; i++)
                {
                    string codeStr = sourceList[i][0] + " ";
                    for (int s = 1; s < sourceList[i].Count(); s++)
                    {
                        codeStr += sourceList[i][s] + ",";
                    }
                    if (codeStr.Substring(codeStr.Length - 1, 1) == ",")
                    {
                        codeStr = codeStr.Substring(0, codeStr.Length - 1);
                    }
                    string machineCode = "";
                    int    j           = 0;
                    for (j = 0; j < lineTable.Count; j++)
                    {
                        if ((int)lineTable[j] == i)
                        {
                            break;
                        }
                    }
                    if (j != lineTable.Count)
                    {
                        machineCode = RunTimeCode.codeList[j].machineCode;
                        Int32 tmp = (Int32)CommonTool.StrToNum(TypeCode.Int32, machineCode, 2);
                        machineCode = "0x" + tmp.ToString("X8");
                    }
                    Code code = new Assembler.Code(CodeType.NOP, null, codeStr, machineCode);
                    code.index   = i;
                    code.address = codeList[j].Address;
                    RunTimeCode.Add(code);
                }
            }
            else
            {
                MipsSimulator.Tools.FileControl.WriteFile(outputPath, assembler.Error.ToString());
                return(false);
            }
            return(true);
        }
Пример #7
0
        static private void ThreadFun()
        {
            if (enableRun < 0)
            {
                isEnd = true;
                return;
            }
            string strArg1 = Register.GetRegisterValue("pc");

            PC = (Int32)CommonTool.StrToNum(TypeCode.Int32, strArg1, 16);
            //获取指令
            code = RunTimeCode.GetCode(PC);

            //设置NPC
            switch (code.codeType)
            {
            case CodeType.OVER:
            {
                enableRun   = -1;
                NPC         = PC;
                ifOverOrNop = true;
                break;
            }

            case CodeType.NOP:
            {
                PC          = PC + 4;
                NPC         = PC;
                ifOverOrNop = true;
                break;
            }

            case CodeType.ERR:
            {
                Form1.Message(code.codeStr);
                RunTimeCode.codeList.Clear();
                break;
            }

            default:
            {
                PC            = PC + 4;
                NPC           = PC;
                mDEStage.code = mIFStage.code;
                mDEStage.args = new object[1] {
                    NPC
                };
                mDEStage.enableRun++;
                break;
            }
            }
            if (MipsSimulator.Program.mode == 1)
            {
                if (code.codeType != CodeType.OVER)
                {
                    int colorIndex = (int)cmdMode.lineTable[mIFStage.code.Index];
                    Form1.codeColor(colorIndex, 1);
                }
            }

            isEnd = true;
            return;
        }