Unconditional Branching ("JMP") and Loops: Turning Finite Space into Infinite Time
How control-flow instructions hijack the Program Counter to create repetition, the engine of all algorithms
So far, our programs stopped after a few lines when hitting DAT. To keep a program alive forever, use the JMP (Jump) instruction to send the execution pointer back up and create a loop!
- JMP uses its A (Left Address) as the jump destination. - A negative offset ($-1) means "jump 1 line UP (back to 0000)"!
🎯 Your Task Change the highlighted A (Left Address) of JMP on row 0001 from $0 to $-1 (click the - button once), then press [PLAY] to keep the loop running for 10+ cycles!
1. Defying Gravity: How JMP Hijacks the Program Counter
From Step 1 through Step 11, the Program Counter (PC) behaved like a stone pulled by gravity: on every clock cycle, it fell strictly downward one row at a time (0000 ➔ 0001 ➔ 0002...) until it inevitably crashed into a DAT cell and died.
If a computer could only execute instructions in a straight line from top to bottom, performing a million calculations would require writing a million lines of code. What liberated computers from this limitation—and gave digital organisms eternal life—is the instruction you mastered in Step 12: "JMP" (Unconditional Jump).
Whereas ADD and MOV mutate data boxes inside RAM, JMP does not alter memory cells at all. Instead, JMP reaches directly into the processor itself and overwrites the Program Counter (PC), redirecting the flow of time to a new address! In CPU microarchitecture, while arithmetic instructions route their output back to the data bus or register file, a jump instruction routes its Effective Address output directly into the Program Counter's input latch, overriding the normal "+1" sequential incrementer.
[0000] ADD.AB #1, $2 ◄──┐ (Cycle 1, 3, 5, 7, 9...)
│ │
▼ │JMP.A $-1 (Rewrites PC = 0001 - 1 = 0000!)
[0001] JMP.A $-1, #0 ───┘ (Cycle 2, 4, 6, 8, 10...)
[0002] DAT.F #0, #0 (Never stepped on! Safe below the loop)2. Negative Relative Offsets ($-1) and the Birth of the Loop
In this mission, you changed the A-field (jump destination) of "JMP.A $0, #0" on row 0001 to "$-1". - When the operand was "$0", the jump target was 0001 + 0 = 0001, trapping the execution pointer on line 2 forever without doing any useful work. - When you changed the operand to "$-1", the jump target became 0001 - 1 = 0000 (one row UP).
Look at the resulting execution trace: - Cycle 1: Execute "ADD.AB #1, $2" at 0000; PC advances naturally to 0001. - Cycle 2: Execute "JMP.A $-1, #0" at 0001; PC is rewritten back to 0000! - Cycle 3: Execute "ADD.AB #1, $2" at 0000 a second time!
A program that occupies only two lines of physical space has now achieved infinite extent in time. Safely bouncing above the lethal DAT cell at 0002, this two-line loop can run for 10 cycles, 1,000 cycles, or forever. Notice the profound relationship between spatial footprint and temporal longevity: before Step 12, surviving for N cycles required N lines of code (a 1:1 ratio of space to time). With a single backward JMP instruction, two lines of space generate an infinite number of execution cycles, decoupling a program's lifespan from its physical size in memory.
3. The Structured Program Theorem and the Heartbeat of Living Code
In 1966, computer scientists Corrado Böhm and Giuseppe Jacopini proved the foundational Structured Program Theorem, demonstrating that any computable algorithm in the universe can be constructed from just three control structures: (1) Sequence (stepping line by line), (2) Iteration (looping via jumps), and (3) Selection (conditional branching).
While beginning programmers in standard software development are often warned to avoid "infinite loops", in systems engineering and artificial life the truth is the exact opposite. An operating system kernel, a video game engine, a heart pacemaker, and a CoreWar organism must NEVER exit their main loop—because exiting the loop means death. The JMP loop you just built is the literal heartbeat that keeps a digital organism alive. Inside a real microprocessor, backwards jump instructions (branches with a negative offset) are so common that hardware branch predictors specifically assume any backward jump is the bottom of a loop and speculatively pre-fetch the top of the loop before the jump even finishes executing! By mastering "JMP.A $-1", you have harnessed the fundamental temporal engine of computation.
🔒 MISSION CLEAR Unlocks the Full Lecture Note
Complete the experiment in the simulator above to automatically unlock the full deep-dive article—or click below to read the full text immediately.