private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            InstructionMemory inst = new InstructionMemory();

            inst.inst = assm.assemblyCodes;
            while (control.pc < inst.inst.Count && control.ins_c == 1)
            {
                AssemblyCode line = inst.inst[control.pc];
                Ins          r    = new Ins();
                inst.register_racodnize(line, r, regs, control);

                Execute alu = new Execute(r, control);

                int alu_result = alu.exe(control, data, regs);
                if (control.write_b == 1)
                {
                    if (control.r_type == 1)
                    {
                        regs.reg[alu.rd] = alu_result;
                    }
                    if (control.im_c == 1)
                    {
                        regs.reg[alu.rt] = alu_result;
                    }
                }

                if (control.jr_pc == 0)
                {
                    control.pc_counter();
                }
            }
            for (int i = 0; i < regs.reg.Length; i++)
            {
                richTextBox1.Text += "Register #" + i + " : " + regs.reg[i] + "\n";
            }


            float cout = 0;

            // float b = 16;
            for (int i = 0; i < 16; i++)
            {
                if (regs.reg_cont[i])
                {
                    cout++;
                }
            }

            richTextBox1.Text += "_____________________________________________" + "\n";
            richTextBox1.Text += "Register Haye Estefade Shode: " + ((cout / 16) * 100) + "%" + "\n";
            richTextBox1.Text += "Memory Estefade Shode: " + (data.mem_percent) + "%" + "\n";
            richTextBox1.Text += "Tedade Dastoor Amal ha: " + (inst.inst.Count) + "\n";


            // ui->label_2->setText( QString :: number((cout/b)*100));

            // ui->mem->setText( QString :: number(data.mem_percent * 4) +(" bytes") );
        }
        public void register_racodnize(AssemblyCode ac, Ins ins, RegisterFile regs, ControlUnit control)
        {
            string opcode = ac.machineCode.Substring(4, 4);

            opcode_r(opcode, control);
            string Rs = ac.machineCode.Substring(8, 4);
            int    s  = bd(Rs);

            ins.rs           = regs.reg[s];
            regs.reg_cont[s] = true;
            if (control.r_type == 1)
            {
                string Rt = ac.machineCode.Substring(12, 4);
                long   t  = bd(Rt);
                ins.rt           = regs.reg[t];
                regs.reg_cont[t] = true;

                string Rd = ac.machineCode.Substring(16, 4);
                ins.rd = bd(Rd);
                regs.reg_cont[ins.rd] = true;
            }
            else if (control.im_c == 1) // I_Type
            {
                string Rt = ac.machineCode.Substring(12, 4);
                ins.rt = bd(Rt);
                regs.reg_cont[ins.rt] = true;

                string imm = ac.machineCode.Substring(16, 16);
                ins.imm = bd(imm);
            }
            else if (control.j == 1) //JType
            {
                string imm = ac.machineCode.Substring(16, 16);
                ins.imm = bd(imm);
            }
        }
示例#3
0
        public void createAssemblyCode(string str, int line)
        {
            string[]     parames = str.Split(' ');
            AssemblyCode ac      = null;
            string       label   = "";
            bool         error   = false;

            for (int i = 0; i < parames.Length; i++)
            {
                if (parames[i] == "")
                {
                    continue;
                }
                if (parames[i] == "add" || parames[i] == "sub" ||
                    parames[i] == "slt" || parames[i] == "or" ||
                    parames[i] == "nand")
                {
                    ac       = new R();
                    ac.label = label;
                    ac.name  = parames[i];
                    ac.type  = "R";
                    ac.createParameters(parames, i + 1, errorList, line);
                    break;
                }
                else if (parames[i] == "addi" || parames[i] == "lui" ||
                         parames[i] == "slti" || parames[i] == "ori" ||
                         parames[i] == "lw" || parames[i] == "sw" ||
                         parames[i] == "beq" || parames[i] == "jalr")
                {
                    ac       = new I();
                    ac.label = label;
                    ac.name  = parames[i];
                    ac.type  = "I";
                    ac.createParameters(parames, i + 1, errorList, line);
                    break;
                }
                else if (parames[i] == "j" || parames[i] == "halt")
                {
                    ac       = new J();
                    ac.label = label;
                    ac.name  = parames[i];
                    ac.type  = "J";
                    ac.createParameters(parames, i + 1, errorList, line);
                    break;
                }
                else if (parames[i] == ".fill" || parames[i] == ".space")
                {
                    ac       = new Directives();
                    ac.label = label;
                    ac.name  = parames[i];
                    ac.type  = "d";
                    ac.createParameters(parames, i + 1, errorList, line);
                    break;
                }
                else
                {
                    if (label == "")
                    {
                        label = parames[i];
                    }
                    else
                    {
                        errorList.Add("Line " + line + " : The assembly name is incorrect!!");
                        error = true;
                        break;
                    }
                }
            }
            if (!error)
            {
                assemblyCodes.Add(ac);
                ac.convertIntoMachineCode();
            }
        }