//------------------------------------------------------------------------------------------------------------ public string Output() { string response = ""; if (_description.Trim() != "") { response += $"-1 {_description}\n"; } int count = _instructions.Count(); for (int i = 0; i < count; ++i) { var instruction = _instructions[i]; string line = $"{i.ToString("D2")} "; if (EPC.ValidWord(instruction)) { line += $"{instruction.ToString(Memory.FORMAT)}"; } else // Assume this is a variable or constant field { line += $"{instruction.ToString()}"; } response += line; if (i < count - 1) { response += '\n'; } } return(response); }
//------------------------------------------------------------------------------------------------------------ private static void runProgramFromFile(string filename, bool debugging = false) { // Assume that each line of the program file contains a location and instruction eg. 01 +1009 try { string[] lines = File.ReadAllLines(filename); var vm = EPC.Make(debugging: debugging); var program = EPML.Make().FillTo(vm.MemoryLimit).Load(lines); Console.Clear(); vm.Run(program); } catch (IOException ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } }
//------------------------------------------------------------------------------------------------------------ private static bool runPA06() { Console.WriteLine("\n**********************IS318-PA06********************\n"); var vm = EPC.Make(); var program = offerProgramChoices(); if (program != null) { vm.Run(program); } else { vm.Run(); } return(true); }
//------------------------------------------------------------------------------------------------------------ public string Dump() { if (_block == null) { return("Memory Stack not initialized"); } string response = "Memory:\n"; int cols = 10; int inCol = 0; // column headings response += " "; for (int i = 0; i < cols; ++i) // numbered column headings { response += String.Format("{0,8}", i.ToString("D2")); } response += "\n"; for (int i = 0; i < _size; ++i) { if (inCol == 0) // first column of new row { response += $"{i.ToString("D2"),8}"; } decimal value = _block[i]; if (EPC.ValidWord(value)) { response += String.Format("{0,8}", value.ToString(FORMAT)); } else { response += String.Format("{0,8}", value.ToString()); } ++inCol; if (inCol == cols) // last column of row { response += "\n"; inCol = 0; } } return(response); }