COA Notes
Logical shift, arithmetic shift, and circular shift (rotate) operations with hardware implementation.
Introduction
Shift micro-operations move bits within a register left or right. While this sounds simple, shifts are remarkably versatile — they can multiply or divide by powers of 2, extract bit fields, serialize data for transmission, and implement efficient algorithms. The way the "empty" positions are filled and the "lost" bits are handled defines different shift types, each with its own purpose.
Types of Shift Operations
1. Logical Shift
Shifts bits in the specified direction. Empty positions are filled with zeros. The bit that falls off the end is typically stored in the Carry flag.
Logical Shift Left (LSL):
Effect: Multiplies unsigned number by 2 (equivalent to ×2)
Logical Shift Right (LSR):
Effect: Divides unsigned number by 2 (equivalent to ÷2, truncating)
2. Arithmetic Shift
Designed for signed numbers (two's complement). The key difference: arithmetic right shift preserves the sign bit.
Arithmetic Shift Left (ASL): Same as logical shift left — fill with zeros from the right.
Note: If the sign bit changes, overflow has occurred.
Arithmetic Shift Right (ASR): Fill with a copy of the sign bit (MSB):
Effect: Divides signed number by 2, rounding toward negative infinity.
3. Circular Shift (Rotate)
No bits are lost — the bit that falls off one end wraps around to the other end.
Rotate Left (ROL):
Rotate Right (ROR):
Rotate Through Carry: The carry flag acts as an extra bit in the rotation:
This is useful for multi-word shifts (shifting a value wider than one register).
RTL Notation for Shifts
Hardware Implementation
Basic Shifter (1-bit shift)
A 1-bit left shift is simply reconnecting wires:
No logic gates needed for a fixed 1-bit shift — just wiring!
Combinational Shifter
A shifter that can do different types of shifts uses multiplexers:
Barrel Shifter
For shifting by variable amounts (shift by 0 to n-1 positions in one cycle):
| Stage 1 | Shift by 0 or 1 (controlled by shift_amount[0]) |
| Stage 2 | Shift by 0 or 2 (controlled by shift_amount[1]) |
| Stage 3 | Shift by 0 or 4 (controlled by shift_amount[2]) |
An n-bit barrel shifter uses log₂(n) stages of multiplexers and can shift by any amount in a single clock cycle. This is what modern processors use.
Example: Shift by 5 (101₂):
- Stage 1 (bit 0 = 1): Shift by 1 ✓
- Stage 2 (bit 1 = 0): Don't shift
- Stage 3 (bit 2 = 1): Shift by 4 ✓
- Total: shifted by 5
Applications of Shift Operations
Fast Multiplication and Division
R1 ← shl R1 ; R1 = R1 × 2
R1 ← shl(shl R1) ; R1 = R1 × 4
R1 ← shr R1 ; R1 = R1 ÷ 2 (unsigned)
Multiply by 10: shift left 3 (×8) + shift left 1 (×2) + add:
Serial Data Transfer
Shift data out one bit at a time for serial communication:
Bit Field Extraction
Extract bits 4-7 from a register:
Cryptography
Many encryption algorithms use rotation operations (circular shifts) as part of their mixing functions.
Shift Operations Summary Table
| Operation | MSB (Left) | Fill | LSB (Right) | Use |
|---|---|---|---|---|
| Logical Left | → Carry | N/A | ← 0 | Unsigned ×2 |
| Logical Right | 0 → | N/A | → Carry | Unsigned ÷2 |
| Arithmetic Left | → Carry | N/A | ← 0 | Signed ×2 |
| Arithmetic Right | Sign → | Sign bit | → Carry | Signed ÷2 |
| Rotate Left | → wraps to LSB | N/A | N/A | Bit manipulation |
| Rotate Right | N/A | N/A | → wraps to MSB | Bit manipulation |
Key Takeaways
- Logical shifts fill with zeros — used for unsigned multiplication/division by 2
- Arithmetic right shift preserves the sign bit — used for signed division by 2
- Rotate wraps bits around without loss — used in cryptography and multi-word operations
- Shift left by n = multiply by 2ⁿ (much faster than actual multiplication)
- Barrel shifters can shift by any amount in one clock cycle using log₂(n) MUX stages
- Shift operations combined with AND masking enable powerful bit-field manipulation
- The ALU integrates shift hardware alongside arithmetic and logic units
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Shift Micro-operations.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Computer Organization & Architecture topic.
Search Terms
computer-organization, computer organization & architecture, computer, organization, register, transfer, and, microoperations
Related Computer Organization & Architecture Topics