Level 25: Negative Check
Open the level →Where it fits in the machine →
Task
Goal: Learn the JN (Jump if Negative) conditional jump. Run the test program and verify the jump works.
JN (Jump if Negative) — conditional jump that triggers when bit 7 of the result = 1 (negative number in two's complement).
The main idea: the processor can answer "what was the result": in two's complement bit 7 is the sign, and JN jumps when the result is negative. Flags turn arithmetic into decisions.
Solution for self-check
Try building the circuit yourself first. The solution below is a way to check yourself if you're stuck or have already solved it.
What you should get: JN fires and Acc = 99 — the jump on a negative result works.
Hardware implementation: 1. Splitter extracts bit 7 from the ALU output (Negative flag). 2. AND gate combines: Decoder.JumpCond AND Bit7. 3. OR gate combines: JumpUncond OR (JumpCond AND Bit7) → PC.Load. 4. When PC.Load=1, the program counter loads the jump address from the operand.
5 − 10 = 251 looks odd, but it works thanks to arithmetic modulo 256: the overflow is simply discarded, and 251 is the same thing as −5 in two's complement. Bit 7 is then 1 — the sign of a negative number.
Test program: - LDA 10 → Acc = 10 - STA 10 → RAM[10] = 10 - LDA 5 → Acc = 5 - SUB 10 → Acc = 5 − RAM[10] = 5 − 10 = 251 (bit 7 = 1, negative) - JN negative → jumps (bit 7 = 1) - LDA 99 → Acc = 99 - HLT
If JN works, Acc = 99. If not, Acc stays at 251.
Click "Run", then "Checkpoint".
Check yourself
Why does 5 − 10 give 251, and why does JN treat it as negative?
Arithmetic modulo 256: 251 is −5 in two’s complement, and bit 7 = 1 marks a negative number.