Teacher answer key

Build Small Programs

Gather four kinds of evidence: prediction of relevant state; behavior across varied cases including boundaries; explanation using trace/state evidence; and a reasoned correction of one mismatch. Mark each as emerging, with support or independent using paper or your school’s existing approved process. A challenge pass is machine-behavior evidence, not proof of authorship or complete mastery. Accept equivalent correct programs; the public key is a model, not the only possible answer.

Public teaching material. Solutions are examples; equivalent correct programs may also pass the actual checks.

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

InstructionPC beforePC afterR0 beforeR0 afterRelevant stateOutput
STORE0100{"registers":[0,0,0,0,0,0,0,0],"flags":{"zero":false,"negative":false,"overflow":false},"sp":255,"stack":[],"callStack":[],"loopStack":[],"memoryReads":[],"memoryWrites":[200]}None
LOAD1200{"registers":[0,5,0,0,0,0,0,0],"flags":{"zero":false,"negative":false,"overflow":false},"sp":255,"stack":[],"callStack":[],"loopStack":[],"memoryReads":[200],"memoryWrites":[]}None
LOAD2300{"registers":[0,5,0,0,0,0,0,0],"flags":{"zero":true,"negative":false,"overflow":false},"sp":255,"stack":[],"callStack":[],"loopStack":[],"memoryReads":[],"memoryWrites":[]}None

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.