public static int StoreInstruction(string[][] programTextArray, ref int i, ref int j, Dictionary <uint, ExeCommand> commandsToExe) { var commandName = programTextArray[i][j]; int instructionLayout = SInstructionOpcode[commandName]; var args = Healper.GetArgs(programTextArray, ref i, ref j, 2); if (!Healper.IsComandWithOffset(args[1], out string register, out int offset)) { throw new SimulatorException { ErrorMessage = $"'unknown store format command" } } ; if (!registersOpcode.ContainsKey(register)) { throw new SimulatorException { ErrorMessage = $"'unknown '{register}' register for load command" } } ; commandsToExe[commandsToExe.Last().Key] = new ExeCommand { Args = new List <string> { args[0], register, offset.ToString() }, Instraction = commandName, Line = i }; instructionLayout |= registersOpcode[args[0]] << 20 | registersOpcode[register] << 15; instructionLayout |= (offset & Convert.ToInt32("111111100000", 2) << 20) | (offset & Convert.ToInt32("11111", 2) << 7); return(instructionLayout); }
public static int IInstruction(string[][] programTextArray, ref int i, ref int j, out string label, Dictionary <uint, ExeCommand> commandsToExe) { var commandName = programTextArray[i][j]; int instructionLayout = IInstructionOpcode[commandName]; if (commandName == "jalr") { label = null; var args = Healper.ParseJalr(programTextArray, ref i, ref j); commandsToExe[commandsToExe.Last().Key] = new ExeCommand { Args = args, Instraction = commandName, Line = i }; if (!Healper.IsComandWithOffset(args[1], out string register, out int offset)) { throw new SimulatorException { ErrorMessage = $"unknown load format command" } } ; if (!registersOpcode.ContainsKey(register)) { throw new SimulatorException { ErrorMessage = $"unknown '{register}' register for load command" } } ; instructionLayout |= registersOpcode[args[0]] << 7 | registersOpcode[register] << 15 | offset << 20; return(instructionLayout); } else { var args = Healper.GetArgs(programTextArray, ref i, ref j); if (!registersOpcode.ContainsKey(args[0]) || !registersOpcode.ContainsKey(args[1])) { throw new SimulatorException { ErrorMessage = $"unknown register" } } ; instructionLayout |= registersOpcode[args[0]] << 7 | registersOpcode[args[1]] << 15; commandsToExe[commandsToExe.Last().Key] = new ExeCommand { Args = args, Instraction = commandName, Line = i }; if (int.TryParse(args[2], out int number)) { instructionLayout = instructionLayout | number << 20; label = null; } else { label = args[2]; } return(instructionLayout); } }