Esempio n. 1
0
        public override void execute(MipsMemory memory, MipsRegisters regs, Dictionary<string, int> linkerTable, Dictionary<string, int> dataTable)
        {
            if (info.name == "la")
            {
                if (!dataTable.ContainsKey(pseudoLabel))
                    throw new ArgumentException("label not found! " + ToString());

                regs.Registers[rt] = dataTable[pseudoLabel];

            } 
            else if (info.name == "lw")
            {
                if (pseudoLabel != "")
                {
                    if (!dataTable.ContainsKey(pseudoLabel))
                        throw new ArgumentException("label not found! " + ToString());

                    regs.Registers[rt] = memory.CmdLoadWord(dataTable[pseudoLabel]);
                }
                else
                {
                    regs.Registers[rt] = memory.CmdLoadWord(regs.Registers[rs] + immediate);
                }
               
            }
            else if (info.name == "sw")
            {
                memory.CmdSaveWord(regs.Registers[rs] + immediate, regs.Registers[rt]);
            }
           
           
        }
Esempio n. 2
0
        public override void execute(MipsMemory memory, MipsRegisters regs, Dictionary<string, int> linkerTable, Dictionary<string, int> dataTable)
        {
            if (!linkerTable.ContainsKey(jumpLabel)) 
                throw new ArgumentException("jump label not found! " + ToString());

            regs.PC = linkerTable[jumpLabel];
        }
Esempio n. 3
0
 public override void execute(MipsMemory memory, MipsRegisters regs, Dictionary<string, int> linkerTable, Dictionary<string, int> dataTable)
 {
     switch (info.name)
     {
         case "addi":
             regs.Registers[rt] = regs.Registers[rs] + immediate;
             break;
     }
 }
Esempio n. 4
0
        public override void execute(MipsMemory memory, MipsRegisters regs, Dictionary<string, int> linkerTable, Dictionary<string, int> dataTable)
        {
            switch (info.name)
            {
                case "slt":
                    regs.Registers[rd] = regs.Registers[rs] < regs.Registers[rt] ? 1 : 0;
                    break;

            }
        }
Esempio n. 5
0
        public override void execute(MipsMemory memory, MipsRegisters regs, Dictionary<string, int> linkerTable, Dictionary<string, int> dataTable)
        {
            if (!linkerTable.ContainsKey(bLabel))
                throw new ArgumentException("branch label not found! " + ToString());

            if (info.name == "beq" && regs.Registers[rs] == regs.Registers[rt])
                regs.PC = linkerTable[bLabel];

            if (info.name == "bne" && regs.Registers[rs] != regs.Registers[rt])
                regs.PC = linkerTable[bLabel];
        }
Esempio n. 6
0
        public override void execute(MipsMemory memory, MipsRegisters regs, Dictionary<string, int> linkerTable, Dictionary<string, int> dataTable)
        {
            switch (info.name)
            {
                case "sll":
                    regs.Registers[rd] = (int)(((uint)regs.Registers[rt]) << shift);
                    break;
                case "srl":
                    regs.Registers[rd] = (int)(((uint)regs.Registers[rt]) >> shift);
                    break;
                case "sra":
                    regs.Registers[rd] = regs.Registers[rt] >> shift;
                    break;

            }
        }
Esempio n. 7
0
 public override void execute(MipsMemory memory, MipsRegisters regs, Dictionary<string, int> linkerTable, Dictionary<string, int> dataTable)
 {}
Esempio n. 8
0
 public override void execute(MipsMemory memory, MipsRegisters regs, Dictionary<string, int> linkerTable, Dictionary<string, int> dataTable)
 {
     throw new NotImplementedException();
 }
