COREWAR

/
Step 7: Observing the "ADD" Instruction
🎯Press [STEP] and observe Cell 0001 B-value become 5(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
👁️ OBSERVATION MODE (Press [STEP])
[Addr][Opcode][A (Left)][B (Right)]
📦 DATA / BOMB (DAT)
0000
▼MOV
#
$
0001
▼MOV
<
<
0002
↺JMN
$
$
0003
❖SPL
@
#
0004
+ADD
#
$
0005
↺JMP
$
$
0006
■DAT
$0
$0
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 07 OF 30Chapter 2: Core Instructions & Autonomous Loops⏱ 5 min read
📖 Lecture Note: Computer Science & Artificial Life Principles Behind This Experiment

The Arithmetic Logic Unit (ALU) and the Read-Modify-Write Micro-Cycle

Behind a single "ADD" instruction lies a three-phase round trip between memory cells and the processor's Arithmetic Logic Unit

#ALU (Arithmetic Logic Unit)#Read-Modify-Write#In-Place Mutation#Operand Modifier (.AB)#Accumulator
🔬Step 7: Observing the "ADD" Instruction

In Chapter 2, we'll learn the core instructions that manipulate memory. First, let's observe an example of the ADD instruction!

Address 0000 contains ADD.AB #2, $1: - A (Left Value): The number to add (#2) - B (Right Value): Where to add it ($1 = 1 box down at 0001) - The data box at 0001 starts with a B-value of 3.

🎯 Your Task (No Editing Needed) Press [STEP] once and watch the B-value of 0001 increase from 3 to 5 (3 + 2)!

1. The Mathematical Brain of the CPU: The ALU

Opening Chapter 2, Step 7 allowed you to observe the most fundamental arithmetic instruction in computing: "ADD.AB #2, $1". With a single click of the [STEP] button, the B-value inside the data box at Address 0001 transformed from 3 into 5.

Inside every physical or virtual processor, the hardware circuit responsible for actually performing math like "3 + 2 = 5" is called the ALU (Arithmetic Logic Unit). If the Program Counter (PC) is the navigator pointing to which line of code runs next, the ALU is the workshop floor where numbers are combined, subtracted, and compared.

Crucially, in a Von Neumann computer, memory cells (RAM) have no ability to do math on their own—they are passive storage boxes. How, then, does executing "ADD.AB #2, $1" at Address 0000 change the number stored inside Address 0001?

[0000] ADD.AB #2, $1  ──(1. Read Source A = 2 & Target B at 0001 = 3)──► ┌─────────┐
                                                                         │   ALU   │ (3 + 2 = 5)
[0001] DAT.F  #0, #5  ◄────────(2. Write Result 5 back to 0001.B)────────┘─────────┘

2. The Read-Modify-Write Sequence

On screen, the number 3 at Address 0001 appears to turn into 5 instantaneously. Under the hood of the MARS virtual machine, however, modifying a memory cell requires a classic three-phase hardware sequence known as Read-Modify-Write (RMW):

1. READ: The processor extracts the source value (#2) from the A-field of Address 0000. It then resolves the destination address ($1 = Address 0001), opens Cell 0001, and reads the current value of its B-field (3) into the ALU. 2. MODIFY: The ALU adds the two inputs together (3 + 2), producing the result 5. 3. WRITE: The processor writes the newly computed value (5) back into the B-field of Address 0001, overwriting the previous value of 3 in place.

Because ADD performs a complete Read-Modify-Write cycle rather than a blind overwrite, the prior state of Cell 0001 matters: starting with 3 and adding 2 yields 5. This ability to accumulate state over time is what allows memory cells to act as variables and counters. In multi-processor computer systems, hardware engineers must take special care to ensure that Read-Modify-Write cycles are executed atomically (indivisibly) so that no other processor can alter the memory cell between the Read step and the Write step. In MARS, every instruction's Read-Modify-Write sequence completes atomically within a single clock tick.

3. How the ".AB" Instruction Modifier Routes Data Between Rooms

Take a closer look at the two-letter suffix ".AB" in "ADD.AB". Because every memory box in CoreWar contains two number rooms (A and B), an instruction must specify which room to read from and which room to write into.

In the ICWS-94 standard, the two letters of the modifier act as a routing switchboard: - The first letter ("A" in .AB) tells the CPU to read the number from the A-field (left room) of the source. - The second letter ("B" in .AB) tells the CPU to add that number into the B-field (right room) of the destination cell.

Other modifiers like ".A" (left-to-left), ".B" (right-to-right), ".BA" (right-to-left), and ".F" (both rooms in parallel) give Redcode programmers surgical control over how data flows between rooms. In traditional microprocessors, this routing is handled by multiplexers (MUX circuits) that select which register bits enter the ALU and which byte lanes are enabled during a memory write. By exposing these modifiers explicitly in the instruction syntax, Redcode-94 lets you see the exact internal wiring of the processor on every line of code. Whenever you see ".AB", visualize a diagonal wire connecting the left room of the source directly into the right room of the destination.

🔒

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