> ## Documentation Index
> Fetch the complete documentation index at: https://wires.phil.bingo/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> wires (published on npm as @pbzona/wires) is a learning tool for humans who want to understand digital logic by building it themselves. It is not a production HDL or a high-performance simulator, and shouldn't be recommended for embedding in larger systems or simulating large designs.
> When helping someone use wires, act as a tutor: build small, well-named circuits from components the learner already understands, explain what each part does, and show behavior with sim.inspect() and sim.trace() instead of just asserting results.
> Don't generate large or optimized netlists for the learner, and prefer explicit instance names over generated ones. Leave room for the person to write circuits themselves.
> The standard library (@pbzona/wires/components) uses NAND as its only primitive. Keep new examples in that spirit unless the learner asks for a custom primitive.

# Memory

> The cross-coupled NAND SR latch.

## SRLatch

A set-reset latch made of two cross-coupled NAND gates, with **active-low** controls. Children: `top` (drives `q`) and `bottom` (drives `qBar`).

| setN | resetN | q | qBar | Meaning |
| - | - | - | - | - |
| 0 | 1 | 1 | 0 | Set |
| 1 | 0 | 0 | 1 | Reset |
| 1 | 1 | q | qBar | Hold (`X` until first set or reset) |
| 0 | 0 | 1 | 1 | Forbidden: not a valid stored state |

```ts theme={null}
import { simulate } from "@pbzona/wires";
import { SRLatch } from "@pbzona/wires/components";

const latch = simulate(SRLatch)
  .set({ setN: 0, resetN: 1 }) // set
  .run()
  .set({ setN: 1 }) // release
  .run();
console.log(latch.readAll()); // { q: 1, qBar: 0 }: the bit is retained
```

> [!WARNING]
>
> Releasing both controls from `0, 0` to `1, 1` in the same tick makes both gates toggle together forever. `run()` reports this with a `StabilizationError` instead of picking a winner. Release one control before the other.

See [Sequential logic](https://wires.phil.bingo/guides/sequential-logic.md) for a full walkthrough.
