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]; }
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]); } }
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; } }
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; } }
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]; }
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; } }
public void execute(MipsMemory memory, Dictionary<string, int> dataTable) { string[] split = args.Split(' '); int pointer = 0; switch (instruction) { case ".word": int[] intArray = new int[split.Length]; for (int i = 0; i < split.Length; i++) { intArray[i] = Convert.ToInt32(split[i]); } pointer = memory.SaveWords(intArray); break; case ".half": short[] halfArray = new short[split.Length]; for (int i = 0; i < split.Length; i++) { halfArray[i] = Convert.ToInt16(split[i]); } pointer = memory.SaveHalfs(halfArray); break; case ".byte": byte[] byteArray = new byte[split.Length]; for (int i = 0; i < split.Length; i++) { byteArray[i] = Convert.ToByte(split[i]); } pointer = memory.SaveBytes(byteArray); break; case ".space": int count = Convert.ToInt32(split[0]); pointer = memory.ReserveBytes(count); break; } if (label != "") dataTable.Add(label, pointer); }
public override void execute(MipsMemory memory, MipsRegisters regs, Dictionary<string, int> linkerTable, Dictionary<string, int> dataTable) {}
public override void execute(MipsMemory memory, MipsRegisters regs, Dictionary<string, int> linkerTable, Dictionary<string, int> dataTable) { throw new NotImplementedException(); }
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"); } }
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"); } }