Skip to content
BetterDL

Program tracing

Also called: tracing, trace, hand tracing, desk checking

Running a program by hand, one instruction at a time, writing down every register and memory word that changes.

Tracing a program means playing the CPU yourself. Start from the reset state and, for each instruction the PC reaches, write down what changes.

A Tiny8 trace line usually records the PC, the ACC, Z and any memory word written. Habits that prevent slips:

  • PC after an instruction = its address + 1, unless a jump is taken.
  • Only LOAD, ADD and SUB change Z. STORE and jumps leave it alone.
  • 8-bit results wrap: 200 + 100 gives 44; 3 − 5 gives 254.
  • A word runs if the PC reaches it, whatever the programmer meant. 00 is HALT.
  • Data in listings is hex: 0A is 10, 14 is 20.
  • For a program loop, trace one pass carefully, spot the pattern, then check the last pass separately.

At the clock level you can also trace one register transfer per cycle, but for whole programs one instruction per line is enough.

Worked example

Example

A four-line trace

Tiny8 starts with PC = 0. Memory: 0: 1C LOAD C, 1: 4D SUB D, 2: 2E STORE E, 3: 00 HALT, C: 09, D: 04.

  1. 1.

    0 LOAD C: ACC = 9, Z = 0, PC = 1.

  2. 2.

    1 SUB D: ACC = 9 − 4 = 5, Z = 0, PC = 2.

  3. 3.

    2 STORE E: M[E] = 5, PC = 3. ACC and Z unchanged.

  4. 4.

    3 HALT: stop, with PC = 4.

  5. 5.

    Cycles: 6 + 6 + 6 + 5 = 23.

Common mistakes

  • Updating Z on a STORE.

  • Reading 14 in a listing as fourteen. It's hex: 20.

  • Stopping a loop trace one pass early or late. Check the final pass on its own.

Practice Program tracing

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Program tracing is taught in Basic CPU / Computer Architecture.