Skip to content
Tutorials Center
My learning

Topics

Lesson 34 of 57 ยท Registers and Counters

Registers and Shift Registers

Learn parallel registers, the four shift register types, universal shift registers, and ring and Johnson counters, with Python models of serial transfers.

One flip-flop stores one bit. Almost nothing useful fits in one bit, so flip-flops are grouped. A group of flip-flops that share a clock and store a multi-bit value is a register. If you also wire each flip-flop's output to its neighbour's input, the stored bits move one place on every clock edge, and the register becomes a shift register. Shift registers are the tool that converts between parallel data (many wires at once) and serial data (one wire, one bit after another), and they appear in everything from keyboards and sensors to USB and SPI links.

This lesson covers the plain parallel register, the four shift register arrangements (SISO, SIPO, PISO, PIPO), the universal shift register that does it all, and two famous circuits made by feeding a shift register back on itself: the ring counter and the Johnson counter.

The parallel register

An n-bit register is n D flip-flops with a common clock. At each active edge every flip-flop copies its D input, so the whole word is captured at once. To hold a value for many cycles, you add a load enable: a 2:1 multiplexer in front of each D chooses between the new data (load = 1) and the flip-flop's own Q (load = 0).

TEXT
D3 D2 D1 D0 โ”€โ”€โ–บ [FF3][FF2][FF1][FF0] โ”€โ”€โ–บ Q3 Q2 Q1 Q0     (all share CLK and LOAD)

Registers hold data between steps of a computation: a program counter, the accumulator of a calculator, the operands of an ALU. The register file in a processor is a bank of registers with address logic.

Shift registers

In a shift register, flip-flop i takes its D input from flip-flop i-1. Only the first flip-flop receives new data from outside, through a serial input. On each clock edge the bits step one place along the chain, and the bit at the end falls out through the serial output.

The four classic types are named by how data enters and leaves:

Four ways to shift

SISO Serial in, serial out. A delay line.
SIPO Serial in, parallel out. Collects bits into a word.
PISO Parallel in, serial out. Sends a word bit by bit.
PIPO Parallel in, parallel out. A plain register.

SIPO and PISO are the pair behind serial communication.

1 / 2
  • SISO delays a stream of bits by n clock cycles, where n is the number of stages.
  • SIPO collects a serial stream into an n-bit word. After n clocks, all n flip-flop outputs are read at once.
  • PISO loads a whole word in one clock (with a load/shift control that switches the D multiplexers) and then shifts it out one bit at a time.
  • PIPO loads and reads all bits in parallel. With no shifting at all, it is the ordinary register.

Let us model a register and a serial-in shift register, and collect a word from a serial wire. We store a register as a list with the most significant bit (MSB) on the left. A right shift moves everything one position to the right and brings the serial input in at the left.

Python A register and a SIPO shift register

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The bit sent first travels furthest: after four clocks it sits in the rightmost flip-flop. Sending the least significant bit first therefore puts every bit exactly where it belongs, and the receiver sees the value 1011 = 11 on its parallel outputs.

Put a PISO on one side and a SIPO on the other, connect them with a single wire and a shared clock, and you have the skeleton of every serial interface. The sender loads a byte and shifts it out; the receiver shifts the bits in. Eight clock cycles move one byte across a single wire.

Python Sending bytes over one wire

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that the wire carries each byte least-significant bit first, exactly as in the SIPO example, and the receiver rebuilds the same byte. The SISO block shows the other use of shift registers: a pure delay. The input pattern 1011 comes out four clock cycles later.

Real serial links add a few things this model skips: a way to tell where a byte starts (start bits, chip-select or framing), a clock that travels along or is recovered from the data, and often error checking such as the parity bit from an earlier lesson.

The universal shift register

A universal shift register supports every operation in one chip. Two mode-select lines S1 S0 control a 4:1 multiplexer in front of each flip-flop's D input:

S1 S0 Operation D of flip-flop i comes from
00 Hold its own Q
01 Shift right the Q of its left neighbour (serial-right input for the first)
10 Shift left the Q of its right neighbour (serial-left input for the last)
11 Parallel load its parallel input

Shifting a binary number left by one place doubles it, and shifting right halves it (dropping the remainder). A universal shift register is therefore also a cheap multiplier and divider by powers of two.

Python A 4-bit universal shift register

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Loading 0011 (3) and shifting left twice gives 1100 (12): two doublings, 3 โ†’ 6 โ†’ 12. Shifting right halves the value again, giving 6. Loading 1000 and shifting right with a 1 entering from the left gives 1100, which is how an arithmetic right shift keeps the sign of a two's complement number, as in the signed numbers lesson.

Ring and Johnson counters

Connect the serial output of a shift register back to its serial input and the bits never leave: they circulate. This is the idea behind two special counters.

A ring counter feeds the last flip-flop's output straight into the first. If it starts with a single 1 (1000), that 1 travels around the ring and the register passes through N distinct states, one per clock. The states are one-hot: exactly one output is high at any time. That gives you N timing signals without any decoder, which is why ring counters are used for sequencing steps in a controller.

A Johnson counter (twisted-ring counter) feeds the inverted last output into the first flip-flop. The register fills up with 1s from one end and then empties again with 0s, giving 2N states from N flip-flops. Each state can be recognised by looking at just two adjacent outputs, so decoding needs only a 2-input gate per state, and because only one bit changes between consecutive states, the decoded outputs are free of glitches.

Python Ring and Johnson counter sequences

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The ring counter has 4 states and the Johnson counter has 8, with the same number of flip-flops. A binary counter with 4 flip-flops reaches 16 states, so ring and Johnson counters trade density for simplicity: no adder-like carry logic, no glitches, trivial decoding.

The last lines point out a weakness. A ring counter must be initialised: if it ever starts (or lands, because of noise) in a state with two 1s, it keeps circulating that bad pattern forever. Practical designs force a good state at power-up or add feedback logic that makes the counter self-correcting. A Johnson counter has the same issue, with unused states that form their own loops. The next lesson shows how binary counters get the most states out of a given number of flip-flops.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which shift register type is used to turn a serial bit stream into a parallel word?

    SIPO means serial in, parallel out. After n clocks the n bits can be read at once from the flip-flop outputs.
  2. 2. A 6-stage SISO shift register is clocked. How long does it delay a bit?

    The bit moves one stage per clock, so it takes six clocks to travel through six stages.
  3. 3. What are the 4 operations of a universal shift register selected by two mode lines?

    Two select lines choose among four sources for each D input, giving hold, shift right, shift left and parallel load.
  4. 4. How many distinct states does a 5-bit Johnson counter have?

    A Johnson counter has 2N states for N flip-flops, so five flip-flops give 10 states.
  5. 5. How does a ring counter differ from a Johnson counter?

    A ring counter feeds back the last output directly, giving N states. The Johnson counter inverts it, giving 2N states.

Summary

  • A register is a group of flip-flops sharing a clock; a load enable (a 2:1 multiplexer in front of each D) lets it hold a value.
  • In a shift register each flip-flop takes its input from its neighbour, so bits move one place per clock edge.
  • SISO is a delay line, SIPO collects a serial stream into a word, PISO sends a word serially, and PIPO is an ordinary register.
  • A universal shift register adds a 4:1 multiplexer per bit to choose hold, shift right, shift left or load; shifting left doubles a number and shifting right halves it.
  • A ring counter circulates a single 1 for N states; a Johnson counter feeds back the inverted output for 2N states; both need a valid starting state.

Next: Asynchronous and Synchronous Counters.