The shape of the lesson
By the end of the lesson, learners can
- One-to- one: Load a program in the lab and run it: each line is one instruction, made of an opcode and (usually) an operand.
- The instruction set: These are the instructions you will meet in 9618 assembly questions, as printed in the syllabus.
- Two passes: A label can be used before the line where it is defined (a forward reference).
- Groups: data movement, input and output, arithmetic, unconditional and conditional jumps, compare.
- One-to-one: one assembly instruction becomes one machine code instruction.
- Pass 1: allocate addresses, build the symbol table (including forward references).
- Pass 2: look up opcodes, replace labels with addresses, generate object code.
One picture every idea returns to
Machine code is the binary instructions a processor executes directly. Assembly language is a low-level language that uses mnemonics (such as LDD and ADD) for opcodes and labels for addresses; each assembly instruction usually translates into one machine code instruction, and both are specific to one processor's instruction set. An assembler translates it. A two-pass assembler needs two passes because of forward references: pass 1 reads the code, allocates addresses and builds a symbol table of labels and their addresses; pass 2 uses the symbol table and the opcode table to generate the object code.
Forty-five minutes, phase by phase
| Time | Phase | What happens in the room | Grouping |
|---|---|---|---|
| 0 to 5 min | Hook: predict | Open with the question in the title, Mnemonics to machine code.. Machine code is just binary, which is hard for people to write and read. Put the figure on the board: it is the one picture every idea in the lesson returns to. | Whole class, then pairs |
| 5 to 13 min | Teach and check: One-to- one | Load a program in the lab and run it: each line is one instruction, made of an opcode and (usually) an operand. Project tab 5 of the lab (Assembly language with the 9618 instruction set) and let a student drive it while the class predicts. | Whole class, then pairs |
| 13 to 21 min | Teach and check: The instruction set | These are the instructions you will meet in 9618 assembly questions, as printed in the syllabus. Your turn: Classify each instruction into its group: CMI 210, OUT, LDR #0, JPN 104, DEC IX. | Pairs |
| 21 to 30 min | Teach and check: Two passes | A label can be used before the line where it is defined (a forward reference). Model the worked example Build the symbol table on the board, one line at a time. Your turn: What value is in TOTAL when the program above reaches END? | Think-Pair-Share |
| 30 to 36 min | Check | The four Stage 1 questions from the student lesson, answered on mini whiteboards or by show of fingers. Re-teach the one most get wrong. | Individual, then whole class |
| 36 to 43 min | Plenary | The exam-style questions from Stage 2, one at a time: thirty seconds alone, then a random call. The feedback lines in the key give the examiner's wording. | Individual, random call |
| 43 to 45 min | Exit and homework | Set the worksheet below (6 questions, 16 marks). Learners self-assess against the objectives before they leave. | Individual |
Protect the parts that carry the learning
The sequence carries about fifty minutes of material, so the lab is driven by one student while the class predicts rather than explored freely. Times are a guide.
Protected: the check at 30 minutes. It is the only individual read on whether the key idea landed, and it is not cut.
Cut first if the build overruns: the last check in Two passes, never the check or the plenary.
In a 60 minute block: run worksheet questions 1 to 3 in class as a Rally Coach set and model both the hardest worked example and its check live.
Think-Pair-Share
Pose the question, give thirty seconds of silent thinking, then a minute to compare with a partner before a few pairs share with the class. The silent minute is the part that cannot be cut.
The full structure, with its variations and the other twelve, is on the cooperative-learning page.
What to head off, and how
| Trap learners fall into | Teaching move that pre-empts it |
|---|---|
| Assembly language is not machine code. | It must still be translated, by an assembler, before the processor can execute it. |
| CMP only compares: it does not change the accumulator. | It sets the result that the next JPE or JPN uses. |
| Do not say pass 1 "translates" the program. | Pass 1 builds the symbol table; the object code is generated in pass 2. |
Assembly language and the two-pass assembler: worksheet
6 questions, 16 marks. Written in the style of the papers; no past paper question is reproduced.
Describe the relationship between assembly language and machine code.
Describe what happens during each pass of a two-pass assembler.
200 LDD FIRST 201 CMP SECOND 202 JPE SAME 203 LDM #78 204 JMP SHOW 205 SAME: LDM #89 206 SHOW: OUT 207 END 208 FIRST: 12 209 SECOND: 12
Complete the symbol table produced by pass 1 for this program, which starts at address 200.
For the program in the previous question, state the character that is output, and explain why. (ASCII: 78 is N, 89 is Y.)
Give the group to which each instruction belongs: (a) STO 300, (b) CMP #10, (c) IN.
Explain why an assembler that reads the program only once could not translate the instruction JMP SHOW at address 204.
Answer key and marking notes
- Assembly language uses mnemonics (and labels) in place of binary opcodes (and addresses).
- Each assembly language instruction translates into one machine code instruction (one-to-one).
- Pass 1: reads each line, removes comments and allocates an address to each instruction.
- Pass 1: adds labels and their addresses to the symbol table (including forward references).
- Pass 2: reads each line again, looks up the opcodes in the opcode table.
- Pass 2: replaces symbolic addresses with absolute addresses from the symbol table and generates the object code.
- SAME 205 and SHOW 206.
- FIRST 208.
- SECOND 209.
- FIRST and SECOND both hold 12, so the compare is True and JPE jumps to SAME.
- LDM #89 loads 89, so OUT outputs Y.
- (a) Data movement.
- (b) Compare.
- (c) Input and output.
- SHOW is a forward reference: it is defined later, at address 206.
- When line 204 is first read, the address of SHOW is not yet known, so the operand cannot be replaced by an absolute address.
6 multiple-choice questions on this lesson
From the topic question bank. Assign them in the app for a marked score in your gradebook, or run the topic as a class game.
Which statement describes the relationship between assembly language and machine code?
- AEach assembly language instruction usually translates into one machine code instruction
- BEach assembly language instruction translates into several machine code instructions
- CAssembly language is executed by the processor directly, so it is not translated
- DAssembly language works on any processor, but machine code works on only one
Which instruction belongs to the compare group of the 9618 instruction set?
- A
CMI 210 - B
JPE 210 - C
LDI 210 - D
SUB 210
Pass 1 of a two-pass assembler processes this program, which starts at address 300.
300 START: IN 301 CMP STOP 302 JPE FINISH 303 OUT 304 JMP START 305 FINISH: END 306 STOP: 35Which symbol table does pass 1 produce?
- ASTART 300, FINISH 305, STOP 306
- BSTART 300, FINISH 302, STOP 301
- CSTART 301, FINISH 306, STOP 307
- DSTART 304, FINISH 302, STOP 301
Which task is carried out in pass 2 of a two-pass assembler?
- AEach symbolic address is replaced by its absolute address from the symbol table
- BEach label is added to the symbol table with its address
- CAn address is allocated to each line using a location counter
- DForward references are recorded so their addresses can be filled in later
In this program, which labels are forward references?
300 START: IN 301 CMP STOP 302 JPE FINISH 303 OUT 304 JMP START 305 FINISH: END 306 STOP: 35
- AFINISH and STOP only
- BSTART only
- CSTART, FINISH and STOP
- DFINISH only
The program below runs and the user types the characters A, B and then # (ASCII: A is 65, B is 66, # is 35). What is output?
300 START: IN 301 CMP STOP 302 JPE FINISH 303 OUT 304 JMP START 305 FINISH: END 306 STOP: 35
- AAB
- BAB#
- C6566
- DBA
Quiz key
Assembly language replaces binary opcodes with mnemonics and addresses with labels, so the relationship is one-to-one. One statement becoming many machine code instructions describes a high-level language. Assembly language must still be translated by an assembler, and it is just as processor-specific as machine code, because it is written for one instruction set.
CMI compares the ACC with the contents of the address held at 210 (indirect), so it is a compare instruction. JPE uses the result of a compare but is a conditional jump. LDI is data movement (an indirect load), and SUB is arithmetic.
Each label takes the address of the line it labels: START 300, FINISH 305 and STOP 306. Using 302 and 301 gives the lines where FINISH and STOP are used, not defined. Starting the count at 301 is an off-by-one slip, and START 304 records the JMP that refers back to it.
In pass 2 the assembler looks up opcodes in the opcode table, swaps each label for its address from the finished symbol table and generates the object code. Adding labels to the symbol table, allocating addresses with a location counter and recording forward references all happen in pass 1.
FINISH is used at 302 but defined at 305, and STOP is used at 301 but defined at 306, so both are forward references. START is used at 304, after its definition at 300, so its address is already known: it is a backward reference. Leaving out STOP forgets that a data label used by CMP counts too.
A (65) is not equal to 35, so the compare is False, JPE does not jump and OUT outputs A; B is handled the same way. When # is typed the ACC holds 35, the compare is True and JPE jumps to FINISH before OUT, so # is never output. OUT outputs characters, not their codes, so 6566 is wrong, and each character is output as soon as it is typed, so the order is not reversed.
What to project
The student lesson embeds these tabs. Open them full screen on the projector; every slider has a drag handle on the stage.
Slides for this lesson
A projectable deck for every pack is on the way. Until then, present the student lesson full screen: its sections, figure and lab tabs follow the same order as the plan above.