28. A Tiny Target Game
Build a three-round game with stored state and scoring.
Open this lesson →
1. Predict and trace
Before running the Try program, predict its output and trace the first three executed instructions. Track the relevant registers, flags or memory as needed. Then step the program to compare.
STORE 5 200
LOAD [200] R1
LOAD 0 R2
LOOP 3
INPUT
CMP R1
JUMP_IF_ZERO hit
JUMP next
hit: LOAD R2
ADD 1
COPY R0 R2
next: NOP
RETURN
LOAD R2
STORE 201
PRINT
HALT
Queue input: 5, 2, 5
Initialize memory: 200: 5
Try prediction key
Output: 2
2. Build and check
Memory 200 contains a target byte. Read exactly three guesses. Count how many equal the target, store the score at memory 201, and print that score once.
Required instruction types: INPUT, CMP, LOOP, STORE, JUMP_IF_ZERO
Example challenge solution
LOAD [200] R1
LOAD 0 R2
LOOP 3
INPUT
CMP R1
JUMP_IF_ZERO hit
JUMP next
hit: LOAD R2
ADD 1
COPY R0 R2
next: NOP
RETURN
LOAD R2
STORE 201
PRINT
HALT
Actual checker fixtures
Case 1
- Input
5, 2, 5- Initial memory
200: 5- Expected output
2- Expected final memory
200: 5, 201: 2- Required memory reads
200
Case 2
- Input
1, 2, 3- Initial memory
200: 9- Expected output
0- Expected final memory
200: 9, 201: 0- Required memory reads
200
Case 3
- Input
0, 0, 0- Initial memory
200: 0- Expected output
3- Expected final memory
200: 0, 201: 3- Required memory reads
200
Case 4
- Input
17, 1, 2- Initial memory
200: 17- Expected output
1- Expected final memory
200: 17, 201: 1- Required memory reads
200
3. Explain the machine
What state changes on a correct guess and on an incorrect one?
Reasoning and teaching note
Score increments only on equality; target remains stored input/rule data. Three guesses produce a numeric score.
29. A Stack-powered Buffer Utility
Combine input, loops, the stack, and indexed storage.
Open this lesson →
1. Predict and trace
Before running the Try program, predict its output and trace the first three executed instructions. Track the relevant registers, flags or memory as needed. Then step the program to compare.
LOAD 3 R3
LOAD 10
PUSH
LOAD 20
PUSH
LOAD 30
PUSH
LOAD 0 R1
LOOP R3
POP
STORE R1
PRINT
LOAD R1
ADD 1
COPY R0 R1
RETURN
HALT
Queue input: None
Initialize memory: All bytes initially zero
Try prediction key
Output: 30, 20, 10
2. Build and check
Read N (0–5), then exactly N byte values. Use the data stack to reverse them. Print the reversed sequence and store it beginning at memory address 0.
Required instruction types: INPUT, LOOP, PUSH, POP, STORE
Example challenge solution
INPUT
COPY R0 R3
LOOP R3
INPUT
PUSH
RETURN
LOAD 0 R1
LOOP R3
POP
STORE R1
PRINT
LOAD R1
ADD 1
COPY R0 R1
RETURN
HALT
Actual checker fixtures
Case 1
- Input
0- Initial memory
All bytes initially zero- Expected output
None- Expected final memory
0: 0
Case 2
- Input
1, 7- Initial memory
All bytes initially zero- Expected output
7- Expected final memory
0: 7
Case 3
- Input
4, 1, 2, 3, 4- Initial memory
All bytes initially zero- Expected output
4, 3, 2, 1- Expected final memory
0: 4, 1: 3, 2: 2, 3: 1
Case 4
- Input
3, 0, 255, 8- Initial memory
All bytes initially zero- Expected output
8, 255, 0- Expected final memory
0: 8, 1: 255, 2: 0
3. Explain the machine
Why use two phases, and what should N=0 do?
Reasoning and teaching note
First collect/push, then pop/write/print in reverse; zero repeats produce no output or accidental writes.
30. Your Own Mini Operating System
Dispatch queued jobs to reusable services and record their results.
Open this lesson →
1. Predict and trace
Before running the Try program, predict its output and trace the first three executed instructions. Track the relevant registers, flags or memory as needed. Then step the program to compare.
LOAD 4
CALL double
STORE 64
PRINT
LOAD 3
CALL square
STORE 65
PRINT
HALT
double: MUL 2
RETURN
square: MUL R0
RETURN
Queue input: None
Initialize memory: All bytes initially zero
Try prediction key
Output: 8, 9
2. Build and check
Read N (0–3), then N pairs (operation, value). Operation 0 doubles, 1 squares, and 2 adds one. Dispatch through CALL subroutines. Print each full result and store its byte at addresses 64, 65, … in job order.
Required instruction types: INPUT, LOOP, CALL, CMP, STORE, RETURN
Example challenge solution
INPUT
COPY R0 R3
LOAD 64 R2
LOOP R3
INPUT
COPY R0 R4
INPUT
COPY R0 R1
LOAD R4
CMP 0
JUMP_IF_ZERO doubleJob
CMP 1
JUMP_IF_ZERO squareJob
LOAD R1
CALL increment
JUMP finish
doubleJob: LOAD R1
CALL double
JUMP finish
squareJob: LOAD R1
CALL square
finish: STORE R2
PRINT
LOAD R2
ADD 1
COPY R0 R2
RETURN
HALT
double: MUL 2
RETURN
square: MUL R0
RETURN
increment: ADD 1
RETURN
Actual checker fixtures
Case 1
- Input
3, 0, 4, 1, 3, 2, 9- Initial memory
All bytes initially zero- Expected output
8, 9, 10- Expected final memory
64: 8, 65: 9, 66: 10
Case 2
- Input
2, 1, -2, 0, 0- Initial memory
All bytes initially zero- Expected output
4, 0- Expected final memory
64: 4, 65: 0
Case 3
- Input
0- Initial memory
All bytes initially zero- Expected output
None- Expected final memory
64: 0
Case 4
- Input
3, 2, 255, 0, 130, 1, 16- Initial memory
All bytes initially zero- Expected output
256, 260, 256- Expected final memory
64: 0, 65: 4, 66: 0
3. Explain the machine
Why can output 260 coexist with memory log 4?
Reasoning and teaching note
R0 keeps the full safe integer; STORE keeps its low byte. Service CALLs hide calculation details, not the dispatch rule.