Skip to content

Demo 6.6: Registers, and Circuits That Walk a Chosen Sequence

The synchronous counter page ended with a description of the circuit that did not mention counting: flip-flops holding a state, combinational logic working out the next one, and a clock stepping between them. A counter is that structure with the simplest possible next-state logic.

So what happens if you take the next-state logic away?

You get a register. Four D flip-flops side by side, one clock wire to all of them, and each D fed from somewhere. There are no gates in it. It performs no computation and does not count, and it is still one of the most widely used circuits in the module.

Each flip-flop has a D input, and something has to be connected to it. That is the only design decision available, and every circuit on this page is a different answer to it:

Where D comes fromWhat the circuit becomes
Its own input pinA storage register. It remembers a word.
Its own QA register that holds. This is what a load enable does.
The Q of the stage before itA shift register. The word moves along, one stage per clock.
The Q of the last stageA ring counter. The word circulates indefinitely.
The Q̄ of the last stageA Johnson counter. Twice as many states, one inverter.

Same four flip-flops in every row. Same single clock. One wire moved.

Keep this in mind, because the four circuits are usually taught separately with four separate diagrams, which hides the fact that they are the same hardware with a different source for D.

The purpose of a storage register is clear: you have a value and you want to keep it.

The shift register takes more explaining, and the explanation is about the number of wires rather than about registers.

Sending an eight-bit value from one chip to another needs eight wires, and the cost of wires is easy to underestimate. Eight pins on the package at each end. Eight tracks on the board. Eight conductors in the cable, and a connector wide enough for them. Widen the value to sixteen bits and all of those costs double.

Or send it on one wire, one bit at a time, and take eight clocks over it. The pin count no longer depends on the width.

A shift register is the converter between those two, and it converts in whichever direction you read it. That is the trade the third tab is about, and it is the reason this circuit is in every serial link, every serial port, and every part that drives more outputs than the processor has free pins.

Holding a word is the storage register. Set the four data inputs, then clock. The point of the tab is the difference between the inputs and the outputs: the outputs only take on the input values at an edge, and that is the reason a register exists.

Shifting it along moves one wire and runs the same four flip-flops as a shift register. There is a serial pattern you can edit a bit at a time, and the waveforms underneath show every output as the one above it delayed by one clock.

Serial and parallel puts numbers on the trade. Pick a width and a shift clock and read the two panels against each other, then the four in/out arrangements and what each one is for.

Walking a sequence feeds the output back to the input. The register then steps through a fixed loop of states, and the tab ends with all sixteen states laid out so you can see the loops that were not designed.

Registers, and Circuits That Walk a Chosen Sequence

Four flip-flops, one clock, and one wire moved: a word held, a word walked along, wires traded against time, and a sequence somebody chose.

A register is a row of flip-flops that share a clock and do no arithmetic whatsoever.

  • Every circuit in this half of the module so far has computed something. This one does not: it remembers.
  • Four D flip-flops side by side, one clock wire to all of them, and each D fed from its own input pin. That is the whole circuit.
  • The clock is not a timekeeper here. It is an instruction, and the instruction is "remember what is on the inputs, now".
  • Between clocks the inputs can do whatever they like and the outputs will not care, which is exactly what makes the thing useful.
  • Everything else on this page is the same four flip-flops with one wire moved.
The data inputs, D0 to D3

Click to change them. Nothing happens to the outputs until you clock.

The load enable
Try one of these
On the inputs
1011
Stored in the register
0000
they agreeno
load enable1
CLKone clock, every stage, the same instantDQ00FF0DQDQ10FF1DQDQ20FF2DQDQ30FF3DQ1D00D11D21D3each D from its own pin: this is a storage register
The inputs and the outputs disagree, and that is fine
  • The inputs are showing 1011 and the register is holding 0000.
  • Neither of those is wrong. The inputs are what is being offered and the outputs are what was accepted, and they are only ever forced to agree at a clock edge.
  • That gap is the entire reason a register exists. Whatever is producing the data can change it whenever it likes, and the register goes on presenting the last value it was told to keep.
  • Press "Clock once" and the two will match until you change the inputs again.
