Tracing Assembly-Language Programs
A trace table records how a program changes the processor's state as its instructions execute. Follow one instruction at a time, update only the values that change, and use the actual next instruction after every jump.
By the end of this page, you should be able to:
- trace changes to ACC, IX and memory;
- explain why a store instruction does not clear ACC;
- evaluate comparisons and follow conditional or unconditional jumps;
- record the effects of IN and OUT;
- show the program state clearly in a trace table.
1. Trace one instruction at a time
Begin with the given values of the registers and memory. Read the instruction at the current program address, work out its effect, and then record the state after it executes.
- Write down the starting values for ACC, IX and any memory locations used.
- Process the instruction at the current address.
- Update only the register, memory location or output that changes.
- Follow the normal next instruction or the jump target.
- Continue until the program ends or the question asks you to stop.
2. Track registers and memory separately
A store instruction copies the value in ACC to the specified memory location. It does not remove the value from ACC. Later instructions can change ACC while the stored memory value remains unchanged.
| Instruction or action | What to record | What stays the same |
|---|---|---|
STO address |
The contents of that memory location become the value in ACC. | ACC keeps its value; IX is unchanged. |
INC IX or DEC IX |
IX increases or decreases by one. | ACC and memory stay unchanged. |
ADD or SUB |
ACC changes according to the arithmetic operation. | IX and unrelated memory locations stay unchanged. |
STO does not clear ACC
Copying a value into memory is not the same as moving it out of ACC. After STO, record
the copied value in memory and keep the same value in ACC unless a later instruction changes it.
3. Evaluate comparisons before following a jump
CMP compares ACC with an immediate value or with the contents at a memory address.
CMI follows an address stored in memory before comparing ACC with the data found there.
Record whether the comparison is true or false before deciding what runs next.
| Jump instruction | When the jump is taken |
|---|---|
JPE | When the comparison result is true. |
JPN | When the comparison result is false. |
JMP | Every time it executes; it does not check a comparison result. |
If a conditional jump is not taken, continue with the next instruction in sequence. If it is taken,
go to its target. An unconditional JMP always transfers control to its target.
4. Trace input and output
IN reads a character and places its ASCII value in ACC. OUT displays the
character represented by the ASCII value currently in ACC. The output is a character, not the denary
code itself.
| Instruction | Effect to record |
|---|---|
IN | Update ACC to the ASCII value of the input character. |
OUT | Record the character represented by the ASCII value in ACC. |
Interactive: step through a short program
This original example is set in a theatre's ticket-checking kiosk. Choose an input character, then use Next instruction to update the trace. You can move backward to review a step. The program stores the input, compares it, follows a branch, updates a register and memory, and outputs a character.
5. Use this checklist for a trace question
- Copy the given starting values accurately.
- Record the effect of each instruction before moving to the next one.
- Keep ACC, IX, memory and output in separate columns.
- After
CMPorCMI, decide whether the result is true or false. - Follow the jump target when a branch is taken; skip instructions that are not executed.
- Do not change values that the current instruction does not affect.
Do not trace skipped instructions
A taken jump changes the next instruction. Values do not change while skipped lines are bypassed. Resume the trace at the target instruction.
6. Check your understanding
Try each question before opening the suggested response.
-
ACC contains
31. What happens to ACC whenSTO 645executes?Suggested response
ACC remains
31. The instruction copies31into memory location645. -
ACC contains
56. A compare instruction checks ACC against61. Is the comparison true or false?Suggested response
False, because
56is not equal to61. -
After that comparison, what does
JPNdo?Suggested response
It takes the jump because the comparison result is false.
-
An input character has ASCII value
84. What is in ACC afterIN?Suggested response
ACC contains
84, the ASCII value of the input character. -
ACC contains the ASCII value for the character
T. What doesOUTdisplay?Suggested response
It displays the character
T, not the denary code.
Final check
Show the state after each relevant instruction. Include the comparison result and the address of the next instruction after a jump. Keep stored memory values and register contents distinct.