Why This Matters
A single NAND gate has no memory. Tie two NAND gates in a feedback loop and the pair can store one bit until a later input changes it. A 32-bit register is 32 stored bits; a program counter, instruction register, cache valid bit, and pipeline register are all repeated versions of that idea.
A processor does not let every signal update whenever it wants. In synchronous logic, combinational gates compute between clock edges, and flip-flops sample on a clock edge. If the clock period is 1 ns, every path between two flip-flops must finish, including flip-flop delay, gate delay, skew, and setup time, before the next edge.
Core Definitions
Combinational Circuit
A circuit whose outputs are functions only of the present inputs. A full adder, decoder, multiplexer, and NAND-only implementation of a Boolean expression are combinational.
Sequential Circuit
A circuit whose outputs depend on present inputs and stored state. The stored state is usually held in latches or flip-flops. Formally, a finite sequential circuit has next-state logic and output logic or .
Latch
A level-sensitive storage element. When its enable input is active, the stored output can follow the input. When enable is inactive, feedback preserves the previous value.
Flip-Flop
An edge-triggered storage element. A D flip-flop samples its data input at a clock edge and holds that sampled value at until the next active edge.
Setup Time and Hold Time
For a flip-flop, setup time is the time that must be stable before the sampling clock edge. Hold time is the time that must remain stable after the edge.
Feedback Makes a Bit
A NAND gate computes . With no feedback, the output is forgotten when inputs change. With feedback, the output of one gate becomes an input to another, and the circuit can settle into one of two stable states.
The active-low SR latch built from cross-coupled NAND gates is the canonical example. Let the external inputs be and . The bars matter because driving an input low asserts it.
| Next | Next | Meaning | ||
|---|---|---|---|---|
| 1 | 1 | previous | previous | hold |
| 0 | 1 | 1 | 0 | set |
| 1 | 0 | 0 | 1 | reset |
| 0 | 0 | 1 | 1 | forbidden |
One implementation can be written as simultaneous equations:
Worked transition from reset to hold:
| Step | Comment | ||||
|---|---|---|---|---|---|
| 0 | 1 | 0 | 0 | 1 | reset asserted |
| 1 | 1 | 1 | 0 | 1 | release reset |
| 2 | 1 | 1 | 0 | 1 | feedback preserves reset |
The forbidden row is more than just a notation problem. When both inputs are low, both NAND outputs become 1, so and stop being complements. If both inputs then return high at nearly the same time, the final state depends on tiny delay differences. That is a race.
Gated D Latch
An SR latch exposes two controls and has a forbidden input combination. A D latch hides that problem by generating set and reset requests from a single data input and an enable .
For a NAND-based gated D latch, the internal active-low inputs are:
When , both and equal 1, so the latch holds. When , exactly one of the two internal requests is asserted.
| Next | ||||
|---|---|---|---|---|
| 0 | 0 | 1 | 1 | previous |
| 0 | 1 | 1 | 1 | previous |
| 1 | 0 | 1 | 0 | 0 |
| 1 | 1 | 0 | 1 | 1 |
This is level-sensitive. If stays high for 10 ns and changes after 4 ns, then can change after that. The latch is transparent while enabled. That property is useful in latch-based timing, but in the common single-clock model it is harder to reason about than edge-triggered storage.
A compact C model shows the behavior without gate delays:
#include <stdint.h>
typedef struct {
uint8_t q;
} DLatch;
void d_latch_step(DLatch *x, uint8_t enable, uint8_t d) {
if (enable) {
x->q = d & 1; // transparent while enable is high
}
}
For input samples (E,D) = (0,0), (1,1), (1,0), (0,1), starting from q=0, the output sequence is 0,1,0,0. The last input has D=1, but the latch is closed.
Edge-Triggered D Flip-Flop
A rising-edge D flip-flop can be built from two D latches in series. The first latch is the master; the second is the slave. On the usual construction, the master is open when clock is low, and the slave is open when clock is high.
| Clock level | Master latch | Slave latch | External |
|---|---|---|---|
| 0 | transparent | closed | holds old slave value |
| 1 | closed | transparent | copies captured master value |
The input value is captured at the low-to-high transition because the master closes just as the slave opens. After the edge, changes on cannot reach until the next rising edge because the master is closed.
Example timing with sampled integer bits:
| Time ns | Clock | Master | ||
|---|---|---|---|---|
| 0.0 | 0 | 0 | 0 | 0 |
| 2.0 | 0 | 1 | 1 | 0 |
| 5.0 | rising | 1 | closes as 1 | becomes 1 |
| 7.0 | 1 | 0 | 1 | 1 |
| 10.0 | falling | 0 | opens | 1 |
| 12.0 | 0 | 0 | 0 | 1 |
| 15.0 | rising | 0 | closes as 0 | becomes 0 |
A register is an array of flip-flops sharing a clock. A 4-bit register storing decimal 10 has bit vector 1010 if written most-significant bit first. At the physical flip-flop level it is often better to name bits by index:
| Bit index | 3 | 2 | 1 | 0 |
|---|---|---|---|---|
| Stored value | 1 | 0 | 1 | 0 |
This C model updates all bits together, matching edge-triggered behavior:
#include <stdint.h>
typedef struct {
uint8_t q; // only low 4 bits are used
} Reg4;
void reg4_rising_edge(Reg4 *r, uint8_t d) {
r->q = d & 0x0f; // simultaneous 4-bit sample
}
The assignment is a single state update in the model. In hardware, it is four flip-flops receiving the same active clock edge.
Setup, Hold, and Clock Skew
A flip-flop is an analog device under the digital abstraction. Near a clock edge, internal nodes race toward stable voltages. If changes too close to the sampling edge, the flip-flop can enter metastability or capture the wrong Boolean value.
The basic synchronous timing inequality for a path from one flip-flop to the next is:
Here is clock-to-Q delay of the source flip-flop, and is the worst combinational delay on the path.
Numeric example. Suppose ps, ps, ps, clock skew is 40 ps against the path, and margin is 30 ps. Then:
The maximum clock frequency is about GHz.
Hold time is checked near the same edge, not the next one. A common simplified condition is:
If ps, ps, ps, and skew is 10 ps in the bad direction, then . The receiving flip-flop might see new data too soon. The fix is not to slow the clock; the fix is to add minimum delay on that short path or change clock distribution.
Synchronous Design Discipline
The standard single-clock discipline is simple. State lives only in flip-flops. All flip-flops use the same active clock edge. Between clock edges, combinational logic computes the next state and outputs.
A synchronous circuit with state register and input follows:
Or, for Moore output logic:
One global edge makes the mental model discrete. At cycle , all registers contain old state. After the rising edge, all registers contain the sampled next state. The combinational cloud may glitch between edges, but those glitches do not matter if timing constraints are met and only registered values are sampled.
Worked Examples
A 3-bit binary up-counter uses three flip-flops storing . Its next-state function is modulo 8.
| Cycle | Decimal | |
|---|---|---|
| 0 | 000 | 0 |
| 1 | 001 | 1 |
| 2 | 010 | 2 |
| 3 | 011 | 3 |
| 4 | 100 | 4 |
| 5 | 101 | 5 |
| 6 | 110 | 6 |
| 7 | 111 | 7 |
| 8 | 000 | 0 |
Bit equations for a synchronous incrementer are:
A shift register stores a vector and shifts it one position per edge. For a 4-bit right shift with serial input in, define new bits as:
| New bit | Source |
|---|---|
in | |
Start with Q3 Q2 Q1 Q0 = 1011. Feed serial inputs 0, 1, 1.
| Edge | Serial input | New register |
|---|---|---|
| 0 | none | 1011 |
| 1 | 0 | 0101 |
| 2 | 1 | 1010 |
| 3 | 1 | 1101 |
The byte-level analogy is exact if the register is packed into a low nibble:
#include <stdint.h>
uint8_t shift4_right(uint8_t q, uint8_t serial_in) {
q &= 0x0f;
return (uint8_t)(((serial_in & 1) << 3) | (q >> 1));
}
/* 0b1011 -> in 0 gives 0b0101
0b0101 -> in 1 gives 0b1010
0b1010 -> in 1 gives 0b1101 */
Finite-State Machines
A finite-state machine adds meaning to the stored bits. The state register holds an encoded state, and combinational logic computes the next encoded state.
A Moore machine output depends only on state. A Mealy machine output depends on state and input. For a serial detector that emits 1 when the suffix 101 has just been seen, a Mealy machine can assert output on the same cycle as the last input bit.
Use states named by the longest matched suffix:
| State | Meaning |
|---|---|
| A | no useful suffix |
| B | suffix 1 |
| C | suffix 10 |
Transition and output table for Mealy detection of 101:
| State | Input | Next state | Output |
|---|---|---|---|
| A | 0 | A | 0 |
| A | 1 | B | 0 |
| B | 0 | C | 0 |
| B | 1 | B | 0 |
| C | 0 | A | 0 |
| C | 1 | B | 1 |
State assignment maps symbolic states to bits. With two flip-flops, choose A=00, B=01, C=10, leaving 11 unused. The next-state table becomes:
| Input | Output | ||
|---|---|---|---|
| 00 | 0 | 00 | 0 |
| 00 | 1 | 01 | 0 |
| 01 | 0 | 10 | 0 |
| 01 | 1 | 01 | 0 |
| 10 | 0 | 00 | 0 |
| 10 | 1 | 01 | 1 |
| 11 | 0 | 00 | 0 |
| 11 | 1 | 00 | 0 |
The unused state rows are specified to return to A. Leaving them unspecified can make simulation and hardware disagree after reset problems or transient faults.
Key Result
The synchronous abstraction is valid when every register-to-register path meets both a maximum-delay and a minimum-delay constraint:
These inequalities are not performance hints. They are the contract that lets a physical network of gates behave like the recurrence .
For the counter above, the recurrence is . The flip-flops do not update one at a time in the abstract model. All three sample their D inputs on the same rising edge. If one flip-flop receives a delayed clock, the counter can skip states because one bit has sampled an input from a different logical cycle.
Common Confusions
Treating an SR latch as if S and R were normal Boolean data inputs
In a NAND SR latch, and is not a stored zero or one. It drives both outputs high. Releasing both inputs then creates a race, so the final bit is not determined by the truth table alone.
Assuming a D latch and D flip-flop have the same timing
A D latch follows while enabled. A D flip-flop samples only at an edge. Replacing flip-flops with latches in a single-clock design can create paths that pass through more than one storage element during the same clock level.
Fixing hold violations by lowering the clock frequency
A hold violation concerns data arriving too soon after the same clock edge. Increasing changes the next-edge spacing, but it does not repair a too-short minimum delay path.
Exercises
Problem
A NAND SR latch starts in the reset state, so and . The input sequence is . List after each input pair settles.
Problem
A path has ps, ps, ps, skew against the path of 30 ps, and margin of 20 ps. What minimum clock period is required, and what is the corresponding maximum frequency?
Problem
Design the next-state table for a 2-bit saturating counter with states 00, 01, 10, 11. Input inc=1 increments unless already at 11. Input inc=0 decrements unless already at 00. Give the table of current state, input, and next state.
References
Canonical:
- Charles Petzold, Code: The Hidden Language of Computer Hardware and Software, 2nd ed. (2022), ch. 10-14, covers relays, feedback, binary addition, and early memory circuits
- David A. Patterson and John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 5th ed. (2014), Appendix B, covers logic design, clocking, latches, flip-flops, and finite-state machines
- J. Clark Scott, But How Do It Know? The Basic Principles of Computers for Everyone (2009), ch. 3-8, builds registers, memory, and control from simple gates
- M. Morris Mano and Michael D. Ciletti, Digital Design, 5th ed. (2013), ch. 5, covers synchronous sequential logic and flip-flop timing
- David Money Harris and Sarah L. Harris, Digital Design and Computer Architecture, 2nd ed. (2012), ch. 3, covers sequential logic, registers, counters, and FSMs
Accessible:
- Noam Nisan and Shimon Schocken, The Elements of Computing Systems, 2nd ed. (2021), ch. 3
- MIT OpenCourseWare, 6.004 Computation Structures, lectures on sequential logic and finite-state machines
- Ben Eater, video series on building an 8-bit computer from logic chips
Next Topics
- /computationpath/combinational-circuits
- /computationpath/registers-and-memory
- /computationpath/finite-state-machines
- /topics/modular-arithmetic