Dissecting the Legendary "Dwarf" Bomber: Four Lines of Architectural Perfection
How ADD, MOV, JMP, DAT, and "@" indirect pointers crystallize into CoreWar's most iconic four-line predator
In Chapter 4, we dissect real combat Warriors! First, observe the complete 4-line classic bomber Dwarf, which combines everything you've learned so far:
1. 0000: ADD.AB #4, $3 ➔ Adds 4 to the B-value of the pointer/bomb box at 0003. 2. 0001: MOV.I $2, @2 ➔ Launches the DAT bomb at 0003 to the address pointed to by @2! 3. 0002: JMP.A $-2, #0 ➔ Jumps back to 0000 to repeat (dropping bombs every 4 cells!). 4. 0003: DAT.F #0, #0 ➔ Serves as both the target pointer and the DAT bomb template.
🎯 Your Task (No Editing Needed) Press [STEP] repeatedly or press [PLAY] to watch Dwarf drop bombs every 4 cells (0007, 0011, 0015...)!
1. Four Lines of Pure Combat Engineering
Opening Chapter 4, Step 19 let you dissect the complete, combat-ready "Dwarf"—the classic four-line bomber introduced alongside the Imp by A. K. Dewdney in 1984.
Dwarf occupies only four cells of memory (Addresses 0000 through 0003), yet those four lines synthesize every concept you mastered across the first eighteen steps into a single interlocking mechanism: - Line 1 (0000): "ADD.AB #4, $3" ➔ THE TARGETING COMPUTER (adds 4 to the B-field of Cell 0003 on every pass to advance the aim). - Line 2 (0001): "MOV.I $2, @2" ➔ THE LAUNCHER (copies the DAT cell at 0003 and hurls it via indirect pointer "@2" to the target address). - Line 3 (0002): "JMP.A $-2, #0" ➔ THE HEARTBEAT (jumps 2 rows back to 0000, sustaining a rapid 3-cycle bombing loop forever). - Line 4 (0003): "DAT.F #0, #0" ➔ THE POINTER & AMMUNITION DEPOT (holds the incrementing target offset: 0, 4, 8, 12...).
┌──► [0000] ADD.AB #4, $3 ──(1. Increments [0003].B: +4, +8, +12...)──┐
│ [0001] MOV.I $2, @2 ──(2. Fires [0003] to 0003 + [0003].B)──────┼──► 💥 [0007], [0011], [0015]...
└─── [0002] JMP.A $-2, #0 ◄─(3. Loops back to 0000 every 3 cycles) │
[0003] DAT.F #0, #0 ◄─(4. Dual Role: Target Pointer & Bomb!)────┘2. The Ingenious Dual Role of Cell 0003: Pointer AND Bomb
The most brilliant stroke of engineering in Dwarf lies in how Line 2 ("MOV.I $2, @2") uses Cell 0003 for two completely different jobs at the exact same time: - The Source Operand ("$2") asks: "What should I copy?" Counting 2 rows down from 0001 lands on Address 0003. So MOV picks up Cell 0003 itself as the bomb payload! - The Destination Operand ("@2") asks: "Where should I throw it?" Counting 2 rows down from 0001 ALSO lands on Address 0003, dereferencing its B-value to find the target coordinates!
Thus, the single DAT cell at 0003 serves simultaneously as the aiming pointer AND the ammunition template! Because of this dual role, the first bomb dropped onto Address 0007 is actually "DAT.F #0, #4", the second bomb dropped onto Address 0011 is "DAT.F #0, #8", and the third onto Address 0015 is "DAT.F #0, #12". Regardless of what number sits inside a DAT cell's B-field, any enemy execution pointer that steps onto a DAT opcode dies instantly. Combining the pointer and the bomb into one cell shrinks Dwarf's footprint by 20%, making it a smaller target for enemies to hit.
3. Why Dwarf Never Bombs Itself When Wrapping Around Memory
There is one more piece of mathematical magic hidden inside Dwarf. As Dwarf hurls bombs every 4 cells (0007, 0011, 0015...), its aim eventually wraps all the way around the circular 800-cell (or 8,000-cell) memory core and approaches its own body at 0000–0003. Why doesn't Dwarf accidentally bomb itself to death?
Let's do the modular math! Every bomb lands at an address of the form: Landing Address = (0003 + 4k) mod 800 Because the core size (800 in Academy, 8,000 in Laboratory) is an exact multiple of 4, as the bombs wrap around the top of memory they land on 0795, then 0799, and then (0799 + 4) mod 800 = Address 0003! Dwarf's three executable instructions at 0000, 0001, and 0002 are completely skipped over! The bomb at 0003 simply overwrites Dwarf's existing DAT cell at 0003 with itself, allowing Dwarf to survive its own barrage forever. This mathematical harmony—where a 4-line program uses a Mod-4 bombing step so that its own 3 lines of executable code sit safely inside the 3-cell gap between bombs—is one of the most celebrated examples of modular invariants in recreational computer science.
🔒 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.