COREWAR

/
Step 13: Build Your First Program (Automatic Counter)
🎯Count up Cell 0002 B-value to 5 or more(0/5)

MISSIONS (30 STEPS)

CH.1: UI & MEMORY BASICS (1-6)
BASIC★☆☆
Step 1: The "STEP" Button That Advances Time
🔒
BASIC★☆☆
Step 2: Process Termination and Restoring with "RESET"
🔒
BASIC★☆☆
Step 3: "Edit Mode" vs. "Running Mode"EDIT
🔒
BASIC★☆☆
Step 4: The Three Rooms of a Memory Box (Changing B)EDIT
🔒
BASIC★☆☆
Step 5: Modifying Both the Left Room (A) and Right Room (B)EDIT
🔒
BASIC★☆☆
Step 6: Literal Numbers (#) vs. Relative Addresses ($)EDIT
CH.2: CORE INSTRUCTIONS (7-13)
🔒
ARITHMETIC★☆☆
Step 7: Observing the "ADD" Instruction
🔒
ARITHMETIC★☆☆
Step 8: Changing the Number to Add (A-Field)EDIT
🔒
ARITHMETIC★☆☆
Step 9: Changing the Target Address (B-Field)EDIT
🔒
ARITHMETIC★☆☆
Step 10: Using the Subtraction Instruction "SUB"EDIT
🔒
BASIC★☆☆
Step 11: Copying an Entire Box with "MOV"EDIT
🔒
CONTROL★☆☆
Step 12: Looping Back in Time with "JMP"EDIT
🔒
CONTROL★☆☆
Step 13: Build Your First Program (Automatic Counter)EDIT
CH.3: VON NEUMANN & DIGITAL LIFE (14-18)
🔒
BASIC★☆☆
Step 14: Why Does "DAT" Become a Bomb?EDIT
🔒
BASIC★☆☆
Step 15: Copying Your Own Instruction (Code = Data)EDIT
🔒
BASIC★☆☆
Step 16: Observation: Stepping Through "Imp", the Oldest Digital Organism
🔒
BASIC★☆☆
Step 17: Modifying the Imp (Copy Destination Experiment)EDIT
🔒
ARITHMETIC★★☆
Step 18: Understanding Indirect Addressing (@ Pointers)EDIT
CH.4: CLASSIC ARCHETYPES (19-24)
🔒
STRATEGY★★☆
Step 19: Observation: Dissecting the "Dwarf" Bomber Step-by-Step
🔒
STRATEGY★★☆
Step 20: Modifying Dwarf (Changing the Bombing Interval)EDIT
🔒
STRATEGY★★☆
Step 21: First Combat: Tune Your Bomb Interval to Destroy the TargetEDIT
🔒
CONTROL★★☆
Step 22: Observation: The "SPL" Split Instruction and Mitosis
🔒
CONTROL★★☆
Step 23: Finding Enemies with Conditional Skip "SEQ / CMP"EDIT
🔒
STRATEGY★★☆
Step 24: Stopping an Imp with a Pre-Decrement "Imp-Gate"EDIT
CH.5: BATTLE EVOLUTION (25-30)
🔒
STRATEGY★★☆
Step 25: [Stone] High-Speed Bomber and Step Size TuningEDIT
🔒
STRATEGY★★☆
Step 26: [Paper] Observing the Self-Replicating Swarm "Mice"
🔒
STRATEGY★★★
Step 27: [Modifying Paper] Tune Clone Dispersal Distance to Overwhelm StoneEDIT
🔒
STRATEGY★★☆
Step 28: [Scissors] Tuning Scanner Stride to Shred PaperEDIT
🔒
STRATEGY★★★
Step 29: [Trap] Abducting Enemy Processes with "Vampire"EDIT
🔒
STRATEGY★★★
Step 30: Graduation Exam: Tune Your Warrior and Win the Final BattleEDIT
🟢 EDIT MODE (Click cells to modify)
[Addr][Opcode][A (Left)][B (Right)]
📦 DATA / BOMB (DAT)
0000
▼MOV
#
$
👈 EDIT
0001
▼MOV
<
<
0002
↺JMN
$
$
0003
❖SPL
@
#
0004
+ADD
#
$
0005
↺JMP
$
$
0006
■DAT
$0
$0
++ ADD ROW
0007
■DAT
$0
$0
0008
■DAT
$0
$0
0009
■DAT
$0
$0
0010
■DAT
$0
$0
0011
■DAT
$0
$0
0012
■DAT
$0
$0
0013
■DAT
$0
$0
0014
■DAT
$0
$0
0015
■DAT
$0
$0
0016
■DAT
$0
$0
0017
■DAT
$0
$0
0018
■DAT
$0
$0
0019
■DAT
$0
$0
0020
■DAT
$0
$0
0021
■DAT
$0
$0
0022
■DAT
$0
$0
0023
■DAT
$0
$0
0024
■DAT
$0
$0
0025
■DAT
$0
$0
0026
■DAT
$0
$0
0027
■DAT
$0
$0
🏟️ARENA (20 ROWS)SCOPE: 0000 - 0019
[CORE MEMORY 800 CELLS (20 ROWS × 40 COLS)]1:1 Row Synced with Editor
TASKS: 0
CYC: 0
📖 LECTURE NOTE // STEP 13 OF 30Chapter 2: Core Instructions & Autonomous Loops⏱ 5 min read
📖 Lecture Note: Computer Science & Artificial Life Principles Behind This Experiment

The Minimal Autonomous Program: State Machines and Digital Homeostasis

How the trinity of Computation (ADD), Control (JMP), and Memory (DAT) forms a self-sustaining automaton

#Finite State Automaton#Computation-Control-Storage Trinity#Counter Algorithm#Homeostasis#Turing Machine Prototype
🔬Step 13: Build Your First Program (Automatic Counter)

To complete Chapter 2, let's finish building an Automatic Counter! 1. 0000: ADD.AB #1, $2 (Add 1 to the data box 2 rows down at 0002) 2. 0001: JMP.A $-1, #0 (Jump 1 row up back to 0000) 3. 0002: DAT.F #0, #0 (The counter data box)

Right now, row 0000 adds #0, so the counter doesn't increase.

🎯 Your Task Change the A (Left Value) of 0000 from #0 to #1 (or higher), press [PLAY], and watch Cell 0002's B-value count up to 5 or more!

1. The Trinity of Computing: Operation, Control, and Storage

To complete Chapter 2, Step 13 brought together everything you have learned into a self-sustaining three-line program—an Automatic Counter: - Row 0000: "ADD.AB #1, $2" ➔ COMPUTATION (the active force that transforms state) - Row 0001: "JMP.A $-1, #0" ➔ CONTROL (the feedback loop that sustains execution across time) - Row 0002: "DAT.F #0, #0" ➔ STORAGE (the memory vessel that accumulates state)

Pause and admire these three lines. What you have built here is not merely a toy exercise—it is the irreducible archetype of every computer program ever written, from operating systems and database engines to modern artificial intelligence.

Consider what happens if any single pillar of this trinity is removed: - Without Row 0000 (Computation), the loop spins forever in place without ever changing the world. - Without Row 0001 (Control), the program adds 1 once and immediately falls into Row 0002 and dies. - Without Row 0002 (Storage), there is no state variable to remember the progress made by previous iterations. Only when Computation, Control, and Storage interlock does a static list of instructions awaken as a dynamic, evolving process.

┌─────────────────── THE COMPUTATIONAL TRINITY ───────────────────┐
│ [0000] ADD.AB #1, $2  ──► 1. COMPUTATION (ALU updates state)   ─┼─┐
│ [0001] JMP.A $-1, #0  ──► 2. CONTROL     (Loop sustains life)   │ │
│ [0002] DAT.F  #0, #5  ◄── 3. STORAGE     (Memory holds 1,2,3..)◄┘ │
└─────────────────────────────────────────────────────────────────┘

2. The Two-Cycle Metabolic Rhythm and Digital Homeostasis

When you pressed [PLAY] and watched Cell 0002 count upward (1, 2, 3, 4, 5...), you may have noticed a distinct rhythm: the counter increments once every TWO clock cycles. - On odd cycles (Cycle 1, 3, 5, 7, 9), the processor executes "ADD" at 0000, increasing the counter by 1. - On even cycles (Cycle 2, 4, 6, 8, 10), the processor executes "JMP" at 0001, returning the Program Counter to the top of the loop.

In biology, the ability of a living system to maintain a stable, self-regulating internal cycle is called Homeostasis. Your three-line automaton exhibits a two-cycle metabolic heartbeat: one beat to act upon memory, and one beat to reset its posture for the next action.

Notice also the dramatic transformation in the role of "DAT" at Address 0002. In earlier steps, a DAT cell was a lethal hazard waiting to kill our falling execution pointer. Now, because the JMP instruction on line 2 creates a protective boundary that turns the execution pointer back before it can ever touch line 3, that very same DAT cell is safely harnessed as an internal organ—a memory register storing our growing counter.

3. How a Simple Counter Evolves into a Bomber or Scanner

At this point, you might wonder: "Counting 1, 2, 3, 4, 5 inside box 0002 is neat, but how does a simple counter become a combat warrior?"

Imagine taking that exact number counting up inside Address 0002 (1, 2, 3, 4, 5...) and treating it not as a passive score, but as a target address coordinate (a Pointer)! On the first loop, your program fires at Address +1; on the second loop, it automatically fires at Address +2; on the third loop, Address +3—sweeping across the entire memory arena automatically without any human intervention!

The humble three-line counter you built in Step 13 is, in fact, the exact engine that powers every bomber (Dwarf), every scanner (Scissors), and every replicator (Paper) in CoreWar. In theoretical computer science, an automaton equipped with unbounded counters that can be incremented, decremented, and tested is known as a Minsky Register Machine (or Counter Machine)—a mathematical model proven by Marvin Minsky in 1961 to be Turing-complete, meaning it can compute anything that the most powerful supercomputer on Earth can compute! In Chapter 3, we will unlock the Von Neumann secrets that turn this counter into a true digital organism.

🔒

🔒 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.