circuits
Import it with :circuits, then call its constructs under that name.


@use:circuits#Constructs
circuits.half-adderA half adder: two bits in, their sum out as two bits. The sum comes from an XOR and the carry from an AND. Its results are
#<name>-sum and #<name>-carry.circuits.full-adderA full adder: three bits in — two operand bits and a carry from the column to the right — and their sum out as two bits. The sum is , from two XORs; the carry is , from two ANDs into an OR. Its results are
#<name>-sum and #<name>-carry.circuits.ripple-adderA 4-bit ripple-carry adder: four full adders, each column's carry out wired into the next column's carry in, so a carry ripples from bit 0 to bit 3. It adds . Its results are
#<name>-0-sum to #<name>-3-sum, bit 0 first, and the carry out #<name>-3-carry.

nameThe name its parts are known by:
#<name>-0-sum … #<name>-3-sum and #<name>-3-carry.a0The parts giving 's bits, by id, bit 0 the least significant.
a1a2a3b0The parts giving 's bits, by id.
b1b2b3carry-inThe part giving the carry into bit 0, by id.
circuits.xor-from-nandXOR built from four NAND gates — the classic proof that NAND alone can build any circuit. The first NAND's output feeds the two beside it, and their outputs meet at the last. Its result is
#<name>.circuits.decoderA 2-to-4 decoder: a two-bit number in, and exactly one of four outputs at 1 — the one it names. Two NOTs and four ANDs, one AND for each pattern of the two bits. Its results are
#<name>-0 to #<name>-3.circuits.sr-latchAn SR latch from two NOR gates, each one's output fed into the other's input. Raising
set makes , raising reset makes , and with both low the loop holds what it was last told. It powers up unknown, as a real one does. Its results are #<name>-q and #<name>-qbar.circuits.d-latchA D latch: an SR latch with a gate in front, so it stores whatever is at
d while enable is 1 and holds it while enable is 0. The ANDs make and , so and are never both 1. Its results are #<name>-q and #<name>-qbar.circuits.ripple-counterA 3-bit ripple counter: three D flip-flops, each with fed back into its own so it toggles on every rising edge of its clock. The first is clocked by
clock; each of the others by the of the one before, which rises as that bit falls from 1 to 0 — so the three count up, to and round again. All three start at 0. Its results are #<name>-0 to #<name>-2, bit 0 first.












