public bool doAssembler(string inputPath, string outputPath, bool reset) { assembler = new MIPS246.Core.Assembler.Assembler(inputPath, outputPath); if (reset) { Form1.Reset(); } else { RunTimeCode.Clear(); } if (assembler.DoAssemble() == true) { List <String[]> sourceList = assembler.SourceList; lineTable = assembler.Linetable; List <Instruction> codeList = assembler.CodeList; if (MipsSimulator.Program.mode != 1) { RunTimeCode.CodeTInitial(); } for (int i = 0; i < codeList.Count; i++) { CodeType codeType = convertToCodeType(codeList[i].Mnemonic.ToString()); string machineCode = convertToMachineCode(codeList[i].Machine_Code); int p = (int)lineTable[i]; string codeStr = sourceList[p][0] + " "; for (int s = 1; s < sourceList[p].Count(); s++) { codeStr += sourceList[p][s] + ","; } if (codeStr.Substring(codeStr.Length - 1, 1) == ",") { codeStr = codeStr.Substring(0, codeStr.Length - 1); } Code code = new Assembler.Code(codeType, null, codeStr, machineCode); code.index = i; code.address = codeList[i].Address; RunTimeCode.codeList.Add(code); } for (int i = 0; i < sourceList.Count; i++) { string codeStr = sourceList[i][0] + " "; for (int s = 1; s < sourceList[i].Count(); s++) { codeStr += sourceList[i][s] + ","; } if (codeStr.Substring(codeStr.Length - 1, 1) == ",") { codeStr = codeStr.Substring(0, codeStr.Length - 1); } string machineCode = ""; int j = 0; for (j = 0; j < lineTable.Count; j++) { if ((int)lineTable[j] == i) { break; } } if (j != lineTable.Count) { machineCode = RunTimeCode.codeList[j].machineCode; Int32 tmp = (Int32)CommonTool.StrToNum(TypeCode.Int32, machineCode, 2); machineCode = "0x" + tmp.ToString("X8"); } Code code = new Assembler.Code(CodeType.NOP, null, codeStr, machineCode); code.index = i; code.address = codeList[j].Address; RunTimeCode.Add(code); } } else { MipsSimulator.Tools.FileControl.WriteFile(outputPath, assembler.Error.ToString()); return(false); } return(true); }
public bool doAssembler(string inputPath, string outputPath,bool reset) { assembler = new MIPS246.Core.Assembler.Assembler(inputPath, outputPath); if (reset) { Form1.Reset(); } else { RunTimeCode.Clear(); } if (assembler.DoAssemble() == true) { List<String> sourceList = assembler.RawSource; lineTable = assembler.Linetable; List<Instruction> codeList = assembler.CodeList; if (MipsSimulator.Program.mode != 1) { RunTimeCode.CodeTInitial(); } for (int i = 0; i < codeList.Count; i++) { CodeType codeType = convertToCodeType(codeList[i].Mnemonic.ToString()); string machineCode = convertToMachineCode(codeList[i].Machine_Code); int p = (int)lineTable[i]; string codeStr = sourceList[p]; Code code = new Assembler.Code(codeType, null, codeStr, machineCode); code.index = i; code.address = codeList[i].Address; RunTimeCode.codeList.Add(code); } for (int i = 0; i < sourceList.Count; i++) { string codeStr = sourceList[i]; string machineCode = ""; int j = 0; for (j = 0; j < lineTable.Count; j++) { if ((int)lineTable[j] == i) { break; } } if (j != lineTable.Count) { machineCode = RunTimeCode.codeList[j].machineCode; Int32 tmp = (Int32)CommonTool.StrToNum(TypeCode.Int32, machineCode, 2); machineCode = "0x" + tmp.ToString("X8"); Code code = new Assembler.Code(CodeType.NOP, null, codeStr, machineCode); code.index = i; code.address = codeList[j].Address; RunTimeCode.Add(code); } else { Code code = new Assembler.Code(CodeType.NOP, null, codeStr, machineCode); code.index = i; code.address =-1; RunTimeCode.Add(code); } } } else { MipsSimulator.Tools.FileControl.WriteFile(outputPath, assembler.Error.ToString()); return false; } return true; }