Combat Address Arithmetic and Initial Pointer Calibration
How base address, initial pointer offset, and step stride combine to calculate the exact landing coordinate of your first shot
Your first enemy (Red Warrior 2) has appeared in the Arena at Address 0400! The enemy is idling at 0400 with JMP $0.
Your Dwarf's pointer at 0003 starts at #392 (0003 + 392 = 0395). With ADD.AB #4, $3, the first bomb lands at 395 + 4 = 0399 and the second at 0403, jumping right over the enemy at 0400!
🎯 Your Task Change the highlighted A (Left Value) on row 0000 from #4 to #5 and press [PLAY] to score a direct hit on 0400 (395 + 5 = 400) and win your first battle!
1. Entering Combat: How MARS Alternates Turns Between Warriors
In Step 21, you graduated from solo target practice into real multi-warrior combat! For the first time, a red enemy program (Warrior 2) appeared halfway across the 800-cell Arena at Address 0400.
When two or more Warriors inhabit the same memory core, how does the MARS processor schedule their execution? MARS enforces strict, deterministic fairness through interleaved turn-taking: - On Cycle 1, Blue (Warrior 1—your program) executes one single instruction. - On Cycle 2, Red (Warrior 2—the opponent) executes one single instruction. - On Cycle 3, Blue executes its next instruction, and so on.
Neither warrior has "private" memory; both live inside the exact same 800 boxes. The battle continues until all execution pointers belonging to one side execute a DAT cell and perish, leaving the surviving warrior victorious. In operating systems history, this shared-memory environment resembles early cooperative multitasking systems (like early Mac OS or Windows 3.1) and embedded real-time kernels without an MMU (Memory Management Unit), where all tasks share a single flat physical address space and any pointer write can directly alter another task's code.
Target Formula: Landing Address = (Pointer Row) + (Initial B-Value) + (1st ADD Stride)
├─ Original (#4): 0003 + 392 + 4 = 0399 (Misses Enemy at 0400! Next shot is 0403)
└─ Tuned (#5): 0003 + 392 + 5 = 0400 (🎯 Direct Hit on Enemy at 0400 on Shot #1!)2. The Ballistic Equation: Base Row + Initial Offset + Stride
In this mission, your enemy was a tiny 1-line program ("JMP.A $0, #0") sitting at Address 0400. To destroy it, you tuned row 0000's step size from "#4" to "#5". Let's break down the exact ballistic math—known in systems programming as Address Arithmetic—that made your first shot a bullseye.
Where does Dwarf's very first bomb land? The landing coordinate is the sum of THREE numbers: 1. THE POINTER'S BASE ADDRESS: The pointer box ("DAT.F #0, #392") sits on the 4th line, which is Address 0003. Remember that in indirect addressing ("@2"), the second-stage offset is always measured relative to the pointer cell itself (0003). 2. THE INITIAL POINTER VALUE: At Cycle 0, the B-field of Cell 0003 starts at #392. Before the loop even begins, the pointer aims at 0003 + 392 = Address 0395. 3. THE FIRST "ADD" STRIDE: On Cycle 1, Line 1 ("ADD.AB #Stride, $3") executes BEFORE Line 2 ("MOV") launches the bomb!
Therefore, the exact landing address of Shot #1 is: Shot #1 Address = 0003 (Base) + 392 (Initial B) + Stride - With the original Stride of #4: Shot #1 lands at 0003 + 392 + 4 = Address 0399, and Shot #2 lands at 0399 + 4 = Address 0403—leaping right over the 1-cell enemy at 0400! - By tuning the Stride to #5: Shot #1 lands at 0003 + 392 + 5 = Address 0400—obliterating the enemy's JMP instruction on the very first volley!
3. Preventing Off-By-One Errors in Low-Level Programming
Missing a target address by a single cell—hitting 0399 instead of 0400—is a classic example of what software engineers call an Off-By-One Error.
When working with pointers in assembly or C, off-by-one bugs almost always happen for one of two reasons: forgetting which address serves as the zero base (here, the pointer cell stands at 0003, not 0000!), or forgetting whether the pointer is incremented before or after it is dereferenced (in Dwarf, ADD runs on line 1 before MOV dereferences the pointer on line 2). Mastering the equation "0003 + 392 + 5 = 0400" gives you the exact spatial precision required to engineer surgical strikes. In real-world systems programming—whether calculating memory buffer boundaries, indexing into hardware page tables, or aligning network packet headers—this exact discipline of verifying "Base + Initial Offset + Pre-Increment" saves engineers from catastrophic memory corruption bugs.
🔒 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.