Why the enable is not a switch on the clock
  • The obvious way to stop a register loading is to stop the clock reaching it, and it is the wrong way.
  • A gated clock arrives late, because it has been through a gate, so that register is no longer in step with the rest of the system.
  • Worse, a gate whose inputs change at the wrong moment can emit a narrow spike, and a flip-flop cannot tell a spike from an edge.
  • So the clock is left alone and the data path is switched instead: a multiplexer on each D choosing between the input pin and the stage’s own Q.
  • Every arrangement on the other three tabs is that same multiplexer with more inputs on it.
What the word actually means
  • A register is any small, fast store built from flip-flops and read or written as a unit.
  • The registers inside a processor are exactly this: a handful of them, a few tens of bits wide, holding the values an instruction is about to work on.
  • Width is a design decision rather than a fact of nature. Four here, eight in a 74HC595, sixty-four in a modern processor.
  • The clock that loads them is the same clock that steps everything else, which is what keeps a synchronous system coherent.
  • This is the smallest interesting example of one, and the counters were the second smallest.

Step 1: Compare the inputs and the stored value

Section titled “Step 1: Compare the inputs and the stored value”

Open Holding a word. The inputs show 1011 and the register is holding 0000.

Both are correct. The inputs are the value presented; the outputs are the value stored. A register keeps those two separate.

Press Clock once and they match. Now change any input bit and watch the outputs: they do not change. Change another, with the same result.

The source of that data can change it at any time, and the register outputs the last value it loaded until the next edge. Every clocked system is built on that property.

Set the enable to Disabled and press the clock. Nothing happens, which is what you would expect.

Now look at how nothing happened. The clock still arrived at every flip-flop and every flip-flop was still triggered by it. What changed is where each D came from: with the load disabled, each D is fed from its own Q, so each stage reloads the value it already had.

From outside this looks like doing nothing, but every stage is still clocked and still loads a value.

Open Shifting it along.

Each D has come off its own pin and gone to the Q of the stage before it. Nothing else about the circuit has changed: same flip-flops and the same single clock.

Press Step one clock four times and watch the pattern shift in from the left, one stage per clock. After four clocks a word that arrived one bit at a time is present across the four outputs, side by side.

That is the conversion: a value spread out in time has become a value spread out across the outputs.

Now read those outputs carefully, because there is a trap in them. The serial input sent 1, 0, 1, 1 in that order, and the outputs read 1101 from Q₀ to Q₃. Those are not the same string, and nothing has gone wrong: the first bit sent has had four clocks to travel and is now in the last stage.

Which end you call the first bit is a convention rather than a fact, and it is one that both ends of a serial link have to agree on before anything works at all. Send the least significant bit first and you read the register one way round; send the most significant first and you read it the other.

Keep stepping and the word shifts out of the far end.

Step 4: Ask why the data does not pass through in one clock

Section titled “Step 4: Ask why the data does not pass through in one clock”

This is an important question, and most students do not think to ask it.

Every stage is clocked at the same instant. Every stage’s D input is connected to the output of the stage before it. So when the edge arrives, what stops a 1 at the input travelling the whole length of the register in one go?

The answer is that a flip-flop looks at its D input at the edge, not after it. Every stage captures the value its neighbour output just before the edge, not the value it is about to change to. All four pass their contents on simultaneously, and each receives what its neighbour was holding.

That only works because outputs take a little time to change. The data has to remain stable for a short time after the edge, which is the hold time, and here it is met by the flip-flop’s own propagation delay.

A shift register is therefore the circuit that hold time exists for. If you have wondered why that number is on a data sheet, this is the answer.

Open Serial and parallel and set the width to 8 bits at 1 MHz.

  • Parallel: 8 wires, one clock, 1.00 µs.
  • Serial: 2 wires, eight clocks, 8.00 µs.

Now step the width up to 32 bits. The parallel wire count goes to 32. The serial wire count does not change.

That is the advantage of serial transfer. The serial cost in wires is independent of the width, and the penalty is time, which is usually available. Very little in an embedded system needs a value inside a microsecond.

The penalty matters for anything that must be fast and wide at once, which is why the memory bus inside a computer is still parallel and the cable to the printer is not.

