The shape of the lesson
By the end of the lesson, learners can
- 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.
- Characters in, characters out: IN and OUT work with ASCII codes, not with numbers as you would type them.
- A tracing method: Examiners award marks for each correct column of values in the right order.
- Start row: copy every starting value first.
- Record changes only: LDD, ADD, SUB, INC, DEC change the ACC; STO changes memory.
- Compare then jump: JPE jumps if True, JPN if False, JMP always.
- ASCII: OUT and IN use character codes (48 = 0, 65 = A).
One picture every idea returns to
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.
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, One line at a time.. Tracing questions give you a short assembly program and the starting contents of memory, and ask you to complete a trace table. 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: 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. Project tab 5 of the lab (Trace an assembly language program) and let a student drive it while the class predicts. | Whole class, then pairs |
| 13 to 21 min | Teach and check: Characters in, characters out | IN and OUT work with ASCII codes, not with numbers as you would type them. Model the worked example Output a stored string on the board, one line at a time. Your turn: If address 202 held 0 instead of 33, what would the output be, and what would IX hold at the end? | Pairs |
| 21 to 30 min | Teach and check: A tracing method | Examiners award marks for each correct column of values in the right order. 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. | Round Table |
| 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, 19 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 A tracing method, 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.
Round Table
One sheet travels round the team. Each student adds one line of working or one idea and passes it on, so the solution is built four hands at a time and every contribution is visible.
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 |
|---|---|
| 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. |
| OUT does not print the number in the ACC. | With 50 in the ACC, OUT outputs the character 2, not 50. |
Tracing an assembly language program: worksheet
6 questions, 19 marks. Written in the style of the papers; no past paper question is reproduced.
100 LDR #0 101 LDX 240 102 ADD 250 103 STO 250 104 INC IX 105 LDD 251 106 DEC ACC 107 STO 251 108 CMP #0 109 JPN 101 110 END
Memory: 240 holds 4, 241 holds 9, 242 holds 2, 250 holds 0, 251 holds 3. Trace the program and give the final contents of addresses 250 and 251, the IX and the ACC.
100 LDM #0 101 STO 300 102 IN 103 CMP #46 104 JPE 109 105 LDD 300 106 INC ACC 107 STO 300 108 JMP 102 109 LDD 300 110 ADD #48 111 OUT 112 END
The user types the characters A, B and then a full stop. (ASCII: A is 65, B is 66, the full stop is 46, the character 0 is 48.) State the final contents of address 300 and the output, and describe what the program does.
Explain the difference between the instructions JPE and JPN.
Memory: 150 holds 152, 151 holds 7, 152 holds 20. Trace LDI 150, SUB 151, STO 151, CMI 150. Give the contents of the ACC and address 151, and state whether the compare is True or False.
Write assembly language instructions, using the 9618 instruction set, to input a character and output it twice.
A loop is meant to run 4 times. The counter is stored at address 90 and starts at 4. The loop ends with LDD 90, DEC ACC, STO 90, CMP #1, JPN to the start of the loop. Explain why the loop does not run 4 times, and correct it.
Answer key and marking notes
- First pass: ACC = 4, 250 = 4, IX = 1, 251 = 2.
- Second pass: ACC = 9 + 4 = 13, 250 = 13, IX = 2, 251 = 1.
- Third pass: ACC = 2 + 13 = 15, 250 = 15, IX = 3, 251 = 0.
- CMP #0 is True, so JPN does not jump; the program ends.
- Final: 250 = 15, 251 = 0, IX = 3, ACC = 0.
- 300 holds 2 (incremented for A and for B).
- When 46 is input, JPE jumps to 109; ACC = 2 + 48 = 50.
- OUT outputs the character 2.
- The program counts the characters typed before a full stop and outputs the count (as a digit).
- JPE jumps to the given address if the previous compare was True.
- JPN jumps to the given address if the previous compare was False (otherwise the next instruction is executed).
- LDI 150: 150 holds 152, which holds 20, so ACC = 20; SUB 151: ACC = 20 - 7 = 13.
- STO 151: address 151 = 13.
- CMI 150: compares the ACC (13) with the contents of 152 (20), so False.
- IN
- OUT
- OUT (followed by END); the ACC is not changed by OUT, so the second OUT outputs the same character.
- The counter goes 3, 2, 1: the compare is True when it reaches 1, so the loop runs only 3 times.
- Compare with 0 instead: CMP #0.
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.
Address 200 holds 7 and address 201 holds 3. What is in the accumulator after these instructions?
LDD 200 SUB 201 STO 202 ADD 202
- A8
- B4
- C11
- D10
What is output by these instructions? (ASCII: 65 is A, so 66 is B, and so on.)
LDM #70 ADD #2 OUT
- AH
- B72
- CJ
- DF
How many times is the instruction at address 103 executed when this program runs?
100 LDM #0 101 STO 300 102 LDD 300 103 ADD #3 104 STO 300 105 CMP #12 106 JPN 102 107 END
- A4
- B3
- C12
- D5
The ACC holds 5 and CMP #5 has just been executed. Which statement is correct?
- AA following JPE would jump, but a JPN would not
- BA following JPN would jump, but a JPE would not
- CBoth JPE and JPN would jump
- DThe CMP has set the ACC to 0, so neither would jump
Memory: 240 holds 5, 241 holds 8, 242 holds 3, 243 holds 0 and 244 holds 6. Trace the program. What are the final contents of address 250 and the index register?
100 LDR #0 101 LDM #0 102 STO 250 103 LDX 240 104 CMP #0 105 JPE 110 106 ADD 250 107 STO 250 108 INC IX 109 JMP 103 110 END
- A250 holds 16 and IX holds 3
- B250 holds 22 and IX holds 4
- C250 holds 16 and IX holds 4
- D250 holds 13 and IX holds 2
The user types C, A, T and then a full stop. What is output? (ASCII: A is 65, C is 67, T is 84, the full stop is 46.)
100 IN 101 CMP #46 102 JPE 106 103 INC ACC 104 OUT 105 JMP 100 106 END
- ADBU
- BCAT
- CDBU/
- DBZS
Quiz key
LDD 200 gives 7, SUB 201 gives 7 − 3 = 4, STO 202 stores 4 at 202 (the ACC is still 4), and ADD 202 gives 4 + 4 = 8. 4 stops before the final ADD. 11 adds the stored 4 to the original 7, as if STO had reset the ACC, and 10 adds the contents of 201 instead of subtracting them.
LDM #70 loads 70 and ADD #2 makes 72; 72 − 65 = 7 letters after A, which is H. OUT outputs a character, not the number 72. J would be 74 and F is 70, the value before the addition.
The ACC at the compare is 3, 6, 9 and then 12. The first three compares are False, so JPN jumps back; at 12 the compare is True and the program ends. That is 4 executions of ADD #3. 3 forgets the final pass that reaches 12, 12 confuses the target value with the number of passes, and 5 counts one pass too many.
5 equals 5, so the compare is True. JPE jumps when the compare was True, and JPN jumps only when it was False, so JPE jumps and JPN does not. Only one of the two can act on a given result, and CMP never changes the ACC: it only records the result of the comparison.
IX = 0 loads 5 (total 5), IX = 1 loads 8 (total 13), IX = 2 loads 3 (total 16), then IX = 3 loads 0 from 243: the compare is True and JPE jumps to END before INC IX, so IX stays 3. 22 adds the 6 at 244, which is never reached. IX 4 increments once more after the 0 was found, and 13 with IX 2 stops one pass early.
Each code is increased by 1 before OUT, so C (67) becomes D, A becomes B and T (84) becomes U. When the full stop (46) is typed the compare is True and JPE jumps to END, so it is never output (its successor would be /). CAT ignores INC ACC, and BZS subtracts 1 instead of adding it.
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.