Logic circuits, written down.
A small language for building and simulating logic circuits, made for people learning how computers work.
↓ Download circ-compile for Linux, macOS, or Windows// half_adder.circ
import xor "<builtin>/xor.circ"
input a, b
xor s(a=a, b=b)
and c(a=a, b=b)
output sum(in=s.out)
output carry(in=c.out) Use any text editor, or write in the playground to check your wiring as you type.
Run circ-compile to produce a self-contained WebAssembly module. Use --preview to print a schematic in your terminal.
Set input pins and read outputs from JavaScript. Run the module in a browser, in Node, or in the playground.
Six primitives. Five macros. One import.
A program is a list of declarations: name input pins, place gates, and connect their ports. Combine circuits with imports to build larger ones. If you know the early Nand2Tetris hardware chapters, these building blocks will look familiar.
Source on the left. Schematic on the right.
This half-adder uses XOR for the sum and AND for the carry. Run circ-compile with --preview to print its schematic in your terminal.
Open it in the playground →// half_adder.circ
import xor "<builtin>/xor.circ"
input a, b
xor s(a=a, b=b)
and c(a=a, b=b)
output sum(in=s.out)
output carry(in=c.out) ╭───╮ ╭───╮
│ a ├○●──▶┤ │ ╭───────╮
╰───╯ │ │AND├○───────▶┤ carry │
│╭─▶┤ │ ╰───────╯
╭───╮ ││ ╰───╯
│ b ├○┼╯
╰───╯ ││ ╭───────╮
╰┼─▶┤ │ ╭─────╮
│ │[xor:s]├○───▶┤ sum │
╰─▶┤ │ ╰─────╯
╰───────╯