Tracing questions give you a short assembly program and the starting contents of memory, and ask you to complete a trace table. There is no shortcut: you act as the processor, carrying out each instruction exactly. Learn a method that keeps every loop, compare and jump under control.
To trace a program, carry out one instruction at a time and record each change in a trace table, with a column for the ACC, any memory addresses that change, the IX if it is used, and the output. A CMP or CMI only sets the result of the comparison; the next JPE (jump if True) or JPN (jump if False) uses it. JMP always jumps. OUT outputs the character whose ASCII value is in the ACC.
Fig. 1: a program that multiplies 6 by 3 by repeated addition
Section 01
A loop, traced.
Run the "Loop with OUT" and "Indexed addressing: total" programs in the lab and watch the trace table fill up row by row. Then follow the program in Fig. 1 below.
100 LDD 200
101 ADD 201
102 STO 200
103 LDD 202
104 DEC ACC
105 STO 202
106 CMP #0
107 JPN 100
108 LDD 200
109 END
Memory at the start: address 200 holds 0, address 201 holds 6, address 202 holds 3.
Instruction address
ACC
200
202
Note
0
3
start
100
0
101
6
102
6
103
3
104
2
105
2
106, 107
2 ≠ 0: False, so JPN jumps to 100
100
6
101
12
102
12
103
2
104
1
105
1
106, 107
1 ≠ 0: False, so JPN jumps to 100
100
12
101
18
102
18
103
1
104
0
105
0
106, 107
0 = 0: True, so JPN does not jump
108
18
109
END
Examiner trap
JPN jumps when the compare was False. Reading it as "jump if not zero" works here only because the compare is with #0; always check what was actually compared.
Section 02
Characters in, characters out.
IN and OUT work with ASCII codes, not with numbers as you would type them. Keep an ASCII reminder beside you: 48 is the character 0, 65 is A and 97 is a.
100 LDR #0
101 LDX 200
102 CMP #0
103 JPE 107
104 OUT
105 INC IX
106 JMP 101
107 END
Memory: 200 holds 72, 201 holds 73, 202 holds 33, 203 holds 0. (ASCII: 72 is H, 73 is I, 33 is !)
Worked example Output a stored string
Trace the program above and state the output.
LDR #0 sets IX to 0. LDX 200 loads the contents of 200 + 0, so ACC = 72.
CMP #0 is False, so JPE does not jump. OUT outputs H. INC IX makes IX = 1 and JMP returns to 101.
LDX 200 now uses 201, so ACC = 73: OUT outputs I and IX = 2. Next, 202 gives ACC = 33: OUT outputs ! and IX = 3.
LDX 200 uses 203, so ACC = 0. CMP #0 is True, so JPE jumps to 107 and the program ends.
Answer: HI! (and IX finishes at 3)
Your turn
If address 202 held 0 instead of 33, what would the output be, and what would IX hold at the end?
The loop stops when ACC = 0 is loaded from 202, so the output is HI and IX finishes at 2.
Examiner trap
OUT does not print the number in the ACC. With 50 in the ACC, OUT outputs the character 2, not 50.
Stage 1 · Learn
Check what the sim just showed you
Four quick checks. Each correct answer earns XP and records this skill on your profile.
Quick check+10 XP
What does STO 200 change?
Quick check+10 XP
In the lab program "Loop with OUT", the ACC holds 51 when OUT runs. What is output?
Quick check+10 XP
After CMP #0 with ACC = 4, does JPN 100 jump?
Quick check+10 XP
In the Fig. 1 program, how many times is ADD 201 executed?
Section 03
A tracing method.
Examiners award marks for each correct column of values in the right order. These habits avoid the common slips.
Start with the given values: copy the starting contents of memory and registers into the first row.
One instruction, one change: only write a value when it changes. LDD changes the ACC; STO changes a memory location, never the ACC.
Compares change nothing: CMP and CMI leave the ACC as it is; note True or False, then decide whether the next JPE or JPN jumps.
Count the loops: a counter that starts at 3 and is decreased until it equals 0 gives exactly 3 passes.
Watch the operand: # means a number (ADD #1 adds 1); no # means an address (ADD 1 adds the contents of address 1).
Your turn
Memory holds 300: 5 and 301: 2. Trace: LDD 300, SUB 301, STO 302, SUB #1, CMP 301, JPE 108 (where 108 is END). Give the final ACC and the contents of 302, and state whether the jump is taken.
LDD 300: ACC = 5. SUB 301: ACC = 3. STO 302: 302 = 3. SUB #1: ACC = 2. CMP 301: 2 = 2, True, so the jump is taken.
Stage 2 · Exam
Exam-style questions
Unlocks once the four checks above are done. Worth more XP, written to AS Paper 1 and Paper 2 standard.
Finish the four checks above to unlock the exam questions
Exam style+20 XP
Memory: 200 holds 4. Trace LDD 200, INC ACC, STO 200, ADD 200. What is the final ACC?
Exam style+20 XP
Address 204 holds 25. Trace LDM #4, MOV IX, LDX 200. What is in the ACC?
Exam style+20 XP
The ACC holds 65. Which instruction pair outputs B?
Exam style+20 XP
A loop counter starts at 5, is decreased by 1 each pass and the loop ends with CMP #0 and JPN. How many passes are made?
Skill unlocked
Tracing assembly language programs, mastered.
This skill is now recorded on your profile. Keep the chain going.