static void Main(string[] args) { MipsMachine vm = new MipsMachine(); MipsToBinary converter = new MipsToBinary(); Prologue(); // interactive while (true) { bool isLittleEndian = true; uint address; uint length4Bytes = 1; Console.Write("> "); string[] input = Console.ReadLine().Split(); switch (input[0]) { case "c": // continue Continue(vm); break; case "s": // go to next step Step(vm); break; case "r": // read register // `r t0` RegisterType reg = (RegisterType)Enum.Parse(typeof(RegisterType), input[1]); if (input.Length >= 3) { bool.TryParse(input[2], out isLittleEndian); } Console.WriteLine($"0x{vm.QueryRegister(reg).ToHexString(isLittleEndian ? Endian.LittleEndian : Endian.BigEndian)}"); break; case "d": // read RAM // `d <address> <length/4Bytes> <0:little-endian/1:big-endian>` try { address = (uint)new System.ComponentModel.UInt32Converter().ConvertFromString(input[1]); } catch (Exception) { Console.WriteLine("[Error] Invalid Address"); continue; } if (input.Length >= 3) { uint.TryParse(input[2], out length4Bytes); } if (input.Length >= 4) { bool.TryParse(input[3], out isLittleEndian); } Console.WriteLine($"0x {vm.QueryRamAsHex(address, length4Bytes, isLittleEndian ? Endian.LittleEndian : Endian.BigEndian)}"); break; case "u": // read RAM as instructions // binarty -> MIPS asm // `u <address> <length/4Bytes>` try { address = (uint)new System.ComponentModel.UInt32Converter().ConvertFromString(input[1]); } catch (Exception) { Console.WriteLine("[Error] Invalid Address"); continue; } if (input.Length >= 3) { uint.TryParse(input[2], out length4Bytes); } Console.WriteLine(vm.GetMipsString(address, length4Bytes)); break; case "a": // write MIPS codes to RAM // `a` // `a <path to asm>` string mips; if (input.Length > 1) { mips = File.ReadAllText(input[1]); } else { mips = AskForMipsCode(); } ProgramInfo prog = converter.ParseMips(mips); MachineCodePack machineCode = prog.ToMachineCode(); vm.Reset(machineCode); // print the next instructions PrintNextInstructions(vm, 16); // do not log the changes caused by program loading vm.CleanLog(); break; case "h": // write hex to RAM // `h <path to hex>` WriteRawTextCodeToRam(input[1], vm, CodingSystem.Hex); break; case "b": // write binary to RAM // `b <path to binary>` WriteRawTextCodeToRam(input[1], vm, CodingSystem.Binary); break; } } }