G27
Self-checkedTier 1 12 min readdl.registers-shift

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. nn D flip-flops with a common clock. Loading a word means putting it on the DD 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 LL: each stage has a 2:1 multiplexer Di=L Ii+L′ QiD_i = L\,I_i + L'\,Q_i (new data when L=1L = 1, own output when L=0L = 0). An nn-bit loadable register is nn flip-flops and nn 2:1 multiplexers.

Shift register. A register whose stages are connected in a chain: each stage's DD input is the previous stage's QQ. 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 Qi←Qi−1Q_i \leftarrow Q_{i-1} and the serial input enters Q0Q_0 (as in the animation below), and shift right means Qi←Qi+1Q_i \leftarrow Q_{i+1}.

Types by how data enters and leaves:

TypeInOut
SISOserialserial
SIPOserialparallel (all QQ at once)
PISOparallel (load)serial
PIPOparallelparallel (an ordinary register)

SIPO converts serial data to parallel in nn clock pulses; PISO converts parallel data to serial in nn pulses. A word shifted in serially emerges in the same order after nn 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 S1S0S_1 S_0. Each stage has a 4:1 multiplexer in front of its flip-flop: input 0 is the stage's own QQ (hold), input 1 is the upper neighbour Qi+1Q_{i+1} (shift right), input 2 is the lower neighbour Qi−1Q_{i-1} (shift left), input 3 is the parallel input. An nn-bit universal shift register is nn flip-flops and nn 4:1 multiplexers.

Shifts as arithmetic. For an nn-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 (⌊x/2⌋\lfloor x / 2 \rfloor).
  • Arithmetic shift right: the sign bit is copied back into the top. For a 2's complement number this is ⌊x/2⌋\lfloor x / 2 \rfloor, rounding toward minus infinity (so −74→−37-74 \to -37 and −5→−3-5 \to -3).
  • 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. nn 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 nn pulses and one full adder, against one step and nn 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 Q0Q_0), so the first bit entered ends up in Q3Q_3 after four pulses.

4-bit shift register: serial in 1, 0, 1, 1: Start

Simulated, not typed
CLKSIQ0Q1Q2Q3Q3Q2Q1Q00000000100100101101101101100t = 0

Dashed 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.

1 / 6
computed by script: discrete-time simulation of the circuit (gate-level unit delays for latches, ideal edges for flip-flops). python3 scripts/gen-dl-seq-traces.py

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 typed

Working

register = 1011 0110

Value, format and bits (changed bits in amber)

register, read as unsignedunsigned= 182
10110110
same bits, read as 2's complementtwos-complement= -74
10110110

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.

1 / 6
computed by script: exact integer, Fraction and truth-table evaluation (IEEE 754 patterns via Python struct where used), not typed by hand. Python 3.15.1, darwin arm64. python3 scripts/gen-dl-traces.py

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 pairs

The 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: −74-74 becomes −37-37. 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

Easy

A 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 Q3Q_3. After the first pulse Q3Q2Q1Q0=0001Q_3Q_2Q_1Q_0 = 0001, 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 Q3Q_3 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

Medium

For Q3Q2Q1Q0=1101Q_3Q_2Q_1Q_0 = 1101: hold (S1S0=00S_1S_0 = 00) keeps 1101. Shift left (1010, each stage takes its lower neighbour) with serial input 0 enters Q0Q_0 and gives 1010. Shift right (0101, each stage takes its upper neighbour) with serial input 1 enters Q3Q_3 and gives 1110. Parallel load (1111) 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 = 13×413 \times 4 (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 −74-74 shifted arithmetically right gives −37-37, and −5-5 gives −3-3, rounding down. (d) A logical shift right of the signed value −74-74 (10110110) would give 01011011 = 91, which is wrong for a signed number.

EX 6Flip-flops and multiplexers needed

GATE level

A 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 = nn D flip-flops, common clock. Load control: Di=LIi+L′QiD_i = L I_i + L' Q_i (a 2:1 multiplexer per bit).
  • Shift register: Di=Qi−1D_i = Q_{i-1} (shift toward the MSB). Data moves one stage per pulse; nn 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 = ×2\times 2 (unsigned, if no carry out). Logical right shift = ⌊x/2⌋\lfloor x/2 \rfloor (unsigned). Arithmetic right shift = ⌊x/2⌋\lfloor x/2 \rfloor (signed). nn rotations restore the value.
  • Serial adder: 1 full adder, 1 carry flip-flop, nn pulses, least significant bit first.
  • Ring counter and Johnson counter are shift registers with feedback (see counters).

Traps and GATE patterns

Connections

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

GATE 2025 · Set 1 · NAT · 2 marksQ2 · page 184 of the book
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)
GATE 2018 · NAT · 1 markQ8 · page 185 of the book
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 ______
GATE 2007 · MCQ · 1 markQ19 · page 187 of the book
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
GATE 2006 · MCQ · 1 markQ22 · page 188 of the book
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 answer

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 answer

12 pulses (one bit per pulse).

Question 3

What does an arithmetic shift right do to the 8-bit value 11110000?

Show answer

It copies the sign bit: 11111000. As signed numbers, −16→−8-16 \to -8.

Question 4

How many flip-flops and how many 4:1 multiplexers are in an 8-bit universal shift register?

Show answer

8 flip-flops and 8 multiplexers.

Revision card

One-screen revision

  • Register: nn D flip-flops, loaded together; hold via D=LI+L′QD = L I + L'Q.
  • 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, nn 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