The shape of the lesson
By the end of the lesson, learners can
- Three kinds of shift: In the lab, shift a byte left and right and watch the zeros enter and the end bits fall off.
- Test, set, clear, toggle: The 9618 instruction set has AND, OR and XOR, each with an immediate operand (#n, Bn or &n) or an address.
- Monitor and control: Run the "Bit masking" program in the lab: it tests one bit of a status byte, outputs Y or N, then sets another bit.
- Logical: zeros fill the gap; left multiplies, right divides (unsigned).
- Arithmetic: keeps the sign bit; cyclic: bits wrap round.
- Test: AND with 1 in that bit, then CMP #0. Clear: AND with 0 in that bit, 1s elsewhere.
- Set: OR with 1 in that bit. Toggle: XOR with 1 in that bit.
One picture every idea returns to
In a logical shift, bits move left or right and zeros fill the empty places (LSL #n, LSR #n). An arithmetic shift keeps the sign bit, so a two's complement number keeps its sign. In a cyclic shift (rotate), a bit leaving one end re-enters at the other. A mask is a bit pattern combined with the ACC: AND with a 1 in one place tests that bit (and AND with a 0 clears it), OR with a 1 sets a bit, and XOR with a 1 flips it, while all other bits are left unchanged.
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, Every bit counts.. A single byte can hold the on or off state of eight different devices: a heater, a fan, a light, an alarm. 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: Three kinds of shift | In the lab, shift a byte left and right and watch the zeros enter and the end bits fall off. Project tab 4 of the lab (Logical shifts) and let a student drive it while the class predicts. Your turn: Apply a cyclic shift of 2 places to the right to 10010011. | Whole class, then pairs |
| 13 to 21 min | Teach and check: Test, set, clear, toggle | The 9618 instruction set has AND, OR and XOR, each with an immediate operand (#n, Bn or &n) or an address. Model the worked example Two changes at once on the board, one line at a time. | Pairs |
| 21 to 30 min | Teach and check: Monitor and control | Run the "Bit masking" program in the lab: it tests one bit of a status byte, outputs Y or N, then sets another bit. Project tab 5 of the lab (Bit masking in assembly language) and let a student drive it while the class predicts. Your turn: With SENSOR holding B01001001, does the program jump to ALARM? What does CONTROL hold afterwards? | Corners |
| 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 Monitor and control, 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.
Corners
Put one answer or viewpoint in each corner of the room. Students move to the corner they agree with, justify the choice to a partner there, then hear one voice from each corner before the reveal.
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 |
|---|---|
| A logical right shift of a negative two's complement number does not halve it: the zero entering on the left makes it positive. | Use an arithmetic shift to keep the sign. |
| To clear a bit, the mask has a 0 in that bit and 1s everywhere else. | A mask of 00000001 with AND clears every bit except bit 0. |
Shifts, masks and bit manipulation: worksheet
6 questions, 19 marks. Written in the style of the papers; no past paper question is reproduced.
Describe the difference between a logical shift, an arithmetic shift and a cyclic shift.
The ACC holds the unsigned value 00110101. Give the contents of the ACC after (a) LSL #2 and (b) LSR #3, each applied to the original value. State the effect of each shift on the denary value.
The 8-bit two's complement value 10011000 is shifted 2 places to the right using an arithmetic shift. Give the result in binary and in denary.
Bit 3 of the byte at address STATUS switches on a pump. Write assembly language instructions, using the 9618 instruction set, to switch the pump on without changing any other bit.
Bit 6 of the byte at address SENSOR is 1 when a door is open. Write assembly language instructions, using the 9618 instruction set, to jump to the label DOOROPEN if the door is open.
The ACC holds 11010010. Give the contents of the ACC after XOR B00001111 and explain the effect of this mask.
Answer key and marking notes
- Logical: bits move left or right, zeros are introduced at the empty end and bits shifted out are lost.
- Arithmetic: the sign bit is preserved (in a right shift the sign bit is copied into the empty places), so signed numbers keep their sign.
- Cyclic: bits shifted out of one end are moved in at the other end, so no bits are lost.
- (a) 11010100.
- (a) 53 becomes 212: multiplied by 4.
- (b) 00000110.
- (b) 53 becomes 6: divided by 8 with the remainder lost (the bits 101 are lost).
- 11100110.
- −104 becomes −26 (divided by 4).
- LDD STATUS
- OR B00001000 (or OR #8 / OR &08)
- STO STATUS
- LDD SENSOR
- AND B01000000 (mask to keep only bit 6)
- CMP #0
- JPN DOOROPEN (or CMP B01000000 then JPE DOOROPEN)
- 11011101.
- The four least significant bits are inverted (toggled).
- The four most significant bits are unchanged, because XOR with 0 leaves a bit as it is.
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.
The accumulator holds 00101101. What does it hold after LSL #2?
- A10110100
- B00001011
- C01011010
- D10110111
Which instruction clears bit 5 of the accumulator to 0 and leaves every other bit unchanged? (Bits are numbered 7 on the left to 0 on the right.)
- A
AND B11011111 - B
AND B00100000 - C
OR B11011111 - D
XOR B11011111
The accumulator holds &5A. What does it hold after XOR &0F?
- A&55
- B&5F
- C&0A
- D&A5
The 8-bit two's complement value 10100100 (−92) has an arithmetic shift of 1 place to the right. What is the result?
- A11010010 (−46)
- B01010010 (82)
- C01001000 (72)
- D10010010 (−110)
The byte 10110001 is given a cyclic shift of 3 places to the right. What is the result?
- A00110110
- B00010110
- C10001101
- D11110110
Address 120 holds B10010110. What is output when this program runs? (ASCII: 89 is Y, 78 is N.)
100 LDD 120 101 AND B00000100 102 CMP #0 103 JPE 107 104 LDM #89 105 OUT 106 END 107 LDM #78 108 OUT 109 END
- AY, because bit 2 is 1, so the AND result is not 0 and JPE does not jump
- BN, because the AND result is not 0, so the compare is True and JPE jumps
- CN, because bit 2 of 10010110 is 0, so the AND result is 0
- DY, because the AND result is 0, so the compare is False and JPE does not jump
Quiz key
Each bit moves two places left, the two leading 0s are lost and two 0s enter on the right: 10110100 (45 × 4 = 180). 00001011 is a shift to the right, 01011010 is a shift of only one place, and 10110111 fills the gap with 1s, but a logical shift always brings in 0s.
x AND 0 = 0 and x AND 1 = x, so AND with 0 in bit 5 and 1s elsewhere clears only bit 5. AND B00100000 clears every bit except bit 5. OR B11011111 sets seven bits to 1 and leaves bit 5 alone. XOR B11011111 flips seven bits and leaves bit 5 unchanged.
&5A = 0101 1010 and &0F = 0000 1111. The low four bits are flipped, 1010 becomes 0101, and the high four are unchanged: 0101 0101 = &55. &5F is the result of OR, &0A the result of AND, and &A5 flips all eight bits, as XOR &FF would.
Each bit moves one place right and the sign bit 1 is copied into the empty place: 11010010, which is −46, half of −92. 01010010 is a logical shift, where a 0 enters and the number becomes positive. 01001000 is a shift to the left, and 10010010 keeps the sign bit but fills the gap with 0, which does not halve the value.
The three right-hand bits, 001, leave the right and re-enter on the left in the same order, in front of 10110: 00110110. 00010110 is a logical right shift, which loses those bits and brings in 0s. 10001101 is a cyclic shift to the left, and 11110110 is an arithmetic right shift, which copies the sign bit.
10010110 AND 00000100 = 00000100, because bit 2 (the third from the right) is 1. That is not 0, so CMP #0 is False, JPE does not jump, and LDM #89 then OUT outputs Y. The compare tests equality with 0, so a non-zero result makes it False, not True. Bit 2 is 1, not 0 (counting from the left gives the wrong bit), and the AND result is not 0.
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.