Exemplo n.º 1
0
        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") );
        }
Exemplo n.º 2
0
 public Execute(Ins ins, ControlUnit control)
 {
     this.rs = ins.rs;
     this.rt = ins.rt;
     if (control.r_type == 1)
     {
         this.rd = ins.rd;
     }
     if (control.im_c == 1 || control.j == 1)
     {
         this.imm = ins.imm;
     }
 }
        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);
            }
        }