Open Walking a sequence.

The serial input has come off its pin and gone to the last stage’s output. Nothing now enters the register and nothing leaves it. Whatever pattern is inside circulates, one place per clock, for as long as the clock runs.

Start it from One bit set and press play. The pattern is 1000, 0100, 0010, 0001, and back to the beginning.

Look at that sequence and try to find the arithmetic in it. There is none. It is not counting up or down, and the four states are not consecutive binary values. The designer chose that order and wired the feedback to produce it.

This is the first circuit in the module whose behaviour is a design decision rather than a consequence of arithmetic, and that is why it is here.

Then switch to Johnson and see what one inverter adds: eight states from the same four flip-flops instead of four, because the pattern fills with ones from the left and then empties from the left.

Still on the last tab, press Two bits set.

The register now cycles through 1010, 0101, 1010, 0101, indefinitely. Two states, not four, and no clock edge will move it out of this loop.

Be precise about what has gone wrong here: the circuit is not broken. No component has failed, nothing is out of specification, and the feedback is doing what it was built to do. The design did not specify what should happen from this state.

Now look at the panel at the bottom of the tab, which steps through all sixteen states and shows every loop the wiring produces.

LoopStatesIs it the design?
1000 → 0100 → 0010 → 00014Yes
1100 → 0110 → 0011 → 10014No
1110 → 0111 → 1011 → 11014No
1010 → 01012No
00001No
11111No

Six separate loops, and no way between them. A four-bit ring counter has sixteen states, of which the design uses four and leaves the other twelve unspecified, and a circuit that has powered up into one of them will stay there until the power is removed.

Try All zeros as well. With no bits set there is nothing to circulate, so the counter outputs zeros indefinitely, which is the most likely failure for a real ring counter.

Switch to Johnson and the result is different but has the same problem: sixteen states split into two loops of eight. The parasitic loop is the same length as the intended one, so a Johnson counter in the wrong loop looks correct on a scope. It is producing the wrong phases.

Quiz
Select 0/1

A four-bit storage register is holding 0110. Its data inputs are changed to 1011 and no clock edge occurs. What do the outputs show?

Quiz
Select 0/1

In a shift register, every stage is clocked at the same instant and every stage's D input is connected to the output of the stage before it. What stops a bit travelling the whole length of the register on one edge?

Quiz
Select 0/1

A four-bit ring counter is switched on and comes up holding 1010. What happens?

Concept Match

Match each item to what it is

Quiz
Select 0/4

Which statements about shift registers and ring counters are true? Select all that apply.

Five things to take away.

  1. A register is flip-flops with no logic between them. It computes nothing. The clock edge acts as the instruction “store what is on the inputs, now”.
  2. Every circuit here is the same hardware with one wire moved. Where D comes from is the only decision, and it turns the same four flip-flops into a store, a shifter, a delay line or a counter.
  3. A shift register converts between time and wires. Bits arriving one at a time leave as a word, and a word leaves one bit at a time. The serial cost in wires does not depend on the width.
  4. Hold time is why it works. Each stage captures what its neighbour was showing just before the edge, so the contents advance exactly one place per clock instead of passing through the whole register.
  5. Feed the output back and the sequence becomes a choice. A ring counter steps through four states because the designer chose them, and the twelve states it leaves undefined are still there.

That last point is the main one of this demonstration.

Every sequential circuit in the module so far has done something arithmetic. A counter’s sequence follows from addition; the AND chain in the synchronous counter is the carry chain from binary arithmetic. The ring counter is the first circuit whose sequence was specified rather than derived, and the moment a sequence can be specified, two new questions follow: what should the next state be from every state, including the ones you did not plan to visit, and what logic produces that?

Those two questions are the whole of finite state machine design, and you already have the tools for both. A state table says what follows what. Karnaugh maps turn a state table into gates. Flip-flops hold the state and a clock steps between them, as they have done since the latch.

A counter is that construction with the simplest possible sequence. A ring counter is that construction with a chosen sequence. What comes next is that construction with a sequence chosen to do a job, and inputs that change which way it goes, which is what a processor is made of.