Student worksheet

Repetition and Counters

Three lesson sections: predict, build, explain. Work on paper or in the local lab. No name, account or student record is requested by the app.

13. Loops: Repeating Things

Pair LOOP with RETURN and treat zero repeats correctly.

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 8
LOOP 4
  PRINT
RETURN
HALT

Queue input: None

Initialize memory: All bytes initially zero

InstructionPC beforePC afterR0 beforeR0 afterRelevant stateOutput
       
       
       

2. Build and check

Read a repeat count from 0 through 5. Print 8 exactly that many times, then halt.

Required instruction types: INPUT, LOOP, PRINT, RETURN

Starter program

INPUT
COPY R0 R1
LOAD 8
LOOP R1
  # Repeated instruction
RETURN
HALT

Your program and notes

3. Explain the machine

How many times does LOOP 0 execute its body?