Esempio n. 9
0
        public static void Exec(List<CmdBase> instructions, List<DataBase> dataCmds, bool perCycleOutput, bool forwarding)
        {
            //Pipline Stages: IF, ID, EX, MEM, WB
            /*
             * Ansatz:
             * Stack der die fünf Stages darstellen soll. solange ausführen bis initale Liste leer is, runden zurückgeben
             */
            List<CmdBase> history = new List<CmdBase>();
            MipsMemory mem = new MipsMemory((int)Math.Pow(2,16));
            MipsRegisters registers = new MipsRegisters();
            Dictionary<String, int> linkTable = CreateLinkTable(instructions);
            Dictionary<String, int> dataTable = new Dictionary<string, int>();

            foreach (var dataCmd in dataCmds)
            {
                dataCmd.execute(mem, dataTable);
            }


            int cycle = 0;
            registers.PC = 0;          
            
            while (true)
            {           
                //One time: Linker? Prepare Memory?
                //Load next Operation
                //Check Conditions (Hazard, Stalling)
                //Execute (Operations, load data, etc...) --> next pc

                if (registers.PC == instructions.Count) 
                    break; //end of program

                cycle++;

                var nextCmd = instructions[registers.PC];

                //Data Hazards, let our cmd WAIT if we need from a cmd before
                var usedRegs = new List<byte>();
                if (history.Count > 0)
                {
                    usedRegs.AddRange(history[history.Count - 1].getDstRegisters());
                    if (history.Count > 1)
                    {
                        usedRegs.AddRange(history[history.Count - 2].getDstRegisters());
                    }
                }
                var actualRegs = nextCmd.getSourceRegisters();

                bool match = false;
                actualRegs.ForEach(ourReg => usedRegs.ForEach(prevReg => { if (ourReg == prevReg) match = true; }));

                if (match && !(forwarding))
                {
                    history.Add(new CmdBubble(""));
                    continue; //hazard found
                }

                int initalPC = registers.PC;
                nextCmd.execute(mem, registers, linkTable, dataTable); 
                history.Add(nextCmd);

                if (registers.PC == initalPC) registers.PC += 1; //normal operations, only branch and jump modify it in the execute cmd
                if (perCycleOutput) Console.WriteLine("{0}: Execution: {1}, NextPC {2}", initalPC, nextCmd, registers.PC);
            }


            Console.WriteLine("=======================");
            Console.WriteLine("Cycle count: " + cycle);

            if (perCycleOutput)
            {
                Console.WriteLine("History Output");
                StringBuilder sb = new StringBuilder();
                foreach (var cmdBase in history)
                {
                    if (!(cmdBase is CmdBubble))
                    {
                        Console.WriteLine(cmdBase);
                        sb.AppendLine(cmdBase.info.inputLine);
                    }
                }

                File.WriteAllText("execution_order.txt", sb.ToString());
                Console.WriteLine("Wrote the executed commands to the file execution_order.txt");
            }

           
        }
Esempio n. 10
0
        public static void Exec(List <CmdBase> instructions, List <DataBase> dataCmds, bool perCycleOutput, bool forwarding)
        {
            //Pipline Stages: IF, ID, EX, MEM, WB

            /*
             * Ansatz:
             * Stack der die fünf Stages darstellen soll. solange ausführen bis initale Liste leer is, runden zurückgeben
             */
            List <CmdBase>           history   = new List <CmdBase>();
            MipsMemory               mem       = new MipsMemory((int)Math.Pow(2, 16));
            MipsRegisters            registers = new MipsRegisters();
            Dictionary <String, int> linkTable = CreateLinkTable(instructions);
            Dictionary <String, int> dataTable = new Dictionary <string, int>();

            foreach (var dataCmd in dataCmds)
            {
                dataCmd.execute(mem, dataTable);
            }


            int cycle = 0;

            registers.PC = 0;

            while (true)
            {
                //One time: Linker? Prepare Memory?
                //Load next Operation
                //Check Conditions (Hazard, Stalling)
                //Execute (Operations, load data, etc...) --> next pc

                if (registers.PC == instructions.Count)
                {
                    break; //end of program
                }
                cycle++;

                var nextCmd = instructions[registers.PC];

                //Data Hazards, let our cmd WAIT if we need from a cmd before
                var usedRegs = new List <byte>();
                if (history.Count > 0)
                {
                    usedRegs.AddRange(history[history.Count - 1].getDstRegisters());
                    if (history.Count > 1)
                    {
                        usedRegs.AddRange(history[history.Count - 2].getDstRegisters());
                    }
                }
                var actualRegs = nextCmd.getSourceRegisters();

                bool match = false;
                actualRegs.ForEach(ourReg => usedRegs.ForEach(prevReg => { if (ourReg == prevReg)
                                                                           {
                                                                               match = true;
                                                                           }
                                                              }));

                if (match && !(forwarding))
                {
                    history.Add(new CmdBubble(""));
                    continue; //hazard found
                }

                int initalPC = registers.PC;
                nextCmd.execute(mem, registers, linkTable, dataTable);
                history.Add(nextCmd);

                if (registers.PC == initalPC)
                {
                    registers.PC += 1;                           //normal operations, only branch and jump modify it in the execute cmd
                }
                if (perCycleOutput)
                {
                    Console.WriteLine("{0}: Execution: {1}, NextPC {2}", initalPC, nextCmd, registers.PC);
                }
            }


            Console.WriteLine("=======================");
            Console.WriteLine("Cycle count: " + cycle);

            if (perCycleOutput)
            {
                Console.WriteLine("History Output");
                StringBuilder sb = new StringBuilder();
                foreach (var cmdBase in history)
                {
                    if (!(cmdBase is CmdBubble))
                    {
                        Console.WriteLine(cmdBase);
                        sb.AppendLine(cmdBase.info.inputLine);
                    }
                }

                File.WriteAllText("execution_order.txt", sb.ToString());
                Console.WriteLine("Wrote the executed commands to the file execution_order.txt");
            }
        }