AQA A level Computer Science [P1] Relative Symbolic Addressing Notes
Relative & Symbolic Addressing
— Computer Science · A Level (9618) · Paper 1 · Assembly language —
★ Exam Tip: A two-pass assembler question usually asks you to fill a symbol table in order (the circled numbers) and then explain how it was filled. Scan line by line, symbols first, absolute addresses next.
1. The Instruction Set (given in the paper)
The processor has one general purpose register — the Accumulator (ACC) — and an Index Register (IX).
Mnemonic
Operand
Binary
What it does
LDM
#n
1100 0001
Immediate addressing — load the number n into ACC
LDD
<address>
1100 0010
Direct addressing — load the contents of the given address into ACC
LDV
#n
1100 0011
Relative addressing — move n locations from the address of the current instruction, load the contents of that address into ACC
STO
<address>
1100 0100
Store the contents of ACC at the given address
DEC
—
1100 0101
Decrement the contents of ACC
OUTCH
—
1100 0111
Output the character whose ASCII code is in ACC
JNE
<address>
1110 0110
After a compare, jump to <address> if the compare was False
JMP
<address>
1110 0011
(Unconditionally) jump to the given address
CMP
#n
1110 0100
Compare the contents of ACC with number n
Watch out:JNE jumps when the compare was False (not equal). If ACC does equal n, JNE does not jump — the next line runs instead.
Three ways to load into ACC
Mode
Instruction
ACC gets…
Immediate
LDM #n
the number n itself
Direct
LDD <address>
the contents of that address
Relative
LDV #n
the contents of the address n places on from this instruction
Relative: address used = address of the current instruction + n
2. Tracing the Program (part b)
Task: complete the trace table for the assembly program. The teacher first numbered every line 0 – 16 (the address of each line, counting from the first instruction).
Pass 3 (CountDown = 13)LDV: 0 + 13 = 13ACC = 32CMP 32: 32 = 32 ⇒ compare True ⇒ JNE does not jumpJMP FinishLDM #88 ⇒ ACC = 88OUTCH ⇒ X, then END
Completed trace table
ACC
CountDown
OUTPUT
—
15
—
67
C
15
14
14
51
3
14
13
13
32
88
X
Blue rows were already printed in the question; green rows are the answers the teacher filled in.
Teacher’s comparisons: 67 ≠ 32 · 51 ≠ 32 · 32 = 32 — the loop stops only when ACC matches Num1 (32). Output of the program: C 3 X.
the program is a loop: print a character, count down, stop when ACC = 32
3. Two-Pass Assembler & Symbol Table (part c)
The program is translated by a two-pass assembler. It now begins with the directive ORG #0100, which tells the assembler to load the first instruction to address 100.
pass 1 → symbol table · pass 2 → needs a second table (the instruction table) to build the executable
Program with absolute addresses
Addr
Label
Instr.
Operand
—
ORG
#0100
100
StartProg:
LDV
#CountDown
101
CMP
Num1
102
JNE
CarryOn
103
JMP
Finish
104
CarryOn:
OUTCH
105
LDD
CountDown
106
DEC
107
STO
CountDown
108
JMP
StartProg
Addr
Label
Instr.
Operand
109
Finish:
LDM
#88
110
OUTCH
111
END
112
CountDown:
15
113
32
114
51
115
67
116
Num1:
32
Board slip corrected: on the board the line JMP StartProg was left without an address, so the numbers from Finish onward came out one too low (Finish 108, CountDown 111, Num1 115). Counting every line, the right values are Finish 109, CountDown 112, Num1 116. StartProg 100 and CarryOn 104 are unaffected.
Filling the symbol table — scan line by line
Teacher’s method: scan line by line; enter the symbols first, then the absolute addresses. The circled numbers show the order of the entries.
Symbolic address
Absolute address (in order made)
StartProg 1
100 2
CountDown 3
UNKNOWN411213
Num1 5
UNKNOWN611614
CarryOn 7
UNKNOWN810411
Finish 9
UNKNOWN1010912
Why this order?
StartProg is a label on the first line → ① with its address 100 ②.
CountDown appears as an operand in LDV (③, address not known yet → UNKNOWN ④).
Num1 in CMP → ⑤ UNKNOWN ⑥; CarryOn in JNE → ⑦ UNKNOWN ⑧; Finish in JMP → ⑨ UNKNOWN ⑩.
Later the labels CarryOn: ⑪, Finish: ⑫, CountDown: ⑬, Num1: ⑭ are reached, so UNKNOWN is struck out and the absolute address written in.
Repeat uses (LDD CountDown, STO CountDown, JMP StartProg) are already in the table — nothing new is added.
“Explain how the assembler made these entries.” [3]
Model answer (teacher’s bullets):
The assembler scans the assembly language instructions in sequence.
When it meets a symbolic address, it checks whether it is already in the symbol table.
If not, it adds it to the symbol table in the symbolic address column.
If it is already in the table, it checks whether the absolute address is known.
If the absolute address is known, it is entered in the appropriate cell.
If the absolute address is not known, it leaves it as UNKNOWN.
part (d)(i)1 mark
The assembler must then complete the second pass, building up the executable file. Name the second table needed.
Answer: Instruction table (the lookup of mnemonic → binary op code).
4. Symbol Table with Relative Addresses (part e)
Same idea, but there is no ORG — the table shows relative addresses, counted from the first instruction = 0. The teacher numbered every line 0 – 14.
Addr
Label
Instr.
Operand
0
StartProg:
LDV
#Offset
1
CMP
Value
2
JPE
EndProg
3
OUTCH
4
LDD
Offset
5
INC
6
STO
Offset
7
JMP
StartProg
8
EndProg:
END
Addr
Label
Instr.
Operand
9
Offset:
10
10
50
11
65
12
89
13
32
14
Value:
32
Note: JPE = jump if the compare was True (equal) — the opposite of JNE.
OUTCH, LDD/STO Offset, INC and JMP StartProg add nothing new — symbols already present.
5. Quick Recap
✓ Full Chapter Cheat-Sheet
LDM #n immediate (number) · LDD addr direct (contents) · LDV #n relative (address = current + n).
JNE jumps if compare is False; JMP always jumps; CMP #n compares ACC with n; OUTCH prints the ASCII char in ACC.
Trace: LDV #CountDown uses n = value in CountDown (15 → 14 → 13) → loads 67, 51, 32 → prints C 3 X.
Two-pass assembler: pass 1 builds the symbol table; pass 2 builds the executable using the instruction table too.
ORG #0100 → first instruction at address 100; no ORG (relative table) → first instruction = 0.
Symbol table: scan line by line → new symbol: add it, address UNKNOWN → when its label line is reached: strike UNKNOWN, write the address. Circled numbers = order of entries.
3-mark explanation: scan in sequence · check if symbol already in table · add if not · if present, check absolute address known · enter it if known · leave UNKNOWN if not.