Eight words of RAM, from NAND gates and tri-state buffers

Eight addressable bits. The board arrives reading itself out: a counter walks the address 0 through 7, the S2/S1/S0 lamps show which word is in play, and DOUT reports what that word holds — so the first thing you see is the memory’s own power-up contents scrolling past, one bit per clock.

Raise PICK to take the address off the counter and onto the A2/A1/A0 switches. Then put a value on DIN, raise WE, and the next clock pulse stores it; drop WE and DOUT shows whatever that word now holds. The memory itself is 85 NAND gates; the counter and the three multiplexers that hand the address back and forth bring the whole board to 145.

Open fullscreen

How addressing actually works

Memory is not a lookup table in hardware; it is a fan-out problem. Three things have to happen at once.

Selection. A2 picks which of two four-word banks is in play. Inside each bank, a DECODE-2 turns the two low address bits into four one-hot lines, so exactly one cell is selected and the other three are not.

Writing. The write pulse is gated twice: once with WE, so nothing is stored unless you ask, and once with the clock, so storing is confined to half of each cycle rather than happening continuously. The result drives the enable of one D-LATCH — and only one, because the decoder guarantees it.

Note what that gate is not. A D-LATCH is level-sensitive: it stays transparent for the entire clock-high phase, so the cell tracks DIN the whole time the clock is up and freezes whatever DIN happened to be when the clock falls. Change DIN twice during one high phase and the second value is what sticks. Level-sensitive cells like this are what most static memory uses, though a real SRAM bit is six transistors rather than four NANDs behind a buffer. An edge-triggered cell — the D-FLOP this library also ships, two latches in series — samples at the instant of the edge and ignores the rest of the phase. That difference is the single most common source of confusion in sequential logic, and you can watch it here: it is why the accumulator in the fetch datapath is a flop and these memory cells are not.

Reading. This is the interesting half. Four cells share one output wire. They cannot all drive it, so each sits behind a TRI buffer enabled by the same one-hot line that selects it. The selected cell drives the wire; the other three disconnect entirely — not low, but floating.

That is why this simulator has a third pin state. Wire a floating output into a board output and it draws as a dashed grey line: nothing is driving it. A bus is exactly this arrangement, and it is how a processor talks to memory over shared wires without every device shouting at once.

You will not catch DOUT floating on this board, though — RAM-8X1 joins its two banks through a MUX-2, and the decoder inside each bank is strictly one-hot, so something is always driving the pin. Open a RAM-4X1 bank to see the shared wire itself, where three of the four TRI buffers are disconnected at any moment.

Things worth trying


Built out of NAND gates and nothing else. The sandbox, the JSON module format and the rest of the library are described in Digital logic — from NAND to a computer.

logic