DFF

Inputs

PinTypeDescription
DbitData input — the bit to store
ClockbitClock signal — write on 0→1 edge

Outputs

PinTypeDescription
QbitStored value (output)

How It Works

Think of a camera flash: until you press the shutter, the scene can change however it likes, but the photo captures exactly one frame. A D flip-flop works the same way: between flashes it simply keeps the last snapshot of the D input on its Q output. This is memory in its purest form — gates and wires remember nothing, a DFF does.

The key property: the value of D is captured strictly at the clock edge — the moment Clock rises from 0 to 1. Whatever happens on D between edges is ignored. Suppose D = 1 at tick one — after the edge Q = 1; at tick two D = 0 — after the edge Q = 0; at tick three D flips to 1 after the edge — Q stays 0 until the next tick.

A nuance: inside the DFF, four NAND gates form a pair of latches in a master-slave arrangement. While one latch accepts data, the other is closed, so races are impossible: there is no transparent pass-through, and exactly the value that was on D at the instant of the edge gets stored.

Examples (clock sequence)

Tick (Clock edge)D at the edgeQ after the edge
111 — the one is stored
200 — the zero is stored
31 (changed after the edge)0 — the old value is kept
411 — the new one is stored

Note tick 3: a change on D after the edge does not affect the output — the edge has already passed.

Usage

Level 11 is the first meeting with memory. Every clocked part of the computer is built from D flip-flops: eight DFFs sharing one Clock form an 8-bit register (level 12), and flip-flops also live inside the program counter and the index register. The insight this level gives you: one DFF = one bit of memory.

A concrete use is a "one-tick delay" and flag storage: feed the result of a comparison into D, and Q will hold it steadily until the next tick, no matter how the input wiggles. This is how the processor remembers the zero bit, and how control circuits decide whether to take a jump.

Build it yourself →

Related components

Related articles

Frequently Asked Questions

How does a DFF differ from a latch?

A latch responds to a signal level, a DFF to a clock edge: the value is captured at the moment Clock rises from 0 to 1.

What does a DFF store between ticks?

The last written value — one bit of memory, updated only on the rising edge of Clock.

What happens if Clock is held at 1 forever?

Nothing: no more edges occur, and Q keeps the last stored value indefinitely. A new write happens only after a falling edge and the next rising edge.

Why is a DFF called "one bit of memory"?

Because it stores exactly one bit until the next clock edge. Eight such flip-flops wired in parallel give you one byte — a register.