diff --git a/src/main/java/mipsim/Processor.java b/src/main/java/mipsim/Processor.java index 68ce2bc..bfb7a56 100644 --- a/src/main/java/mipsim/Processor.java +++ b/src/main/java/mipsim/Processor.java @@ -112,15 +112,22 @@ public void eval(final long time) { @Override public void writeDebug(@NotNull StringBuffer buffer) { - final var pc = BusKt.toInt(this.wbif.pc); - final var instBin = BusKt.toInt(instructionMemory.instruction); - final var instStr = ParserKt.parseBinToInstruction(instBin); - - buffer.append(String.format("pc pipe: %04xH\t", pc)); - buffer.append(String.format("pc inst: %04xH\t", BusKt.toInt(instructionMemory.pc))); - buffer.append(String.format("pc ifid: %04xH\n", BusKt.toInt(ifid.pc))); - buffer.append(String.format("inst read: %08xH = ' %s '\t", instBin, instStr)); - buffer.append(String.format("inst ifid: %08xH\n", BusKt.toInt(ifid.instruction))); + { + final var pc = BusKt.toInt(this.wbif.pc); + buffer.append(String.format("pc in if: %04xH\n", pc)); + } + + { + final var instBin = BusKt.toInt(instructionMemory.instruction); + final var instStr = ParserKt.parseBinToInstruction(instBin); + buffer.append(String.format("inst in mem: %08xH = ' %s '\n", instBin, instStr)); + } + { + final var instBin = BusKt.toInt(ifid.instruction); + final var instStr = ParserKt.parseBinToInstruction(instBin); + buffer.append(String.format("inst in ifid: %08xH = ' %s '\n", instBin, instStr)); + } + DebugKt.writeTo(registerFile, buffer); } diff --git a/src/main/java/mipsim/console/Main.java b/src/main/java/mipsim/console/Main.java index 4a33d06..ea6b769 100644 --- a/src/main/java/mipsim/console/Main.java +++ b/src/main/java/mipsim/console/Main.java @@ -87,14 +87,14 @@ public static void runProgram() { public static int find_DebugLevel() { System.out.println("--- Debug Levels ---"); - System.out.println("1. Easy : "); - System.out.println("2. medium : "); - System.out.println("3. advance: "); + System.out.print("1. Easy\t"); + System.out.print("2. medium\t"); + System.out.println("3. advance"); return Console.askInteger("please choice Debug level:", 0); } public static boolean find_stepShow() { - return Console.askYesNo("Do you like to see step by step of code that you Run in Cpu ?", false); + return Console.askYesNo("Do you like to see step by step of code that you Run in Cpu ?", true); } public static boolean find_heWantToSaveInMemory() { diff --git a/src/main/java/mipsim/sim/Simulator.java b/src/main/java/mipsim/sim/Simulator.java index 1c13c94..ab7273c 100644 --- a/src/main/java/mipsim/sim/Simulator.java +++ b/src/main/java/mipsim/sim/Simulator.java @@ -3,7 +3,6 @@ import mipsim.Processor; import mipsim.console.Console; import sim.base.BusKt; -import sim.tool.DebugKt; import java.io.File; import java.util.Arrays; @@ -43,8 +42,7 @@ public void loadInstructions(final File instructionsFile) { } public void run(int debugLevel, boolean stepByStep) { - DebugKt.println(processor.instructionMemory); - testOn(processor.dataMemory, "dataMemory"); + testOn(processor.dataMemory, "dataMemory - before run"); for (var i = 0; i < 100; i++) { if (runStep(i, debugLevel)) break; @@ -52,7 +50,8 @@ public void run(int debugLevel, boolean stepByStep) { if (stepByStep && !Console.askYesNo("Do tou want to continue?", true)) break; } - testOn(processor.dataMemory, "dataMemory"); + testOn(processor.registerFile, "registerFile - after run"); + testOn(processor.dataMemory, "dataMemory - after run"); } boolean runStep(int step, int debugLevel) { diff --git a/src/main/kotlin/mipsim/units/RegisterFileUnit.kt b/src/main/kotlin/mipsim/units/RegisterFileUnit.kt index 6b1d5cc..c27d1fc 100644 --- a/src/main/kotlin/mipsim/units/RegisterFileUnit.kt +++ b/src/main/kotlin/mipsim/units/RegisterFileUnit.kt @@ -39,18 +39,19 @@ class RegisterFileUnit(clock: Value) : Eval, DebugWriter { val values = _memory.bulkRead(32) for (i in 0..31) { val value: Int = values[i] - buffer.append(String.format("$%d=%04xH ", i, value)) + buffer.append(String.format("$%-2d=%08xH ", i, value)) + if (i % 8 == 7) buffer.appendln() } - buffer.append("\n") - buffer.append("ReadReg1: ").append(readReg1.toInt()).append("\t") - buffer.append("ReadReg2: ").append(readReg2.toInt()).append("\t") - buffer.append("WriteReg: ").append(writeReg.toInt()).append("\n") - buffer.append("RegWrite: ").append(regWrite).append("\t") - buffer.append("ReadData1: ").append(readData1.toInt()).append("\t") - buffer.append("ReadData2: ").append(readData2.toInt()).append("\t") - buffer.append("WriteData: ").append(writeData.toInt()) - } + buffer.append(String.format("WriteReg: %02d\t", writeReg.toInt())) + buffer.append(String.format("WriteData: %d\t", writeData.toInt())) + buffer.append(String.format("RegWrite: %d\n", regWrite.toInt())) + + buffer.append(String.format("ReadReg1: %02d\t", readReg1.toInt())) + buffer.append(String.format("ReadData1: %d\n", readData1.toInt())) + buffer.append(String.format("ReadReg2: %02d\t", readReg2.toInt())) + buffer.append(String.format("ReadData2: %d\n", readData2.toInt())) + } } internal fun main1() {