CalculateQuestion 1 · Recall
Loading…
By the end you can carry out logical, arithmetic and cyclic shifts on an 8-bit pattern, say what happens to the bits that fall off, and explain when a shift is the same as multiplying or dividing by a power of 2.
A register is just a row of bits. A shift slides the whole row one or more places left or right.
Two things have to be decided every time:
The three kinds of shift differ only in their answers to those two questions.
Logical shift
Bits move one place left or right; zeros enter the empty positions, and any bit pushed past the end is lost.
LSL, logical shift left): every bit moves towards the most significant end, zeros enter at the right.LSR, logical shift right): every bit moves towards the least significant end, zeros enter at the left.Losing bits is not a malfunction. It is what happens when the answer does not fit.
Worked example: Shifting 45 to the left, then to the right
ACC holds 0010 1101 (denary 45). Carry out (a) a logical shift left by 2, (b) a logical shift right by 2.
For unsigned binary, a logical shift is arithmetic in disguise:
It is a fast way for a processor to multiply or divide by 2, 4, 8 and so on — no multiplier circuit needed.
The rule has a hard limit: the answer must fit. 1100 0011 is 195. Shift it left by 1:
1100 0011 (195)
1000 0110 (134)
The leading 1 fell off the end and vanished. 195 × 2 = 390, which needs nine bits, and the register only has eight. The result is not 390 and it is not an error either — it is what a register does when a bit runs out of room. That is overflow, and it is why a left shift is only "multiply by 2" while the answer still fits.