Skip to content

Commit c648b20

Browse files
author
Axel Kern
committed
CPU Emulator: Fix wrong jump target
Bugfix: The A Register was wrongly updated before deriving the jump target. The jump target should be based on the value in A before executing the jump instruction. Example: @1234 A=0;JMP // should jump to 1234, not to 0 The corrected behavior is in line with the Hardware Simulator. See here: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/Subtle-different-behaviors-between-the-CPU-emulator-and-the-proposed-CPU-design-td4034781.html
1 parent 6c3eb2a commit c648b20

File tree

1 file changed

+2
-2
lines changed
  • SimulatorsPackage/src/main/java/Hack/CPUEmulator

1 file changed

+2
-2
lines changed

SimulatorsPackage/src/main/java/Hack/CPUEmulator/CPU.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class CPU
5151
// The time that passed since the program started running.
5252
protected long time;
5353

54-
// An assembler transltor
54+
// An assembler translator
5555
protected HackAssemblerTranslator assemblerTranslator;
5656

5757
/**
@@ -161,8 +161,8 @@ public void executeInstruction() throws ProgramException {
161161
bus.send(rom, PC.get(), A, 0);
162162
else if ((instruction & 0xe000) == 0xe000) {
163163
computeExp(instruction);
164-
setDestination(instruction);
165164
pcChanged = checkJump(instruction);
165+
setDestination(instruction);
166166
}
167167
else if (instruction != HackAssemblerTranslator.NOP)
168168
throw new ProgramException("At line " + PC.get() +

0 commit comments

Comments
 (0)