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
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
Starter program
LOAD [200] R1
LOAD 0 R2
LOOP 3
INPUT
CMP R1
# Add one point only on a hit.
RETURN
LOAD R2
STORE 201
PRINT
HALT
Your program and notes
3. Explain the machine
What state changes on a correct guess and on an incorrect one?
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
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
Starter program
INPUT
COPY R0 R3
LOOP R3
# Read and push each byte.
RETURN
LOAD 0 R1
LOOP R3
# Pop, store, print, and move destination pointer.
RETURN
HALT
Your program and notes
3. Explain the machine
Why use two phases, and what should N=0 do?
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
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
Starter program
INPUT
COPY R0 R3
LOAD 64 R2
LOOP R3
INPUT
COPY R0 R4
INPUT
COPY R0 R1
# Choose and call a service, then store and print its result.
RETURN
HALT
double: MUL 2
RETURN
square: MUL R0
RETURN
increment: ADD 1
RETURN
Your program and notes
3. Explain the machine
Why can output 260 coexist with memory log 4?