Registers and shift registers
Registers built from D flip-flops, parallel load, the four shift-register types, the universal shift register, shifts and rotates and what they mean arithmetically, and serial addition.
Why it exists
A single flip-flop stores one bit. A processor stores words: the program counter, the instruction register, the accumulator. A register is a row of flip-flops that are loaded and read together. A shift register moves its contents one position on each clock pulse, which is how data is converted between serial and parallel form (a keyboard, a serial port, a network interface), how a processor multiplies and divides by powers of two, and how many arithmetic units step through the bits of an operand. GATE asks for the contents after some clock pulses, the number of pulses needed, the type of shift register for a task, and what shifts do to a number.
Prerequisites
You need the D flip-flop from latches and flip-flops.
Precise definitions
Register. D flip-flops with a common clock. Loading a word means putting it on the inputs before the clock edge; after the edge the flip-flops hold it. To keep the old value when not loading, add a load control : each stage has a 2:1 multiplexer (new data when , own output when ). An -bit loadable register is flip-flops and 2:1 multiplexers.
Shift register. A register whose stages are connected in a chain: each stage's input is the previous stage's . At every clock edge all stages copy their neighbour simultaneously, so the data moves one position. In this page shift left means toward the more significant end, so and the serial input enters (as in the animation below), and shift right means .
Types by how data enters and leaves:
| Type | In | Out |
|---|---|---|
| SISO | serial | serial |
| SIPO | serial | parallel (all at once) |
| PISO | parallel (load) | serial |
| PIPO | parallel | parallel (an ordinary register) |
SIPO converts serial data to parallel in clock pulses; PISO converts parallel data to serial in pulses. A word shifted in serially emerges in the same order after more pulses (first in, first out).
Universal shift register. One register that can hold, shift left, shift right and load in parallel, selected by a 2-bit mode input . Each stage has a 4:1 multiplexer in front of its flip-flop: input 0 is the stage's own (hold), input 1 is the upper neighbour (shift right), input 2 is the lower neighbour (shift left), input 3 is the parallel input. An -bit universal shift register is flip-flops and 4:1 multiplexers.
Shifts as arithmetic. For an -bit register:
- Logical shift left by one: a 0 enters at the bottom, the top bit goes to the carry. For an unsigned number this multiplies by 2, correct if the carry out is 0.
- Logical shift right: a 0 enters at the top. For an unsigned number this is integer division by 2 ().
- Arithmetic shift right: the sign bit is copied back into the top. For a 2's complement number this is , rounding toward minus infinity (so and ).
- Arithmetic shift left: the same as logical shift left; the result is correct unless the sign bit changes (overflow).
- Rotate (circular shift): the bit that leaves one end enters at the other. rotations in one direction restore the register.
Serial adder. Two shift registers hold the operands, one full adder adds one pair of bits per clock pulse starting from the least significant bit, and a carry flip-flop keeps the carry for the next pulse. The sum bits are shifted into one of the registers. It needs pulses and one full adder, against one step and full adders for a parallel adder: slower but much cheaper.
Clocking. All stages share one clock, so every stage changes at the same instant (a synchronous shift register). The data that a stage copies is the neighbour's value just before the edge; it is not the new value, which is why the data advances one stage per pulse and not all the way through.
How it works
Step through four clock pulses shifting in the serial input 1, 0, 1, 1. At each rising edge every stage takes the value of its left neighbour (the serial input for ), so the first bit entered ends up in after four pulses.
4-bit shift register: serial in 1, 0, 1, 1: Start
Simulated, not typedDashed lines mark rising clock edges. Green is an output, blue a stored state, black an input, grey the clock. One tick = one time unit.
Step 1
Four D flip-flops in a row: the serial input feeds Q0 and each Q feeds the next D. All are clocked together, so at every rising edge each stage copies its left neighbour. The register starts at 0000.
The data-path view of the same hardware: what shifts and rotates do to the value in an 8-bit register, read as an unsigned number and as a 2's complement number.
Shift and rotate operations on an 8-bit register: Start
Computed exactly, not typedWorking
register = 1011 0110
Value, format and bits (changed bits in amber)
Step 1
An 8-bit register. As unsigned it holds 182; read as 2's complement it holds -74. The same operations are applied to it in turn, each from the starting value.
Worked examples
EX 1Shift, rotate and a serial adder in a program
Easy#include <stdio.h>
#include <stdint.h>
static void show(const char *what, uint8_t x) {
printf("%-24s", what);
for (int i = 7; i >= 0; i--) putchar(((x >> i) & 1) ? '1' : '0');
printf(" unsigned %3u signed %4d\n", x, (int8_t)x);
}
/* serial adder: one full adder and one carry flip-flop, least significant bits first */
static unsigned serial_add(unsigned a, unsigned b, int n, int *carry_out) {
int carry = 0;
unsigned s = 0;
for (int i = 0; i < n; i++) {
int x = (a >> i) & 1, y = (b >> i) & 1;
s |= (unsigned)(x ^ y ^ carry) << i;
carry = (x & y) | (carry & (x ^ y));
}
*carry_out = carry;
return s;
}
int main(void) {
uint8_t v = 0xB6;
show("start", v);
show("logical shift left", (uint8_t)(v << 1));
show("logical shift right", (uint8_t)(v >> 1));
show("arithmetic shift right", (uint8_t)(((int8_t)v) >> 1));
show("rotate left", (uint8_t)((v << 1) | (v >> 7)));
show("rotate right", (uint8_t)((v >> 1) | (v << 7)));
int c;
unsigned s = serial_add(11, 6, 4, &c);
printf("serial adder, 4 clock pulses: 1011 + 0110 gives sum bits %u and carry %d\n", s, c);
int bad = 0;
for (unsigned a = 0; a < 16; a++)
for (unsigned b = 0; b < 16; b++) {
unsigned r = serial_add(a, b, 4, &c);
bad += r + ((unsigned)c << 4) != a + b;
}
printf("serial adder wrong on %d of 256 pairs\n", bad);
return 0;
}start 10110110 unsigned 182 signed -74
logical shift left 01101100 unsigned 108 signed 108
logical shift right 01011011 unsigned 91 signed 91
arithmetic shift right 11011011 unsigned 219 signed -37
rotate left 01101101 unsigned 109 signed 109
rotate right 01011011 unsigned 91 signed 91
serial adder, 4 clock pulses: 1011 + 0110 gives sum bits 1 and carry 1
serial adder wrong on 0 of 256 pairsThe first six lines are the animation's register operations. A logical left shift doubles 182 to 364, and the register keeps only the low 8 bits (108). The arithmetic right shift keeps the sign: becomes . The serial adder adds one bit pair per clock pulse and gives the correct 4-bit sum and carry for all 256 pairs.
EX 2Contents after the clock pulses
EasyA 4-bit SIPO shift register starts at 0000 and receives the serial input 1, 0, 1, 1 (first bit first), one bit per rising edge, shifting toward . After the first pulse , after the second 0010, after the third 0101, after the fourth 1011. Then four more pulses with a 0 on the input shift the word out of as 1, 0, 1, 1: the same order as it went in.
EX 3How many pulses?
Medium(a) To load an 8-bit word into a SIPO register from a serial line takes 8 pulses. (b) To send it out through a PISO register takes 8 pulses (after one parallel load). (c) In an 8-bit parallel register it takes one pulse. (d) A serial adder for two 16-bit numbers takes 16 clock pulses and uses 1 full adder, 1 carry flip-flop, and the two shift registers.
EX 4Universal shift register selections
MediumFor : hold () keeps 1101. Shift left (, each stage takes its lower neighbour) with serial input 0 enters and gives 1010. Shift right (, each stage takes its upper neighbour) with serial input 1 enters and gives 1110. Parallel load () copies the parallel input, for example 0110. The script checks these four cases.
EX 5Multiplying and dividing by shifting
GATE level(a) The unsigned value 13 (00001101) shifted left twice is 00110100 = 52 = (no bit was lost). (b) The unsigned value 182 (10110110) shifted left once loses the top bit, giving 108, not 364. (c) The signed value shifted arithmetically right gives , and gives , rounding down. (d) A logical shift right of the signed value (10110110) would give 01011011 = 91, which is wrong for a signed number.
EX 6Flip-flops and multiplexers needed
GATE levelA 4-bit universal shift register needs 4 D flip-flops and 4 4:1 multiplexers (each multiplexer has 4 data inputs and 2 select lines shared by all four). A 16-bit register with a load control needs 16 flip-flops and 16 2:1 multiplexers. If instead the load is done by gating the clock, the multiplexers are replaced by a clock gate, but then the clock to different registers is delayed differently (clock skew), which is why synchronous designs prefer the multiplexer.
Cheat box
Cheat box
- Register = D flip-flops, common clock. Load control: (a 2:1 multiplexer per bit).
- Shift register: (shift toward the MSB). Data moves one stage per pulse; pulses to fill or empty.
- SISO, SIPO (serial to parallel), PISO (parallel to serial), PIPO. First in, first out.
- Universal shift register: 4:1 multiplexer per stage (hold, shift right, shift left, load).
- Left shift = (unsigned, if no carry out). Logical right shift = (unsigned). Arithmetic right shift = (signed). rotations restore the value.
- Serial adder: 1 full adder, 1 carry flip-flop, pulses, least significant bit first.
- Ring counter and Johnson counter are shift registers with feedback (see counters).
Traps and GATE patterns
Connections
Builds on
Across subjects
A shift register with feedback is a counter (ring and Johnson). Each stage of a universal shift register is a multiplexer in front of a flip-flop. A serial adder is the full adder of adders and subtractors used once per bit. The shift microoperations of the processor rely on signed number representation, and the registers in the datapath are the state elements of the instruction cycle.
PYQs
4 previous year questions from your book. I re-solved each one myself (4 by running or simulating, 0 by reasoning only); the book's key is shown next to my answer. All PYQs
Consider the given sequential circuit designed using D-Flip-flops. The circuit is initialized with some value (initial state). The number of distinct states the circuit will go through before returning to the initial state is . (Answer in integer)
Consider the sequential circuit shown in the figure, where both flip-flops used are positive edge-triggered D flip-flops. The number of states in the state transition diagram of this circuit that have a transition back to the same state on some value of "in" is ______
What is the final value stored in the linear feedback shift register if the input is 1011101?
- (a)0110
- (b)1011
- (c)1101
- (d)1111
Consider the circuit in the diagram. The operator represents Ex-OR. The D flip-flops are initialized to zeroes (cleared) The following data: is supplied to the "data" terminal in nine clock cycles. After that the values of q2q1qo are:
- (a)000
- (b)001
- (c)010
- (d)101
Self-check
Question 1
A 4-bit register holds 0110. After one logical shift left and then one rotate right, what does it hold?
Show answerHide
Logical shift left: 1100. Rotate right: the bottom bit (0) re-enters at the top: 0110. The register returns to 0110.
Question 2
How many clock pulses does it take to move a 12-bit word from one 12-bit shift register to another through a single serial wire?
Show answerHide
12 pulses (one bit per pulse).
Question 3
What does an arithmetic shift right do to the 8-bit value 11110000?
Show answerHide
It copies the sign bit: 11111000. As signed numbers, .
Question 4
How many flip-flops and how many 4:1 multiplexers are in an 8-bit universal shift register?
Show answerHide
8 flip-flops and 8 multiplexers.
Revision card
One-screen revision
- Register: D flip-flops, loaded together; hold via .
- Shift register: each stage copies its neighbour at the clock edge; one place per pulse; SISO, SIPO, PISO, PIPO.
- Universal: 4:1 multiplexer per stage (hold, right, left, load).
- Left shift doubles, logical right shift halves (unsigned), arithmetic right shift halves signed (rounds down), rotate is circular.
- Serial adder: one full adder + carry flip-flop, pulses.
References
- ·Mano and Ciletti, Digital Design, 5th ed., Chapter 6 Registers and Counters (registers, shift registers, serial addition, universal shift register)
- ·Morris Mano, Computer System Architecture, Register transfer and microoperations (shift microoperations)
Verification
The shift-register waveform is a simulation (scripts/gen-dl-seq-traces.py) re-simulated independently in tests/dl-seq-traces.test.ts; the shift and rotate results are computed exactly (scripts/gen-dl-traces.py) and decoded again in tests/dl-traces.test.ts. The arithmetic meaning of shifts, serial transfer, the serial adder for all 4-bit and 5-bit operands, the universal shift register selections and the load-control equation are checked in scripts/enum-checks/dl_seq.py. The C program is compiled and run by npm run verify:c. Textbook chapter titles are from memory; the independent second pass has not been run, so the page stays draft. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (conversions, signed ranges and flags, IEEE 754 fields and custom formats, Boolean identities and counts, K-map groups, adder carries, BCD correction, flip-flop conversions, counter sequences and T equations, state reduction, Quine-McCluskey rounds and covers, floating-point alignment and rounding); long C programs were not re-read line by line (they are compiled and compared by npm run verify:c, and their printed outputs were checked against the prose); tables and animations are machine output and were read, not re-run; The description of the inputs of the 4:1 multiplexer of the universal shift register called them 'right' and 'left' neighbour in a way that contradicted the worked example; it now says upper neighbour (shift right) and lower neighbour (shift left). Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)