A-Level Computer Science — Assembly Language and the Two-Pass Assembler: five instruction groups, five addressing modes and program tracing (lesson-prep guide for tutors)
- 2026-11-27
Students can recite LDM and LDD, then answer “because of labels” when asked why a program is assembled twice. This chapter ties the two passes to 3 forward references in a 8-instruction program that occupies 9 locations, then traces a loop that prints AB one instruction at a time.
01 Prerequisites (3-minute check)
If any of these fails, fix it before the lesson starts.
| Skill | Quick check | Pass mark |
|---|---|---|
| Fetch-execute cycle | What are the three stages of executing an instruction | Fetch, decode, execute |
| Program counter | Does the PC hold the instruction or an address | The address of the next instruction |
| Hexadecimal with & | What is &4A in denary | 74 |
| Two complement negatives | What is 11111000 in 8-bit two complement | Minus 8 |
| Address and contents | Are address 300 and the contents of 300 the same thing | No: one is a location, the other is the value stored there |
02 Lesson flow (60 minutes)
| Time | Stage | Tutor does | Student does |
|---|---|---|---|
| 0-8 min | Opening: one assembly line is one machine instruction | Put LDM #65 beside its machine code and mark which part is the opcode and which is the operand | Say that one mnemonic maps to one opcode |
| 8-22 min | Pass 1: location counter and symbol table | Walk a 8-instruction program: add one per instruction, record a label with the current address, and note that a label takes no location | Fill in the addresses of loop and total |
| 22-34 min | Pass 2: look up and fill in | Re-read each line, replace loop with 2 and total with 8, and resolve the 3 forward references | Complete the operand of all four references |
| 34-44 min | The five instruction groups | Give two examples per group and stress that CMP with JPE and JPN is one group | Place a given instruction in the right group |
| 44-54 min | The five addressing modes | One memory, five loads: immediate 50, direct 400, indirect 77, indexed 91, relative to 45 and 37 | Work out what each load puts in ACC |
| 54-60 min | Tracing and the exit check | Trace the AB loop line by line and count 31 instructions | State the final ACC and the contents of address 300 |
03 Teaching script (read it out)
Scene 1: One assembly line, one machine instruction
The contrast with a high-level language matters: one high-level statement can become dozens of machine instructions, one-to-many, and the translator is a compiler; assembly is one-to-one and the translator is an assembler. That is also why assembly stays tied to a processor family: move to a different architecture and the same program must be rewritten, while a high-level program is merely recompiled.
Break one misconception immediately: a label is not an instruction. `loop:` and `total:` exist only in the source, giving an address a name; they emit no machine code and occupy no location. The demonstration program has 8 instructions and one data item, so it occupies 9 locations, and its two labels take none of them. That is the first piece of arithmetic a student must be able to state.
Student task: classify each line of a five-line source listing as instruction, label or data, then state how many memory locations the listing occupies.
Say this: the assembler decides nothing, it only matches; one line in, one line out.
Scene 2: Two passes: record addresses, then fill them in
Pass 1 does one job: walk the source once with a location counter starting at 0, add one to the counter for every instruction, and on every label write the pair (label, current counter) into the symbol table, without adding to the counter. At the end the table has two rows: loop is 2 and total is 8. Pass 1 needs no operand values at all, which is exactly why forward references are harmless here.
Pass 2 walks the source again, now holding the full symbol table, replaces every label in an operand with its number and emits machine code. The program has four references: 3 forward references to total at addresses 1, 2 and 4, and 1 backward reference from JPN loop at address 6 back to 2. Make the phrasing precise: a forward reference is not an error, it is merely information that arrives late, which is what pass 1 exists for.
Error checking splits the same way: pass 1 catches a duplicated label, pass 2 catches an undefined label. Mention in one sentence that a single pass with back-patching also works, but the syllabus asks for the stages of a two-pass assembler, so answers use two passes.
Student task: from a 12-instruction program with 5 labels, write the whole symbol table with every address, and count the forward and backward references.
Say this: pass 1 does one thing, turning names into addresses; pass 2 puts those addresses into the instructions.
Scene 3: Five groups, five modes, one trace
One memory shows all five modes at once: address 300 holds 400, address 400 holds 77, IX is 4 and address 304 holds 91. LDM #50 gives 50, the operand is the value. LDD 300 gives 400, the operand is the address. LDI 300 gives 77, because the cell named holds another address, one level deeper. LDX 300 gives 91, because the address is 300 plus IX. Relative addressing belongs to jumps: JMP +5 at address 40 reaches 45, and JMP -3 reaches 37; the offset is measured from the current instruction, so add one more if a question says the offset starts at the next instruction.
Now trace the loop that prints AB: ACC loads 65, the character A, and stores it at 300, while counter 301 starts at 0. The loop reads 300, compares with 67, prints while unequal, adds one to the counter and to the value, then jumps back. The second pass prints B. The third reads 67, CMP finds equality, JPE leaves the loop, and the counter 2 is loaded into ACC before the program ends. That is 31 instructions executed, 2 characters printed, address 300 ending at 67 and address 301 at 2.
Student task: change the starting value at address 300 from 65 to 88, the character X, and state the output, the number of iterations, and the new instruction count.
Say this: tracing is not reading, it is filling a table: ACC, any changed memory, and where the PC goes next.
04 Question types and worked steps
| Type | Example | Steps | Answer |
|---|---|---|---|
| Pass 1: build the symbol table | A program of 12 instructions with 5 labels | Start the counter at 0, add one per instruction, write each label with the current address, and give a label no location | start 1, loop 2, done 9, count 12, result 13, over 14 locations |
| Pass 2: fill in the addresses | The same program | Re-read every line, look up each label operand and replace it with a number, then emit machine code | 4 forward and 1 backward references resolved |
| Identify the addressing mode | LDM #50, LDD 300, LDI 300, LDX 300 | Ask whether the operand is a value or an address; a cell holding another address is indirect; adding IX makes it indexed | immediate 50, direct 400, indirect 77, indexed 91 |
| Trace a program | The loop that prints A and B in 8 instructions | Fill a table row per line: ACC, changed memory, next address; after a compare write whether the condition was true | ACC ends at 2, address 300 holds 67, 31 instructions |
| Place an instruction in a group | INC ACC, JPN loop, CMI 300 | Five groups: data movement, input and output, arithmetic, unconditional and conditional, compare | Arithmetic, conditional jump, compare |
05 Independent practice (3 questions)
| Question | Answer | What to watch |
|---|---|---|
| A program has 12 instructions, 5 labels and two data items. After assembly, how many rows does the symbol table have and at what addresses? How many locations does the program occupy, and how many references point forward and backward? | 5 rows: start 1, loop 2, done 9, count 12, result 13; 14 locations, 12 instructions plus two data items; 4 forward and 1 backward | Count instructions to fix the addresses, then record labels; each data item also needs a location, and labels need none |
| Address 600 holds 700, address 700 holds 42, address 608 holds 99, and IX is 8. What do LDM #42, LDD 600, LDI 600 and LDX 600 put into ACC? | 42 for immediate, 700 for direct, 42 for indirect because address 600 holds 700, and 99 for indexed because 600 plus 8 is 608 | Ask of each instruction whether the operand is the value itself or an address to look up |
| A program uses address 400 as a running total and address 401 as a countdown, starting at 0 and 4. Each iteration adds the countdown to the total and subtracts one from the countdown, stopping when the countdown reaches zero. What are ACC, address 400 and address 401 at the end? | ACC 10, address 400 holds 10, address 401 holds 0 | 4 plus 3 plus 2 plus 1 is 10; JPN does not jump when the compare is true, so the loop ends only after the countdown reaches 0 |
06 Common mistakes and what to say
| Mistake | Student writes | Say this |
|---|---|---|
| Counting a label as an instruction | Saying 8 instructions plus two labels need 11 locations | A label is only a name and emits nothing; 8 instructions plus one data item is 9 locations. |
| Treating LDI and LDD as the same | Saying LDI 300 and LDD 300 both give 400 | LDD 300 reads the contents of address 300, which is 400; LDI 300 reads that value and then reads the cell it points to, giving 77, one level deeper. |
| Filling in operands during pass 1 | Saying pass 1 can already emit complete machine code | At STO total, pass 1 has not yet reached total at address 8, so a forward reference cannot be resolved; pass 1 only builds the table, pass 2 fills it in. |
| Letting CMP overwrite ACC in a trace | Writing that ACC becomes zero after CMP | CMP updates flags only and leaves ACC alone; JPE and JPN read the flags, so ACC still holds the last value loaded. |
07 Homework (paper, section and question numbers)
- A-Level Computer Science chapter index — Every chapter in this subject
- All lesson-prep guides — Other subjects in the same series
- Redo this chapter — Practice questions 1 to 3: the symbol table for 12 instructions, four loads under four addressing modes, and the countdown total trace
08 Exit check (last 5 minutes)
| Question | Answer | Decision |
|---|---|---|
| One stage | Pass 1 builds the symbol table, pass 2 fills in the addresses | No answer on the two stages means scene 2 needs redoing |
| One figure | 8 instructions plus one data item is 9 locations | Saying 11 means the labels were counted as instructions |
| One difference | LDD reads one level and gives 400, LDI reads two and gives 77 | Saying both are the same means scene 3 needs redoing |
09 Tutor FAQ
Why not write machine code directly?
Because every address shifts whenever the program changes. Write total as a label and add one instruction, and the assembler recomputes all 3 forward references; by hand you would recount addresses each time. Readability, easy editing and portability across one processor family are the other reasons.
Are two passes compulsory? Can it be done in one?
Yes, by leaving operands blank and patching them once the labels are met. But the syllabus asks for the stages of a two-pass assembler, so answer pass 1 then pass 2, and describe back-patching only as an alternative implementation.
How is a relative address worked out?
Add the offset to the address of the current instruction. JMP +5 at address 40 reaches 45, and JMP -3 reaches 37. If a question states that the offset starts at the next instruction, add one more, and always say which convention you used.
Find a tutor — freeTutor Registration →
A TutorZone lesson-prep guide. Written by the TutorZone team; questions and lesson flow are original and are not taken from any school or publisher material.



