D3D2D1D0INout010101010110MUX10MUX10MUX10MUX01DQFF30101DQFF201DQFF101DQFF001DECODERR00101R11110R20011R31001READ MUXwrite----read----01010101010110
Lit wire with moving dashes: it carries a 1Lamps: a glowing lamp shows 1, a dark one 0; the lamp on a flip-flop is the bit it storesMoving pucks: bits travelling at a clock edgeRegister file: four registers, a write decoder and a read muxFour D flip-flops on one clock make a 4-bit register; at each rising edge every bit is captured together. A mux in front of each flip-flop lets the load signal choose: take the new data (load 1) or feed the old bit back (load 0). Wired Q to next input, the same flip-flops form a shift register; on the right, a register file picks one register to write with a decoder and one to read with a mux. Real parts: Texas Instruments' SN74HC273 contains eight D flip-flops that share one clock and load on its positive edge; the SN74HC595 is an 8-bit serial-in shift register.

Flip-flops in a row

  1. A D flip-flop stores one bit. At each rising clock edge, the moment the clock goes from 0 to 1, it copies its input D to its output Q. A register is a row of them: 4 flip-flops hold 4 bits.

Load or keep

Shift registers

Register files

The bits, edge by edge

;; step 1/10 · a-register
;; about: Data in, Flip-flops, Clock
D flip-flop: 1 bit of memory
  rising clock edge: Q takes D
  any other time:   Q holds

4 flip-flops  → a 4-bit register
8 flip-flops  → an 8-bit register
32 flip-flops → a 32-bit register

here: D = 1011 → at the edge Q = 1011

A register with a load (enable) input puts a 2-input multiplexer in front of each flip-flop: with load 0 the mux feeds Q back to D, so the flip-flop reloads its own value at every edge (Harris and Harris, section 3.2.5; Nand2Tetris chapter 3 builds its Bit chip the same way). In Python, x >> n is floor division by 2 to the power n, so 12 >> 1 is 6 and 7 >> 1 is 3: the bit shifted out is the remainder that gets dropped.