Stutr

Parts reference

Every Stutr part: wiring, gates, plexers, arithmetic, memory, input and output. Pins, default width, settings, code name and a working example for each.

How to read this page

There are 59 parts. For each one you see what it does, the word used in code, its input and output pins in order, its default width, its settings, and a small circuit you can paste into the Code tab.

Pins are listed in the order you write them in code. A pin named > is a clock input. "Unlabeled" pins have no name on the canvas. Clocked parts act only on a rising clock edge.

Wiring

Pin (input)

A value you control. Click it with the Poke tool to change it: a 1-bit pin flips between 0 and 1, a wider pin counts up by one and wraps around.

In code
Input (also in)
Inputs
none
Outputs
1 unlabeled
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
Input a = 1;
Input<4> b = 9;
Output led = a;
Output<4> y = b;

Clock

A pin that flips between 0 and 1 by itself while the circuit is running (press Run). Clocked parts act on its rising edge, the moment it goes from 0 to 1. Click it with the Poke tool to step one edge at a time.

In code
Clock (also clk)
Inputs
none
Outputs
1 unlabeled
Clock ck;
Counter<3> c(ck);
Output<3> y = c;

Constant

A fixed number, 0 to 65535, cut down to the part's width.

In code
Constant (also const)
Inputs
none
Outputs
1 unlabeled
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
  • value: Value, default 1
Constant<4> k = 9;
Output<4> y = k;

Power

Always outputs all ones (a 1 on every bit of its width).

In code
Power
Inputs
none
Outputs
1 unlabeled
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
Power p;
Output y = p;

Ground

Always outputs 0.

In code
Ground (also gnd)
Inputs
none
Outputs
1 unlabeled
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
Ground g;
Output y = g;

Probe (output)

Shows the value that reaches it. Use it to read a result. Wide probes show the number in hexadecimal.

In code
Output (also out)
Inputs
1 unlabeled
Outputs
none
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
Input<4> a = 5;
Output<4> y = a;

Splitter

Breaks a multi-bit value into single bits. Bit 0 is the lowest. Refer to a bit with square brackets: sp[0].

In code
Splitter (also split)
Inputs
In
Outputs
one 1-bit output per bit of the width (0 is the lowest)
Default width
4 bits
Settings
  • bits (also written <bits>): data width, 1 to 16, default 4
Input<4> a = 5;
Splitter<4> sp(a);
Output low = sp[0];
Output high = sp[3];

Combiner

The opposite of a splitter: joins single bits into one multi-bit value. Input 0 becomes the lowest bit.

In code
Combiner (also merge)
Inputs
one 1-bit input per bit of the width (0 is the lowest)
Outputs
1 unlabeled
Default width
4 bits
Settings
  • bits (also written <bits>): data width, 1 to 16, default 4
Input a = 1;
Input b = 0;
Input c = 1;
Input d = 1;
Combiner<4> m(a, b, c, d);
Output<4> y = m;

Tunnel

A wireless connection. Tunnels that share the same tag are connected. Wire one of them to a source and the others carry its value, so you can skip long wires.

In code
Tunnel
Inputs
In
Outputs
1 unlabeled
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
  • tag: Tag (same tag = connected)
Input a = 1;
Tunnel t1(a, tag="x");
Tunnel t2(tag="x");
Output y = t2;

Pull resistor

Gives a floating (undriven) wire a definite value. With nothing driving it, it outputs 0 or all ones depending on its setting. Otherwise it passes the input through.

In code
PullResistor (also pull)
Inputs
In
Outputs
1 unlabeled
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
  • to: Pull to (0 or 1), default "1"
Input a = 1;
Input en = 0;
Input nen = 1;
TransmissionGate t(a, en, nen);
PullResistor p(t, to="0");
Output y = p;

Transistor

A switch controlled by its gate G. An n-type passes the source S when G is 1. A p-type passes it when G is 0. When closed off, the output floats.

In code
Transistor (also trans)
Inputs
G, S
Outputs
D
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
  • kind: Type (n or p), default "n"
Input g = 1;
Input s = 1;
Transistor t(g, s, kind="n");
Output y = t;

Transmission gate

Passes A to B when G is 1 and !G is 0. Otherwise B floats.

In code
TransmissionGate (also tgate)
Inputs
A, G, !G
Outputs
B
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
Input a = 1;
Input g = 1;
Input ng = 0;
TransmissionGate t(a, g, ng);
Output y = t;

Bit extender

Makes a value wider. The new top bits are filled with zeros, ones, or a copy of the sign (top) bit.

In code
BitExtender (also ext)
Inputs
In
Outputs
1 unlabeled
Default width
4 bits
Settings
  • bits (also written <bits>): data width, 1 to 16, default 4
  • to: Output bits, default 8
  • fill: Fill (zero one sign), default "zero"
Input<4> a = 9;
BitExtender<4> e(a, to=8, fill="sign");
Output<8> y = e;

Gates

NOT gate

Flips every bit: 1 becomes 0 and 0 becomes 1.

In code
Not
Inputs
1 unlabeled
Outputs
1 unlabeled
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
Input a = 1;
Not n(a);
Output y = n;

Buffer

Passes its input through unchanged. Useful for tidy wiring.

In code
Buffer (also buf)
Inputs
1 unlabeled
Outputs
1 unlabeled
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
Input a = 1;
Buffer b(a);
Output y = b;

AND gate

Outputs 1 only when both inputs are 1. For wider gates it works on each bit separately.

In code
And
Inputs
2 unlabeled
Outputs
1 unlabeled
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
Input a = 1;
Input b = 0;
And g(a, b);
Output y = g;

OR gate

Outputs 1 when at least one input is 1.

In code
Or
Inputs
2 unlabeled
Outputs
1 unlabeled
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
Input a = 1;
Input b = 0;
Or g(a, b);
Output y = g;

NAND gate

AND followed by NOT. Every other gate can be built from NANDs alone.

In code
Nand
Inputs
2 unlabeled
Outputs
1 unlabeled
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
Input a = 1;
Input b = 1;
Nand g(a, b);
Output y = g;

NOR gate

OR followed by NOT.

In code
Nor
Inputs
2 unlabeled
Outputs
1 unlabeled
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
Input a = 0;
Input b = 0;
Nor g(a, b);
Output y = g;

XOR gate

Outputs 1 when the inputs differ.

In code
Xor
Inputs
2 unlabeled
Outputs
1 unlabeled
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
Input a = 1;
Input b = 0;
Xor g(a, b);
Output y = g;

XNOR gate

Outputs 1 when the inputs are the same.

In code
Xnor
Inputs
2 unlabeled
Outputs
1 unlabeled
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
Input a = 1;
Input b = 1;
Xnor g(a, b);
Output y = g;

Odd parity

Outputs 1 when an odd number of its three inputs are 1.

In code
OddParity (also odd)
Inputs
3 unlabeled
Outputs
1 unlabeled
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
Input a = 1;
Input b = 1;
Input c = 1;
OddParity p(a, b, c);
Output y = p;

Even parity

Outputs 1 when an even number of its three inputs are 1.

In code
EvenParity (also even)
Inputs
3 unlabeled
Outputs
1 unlabeled
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
Input a = 1;
Input b = 1;
Input c = 0;
EvenParity p(a, b, c);
Output y = p;

Controlled buffer

Passes D through only while E is 1. While E is 0 the output floats (nothing drives the wire). This is how several parts share one bus.

In code
ControlledBuffer (also cbuf)
Inputs
D, E
Outputs
1 unlabeled
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
Input<4> d = 7;
Input e = 1;
ControlledBuffer<4> cb(d, e);
Output<4> y = cb;

Controlled inverter

Like the controlled buffer, but outputs the inverted value while E is 1.

In code
ControlledInverter (also cinv)
Inputs
D, E
Outputs
1 unlabeled
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
Input<4> d = 7;
Input e = 1;
ControlledInverter<4> ci(d, e);
Output<4> y = ci;

Plexers

Multiplexer

Chooses one of two inputs. Output is input 0 when S is 0, and input 1 when S is 1.

In code
Mux
Inputs
0, 1, S
Outputs
1 unlabeled
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
Input<4> a = 3;
Input<4> b = 9;
Input s = 1;
Mux<4> m(a, b, s);
Output<4> y = m;

Demultiplexer

Sends D to output 0 or output 1, depending on S. The other output is 0.

In code
Demux
Inputs
D, S
Outputs
0, 1
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1

Refer to outputs as .out0, .out1 or by number in square brackets.

Input<4> d = 5;
Input s = 1;
Demux<4> dm(d, s);
Output<4> y0 = dm.out0;
Output<4> y1 = dm.out1;

Decoder

Turns a 2-bit number (S0 is the low bit) into four lines. Exactly one output is 1.

In code
Decoder (also dec)
Inputs
S0, S1
Outputs
0, 1, 2, 3

Refer to outputs as .out0, .out1, .out2, .out3 or by number in square brackets.

Input s0 = 1;
Input s1 = 0;
Decoder dc(s0, s1);
Output y = dc.out1;

Priority encoder

Reports the highest-numbered input that is 1 as a 2-bit number (Y0 low bit). V is 1 when any input is 1.

In code
PriorityEncoder (also penc)
Inputs
0, 1, 2, 3
Outputs
Y0, Y1, V

Refer to outputs as .y0, .y1, .valid or by number in square brackets.

Input a = 0;
Input b = 1;
Input c = 0;
Input d = 0;
PriorityEncoder pe(a, b, c, d);
Output y = pe.y0;
Output v = pe.valid;

Bit selector

Outputs a single bit of the input, chosen by the Sel number.

In code
BitSelector (also bsel)
Inputs
In, Sel
Outputs
1 unlabeled
Default width
8 bits
Settings
  • bits (also written <bits>): data width, 1 to 16, default 8
Input<8> a = 0b10100000;
Input<3> i = 5;
BitSelector<8> b(a, i);
Output y = b;

Arithmetic

Adder

Adds A and B plus a carry-in Ci. Outputs the sum and a carry-out. Numbers are unsigned and wrap around.

In code
Adder (also add)
Inputs
A, B, Ci
Outputs
S, Co
Default width
4 bits
Settings
  • bits (also written <bits>): data width, 1 to 16, default 4

Refer to outputs as .sum, .carry or by number in square brackets.

Input<4> a = 7;
Input<4> b = 9;
Adder<4> s(a, b);
Output<4> sum = s;
Output co = s.carry;

Subtractor

Computes A minus B minus a borrow-in Bi. Outputs the difference and a borrow-out.

In code
Subtractor (also sub)
Inputs
A, B, Bi
Outputs
D, Bo
Default width
4 bits
Settings
  • bits (also written <bits>): data width, 1 to 16, default 4

Refer to outputs as .diff, .borrow or by number in square brackets.

Input<4> a = 9;
Input<4> b = 7;
Subtractor<4> d(a, b);
Output<4> diff = d;
Output bo = d.borrow;

Multiplier

Computes A times B plus Ci. The low half of the answer is the product and the high half is the carry output.

In code
Multiplier (also mul)
Inputs
A, B, Ci
Outputs
P, Co
Default width
4 bits
Settings
  • bits (also written <bits>): data width, 1 to 16, default 4

Refer to outputs as .product, .carry or by number in square brackets.

Input<4> a = 6;
Input<4> b = 7;
Multiplier<4> m(a, b);
Output<4> p = m;
Output<4> hi = m.carry;

Divider

Divides A by B and outputs the quotient and the remainder. Up supplies extra high bits of the dividend. Dividing by zero gives an all-ones quotient and a remainder of 0.

In code
Divider (also div)
Inputs
A, B, Up
Outputs
Q, R
Default width
4 bits
Settings
  • bits (also written <bits>): data width, 1 to 16, default 4

Refer to outputs as .quotient, .remainder or by number in square brackets.

Input<4> a = 13;
Input<4> b = 3;
Divider<4> d(a, b);
Output<4> q = d.quotient;
Output<4> r = d.remainder;

Negator

Two's complement negative of the input.

In code
Negator (also neg)
Inputs
In
Outputs
1 unlabeled
Default width
4 bits
Settings
  • bits (also written <bits>): data width, 1 to 16, default 4
Input<4> a = 3;
Negator<4> n(a);
Output<4> y = n;

Comparator

Compares A and B as unsigned numbers. Exactly one of the three outputs is 1.

In code
Comparator (also cmp)
Inputs
A, B
Outputs
>, =, <
Default width
4 bits
Settings
  • bits (also written <bits>): data width, 1 to 16, default 4

Refer to outputs as .gt, .eq, .lt or by number in square brackets.

Input<4> a = 5;
Input<4> b = 3;
Comparator<4> c(a, b);
Output gt = c.gt;
Output eq = c.eq;
Output lt = c.lt;

Shifter

Shifts or rotates the input by Sh places. Modes: ll logical left, lr logical right, ar arithmetic right (keeps the sign), rl rotate left, rr rotate right.

In code
Shifter (also shift)
Inputs
In, Sh
Outputs
1 unlabeled
Default width
4 bits
Settings
  • bits (also written <bits>): data width, 1 to 16, default 4
  • mode: Mode (ll lr ar rl rr), default "ll"
Input<4> a = 0b0110;
Input<2> n = 1;
Shifter<4> sh(a, n, mode="lr");
Output<4> y = sh;

Bit adder

Counts how many bits are 1 across its three inputs.

In code
BitAdder (also badd)
Inputs
0, 1, 2
Outputs
N
Default width
1 bit
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1
Input<4> a = 0b1011;
Input<4> b = 0b0001;
Input<4> c = 0;
BitAdder<4> n(a, b, c);
Output<4> y = n;

Bit finder

Finds the position of the lowest or highest bit that is 1 (or 0). Found is 1 when there is one. Modes: low1, high1, low0, high0.

In code
BitFinder (also bfind)
Inputs
In
Outputs
Idx, P
Default width
4 bits
Settings
  • bits (also written <bits>): data width, 1 to 16, default 4
  • find: Find (low1 high1 low0 high0), default "low1"

Refer to outputs as .index, .found or by number in square brackets.

Input<4> a = 0b0100;
BitFinder<4> f(a, find="low1");
Output<2> idx = f.index;
Output ok = f.found;

Memory

D flip-flop

Stores its input D on each rising clock edge. Q is the stored value and !Q is its opposite.

In code
DFlipFlop (also dff)
Inputs
D, >
Outputs
Q, !Q
Default width
1 bit
Clocked
Acts on the rising edge of its clock pin
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1

Refer to outputs as .q, .nq or by number in square brackets.

Input d = 1;
Clock ck;
DFlipFlop ff(d, ck);
Output q = ff.q;
Output nq = ff.nq;

T flip-flop

Flips its stored value on a rising clock edge when T is 1. Wired to 1 it divides the clock frequency by two.

In code
TFlipFlop (also tff)
Inputs
T, >
Outputs
Q, !Q
Default width
1 bit
Clocked
Acts on the rising edge of its clock pin
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1

Refer to outputs as .q, .nq or by number in square brackets.

Input t = 1;
Clock ck;
TFlipFlop ff(t, ck);
Output q = ff.q;

J-K flip-flop

On a rising edge: J=1 sets it, K=1 clears it, both 1 flips it, both 0 holds it.

In code
JKFlipFlop (also jkff)
Inputs
J, >, K
Outputs
Q, !Q
Default width
1 bit
Clocked
Acts on the rising edge of its clock pin
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1

Refer to outputs as .q, .nq or by number in square brackets.

Input j = 1;
Input k = 0;
Clock ck;
JKFlipFlop ff(j, ck, k);
Output q = ff.q;

S-R flip-flop

On a rising edge: S=1 sets it, R=1 clears it.

In code
SRFlipFlop (also srff)
Inputs
S, >, R
Outputs
Q, !Q
Default width
1 bit
Clocked
Acts on the rising edge of its clock pin
Settings
  • bits (also written <bits>): data width, 1 to 16, default 1

Refer to outputs as .q, .nq or by number in square brackets.

Input s = 1;
Input r = 0;
Clock ck;
SRFlipFlop ff(s, ck, r);
Output q = ff.q;

Register

Stores a multi-bit value on each rising clock edge.

In code
Register (also reg)
Inputs
D, >
Outputs
Q
Default width
4 bits
Clocked
Acts on the rising edge of its clock pin
Settings
  • bits (also written <bits>): data width, 1 to 16, default 4
Input<4> d = 9;
Clock ck;
Register<4> r(d, ck);
Output<4> y = r;

Counter

Adds one on every rising clock edge and wraps back to 0 after its largest value.

In code
Counter (also ctr)
Inputs
>
Outputs
Q
Default width
2 bits
Clocked
Acts on the rising edge of its clock pin
Settings
  • bits (also written <bits>): data width, 1 to 16, default 2
Clock ck;
Counter<4> c(ck);
Output<4> y = c;

Shift register

A chain of stages. Each clock edge moves values one stage along. The output is the value from the last stage, so it appears after as many clocks as there are stages.

In code
ShiftRegister (also shreg)
Inputs
In, >
Outputs
1 unlabeled
Default width
4 bits
Clocked
Acts on the rising edge of its clock pin
Settings
  • bits (also written <bits>): data width, 1 to 16, default 4
  • stages: Stages, default 4
Input<4> d = 5;
Clock ck;
ShiftRegister<4> sr(d, ck, stages=3);
Output<4> y = sr;

Random generator

Produces a new pseudo-random number on every rising clock edge.

In code
RandomGenerator (also rnd)
Inputs
>
Outputs
1 unlabeled
Default width
4 bits
Clocked
Acts on the rising edge of its clock pin
Settings
  • bits (also written <bits>): data width, 1 to 16, default 4
Clock ck;
RandomGenerator<4> r(ck);
Output<4> y = r;

RAM

Memory you can write and read. When WE is 1, a rising clock edge stores D at address A. Q always shows what is stored at the current address (reading needs no clock). Contents are not saved with the circuit.

In code
RAM
Inputs
A, D, WE, >
Outputs
Q
Default width
4 bits
Clocked
Acts on the rising edge of its clock pin
Settings
  • bits (also written <bits>): data width, 1 to 16, default 4
  • addr: Address bits, default 4
Input<4> a = 3;
Input<4> d = 9;
Input we = 1;
Clock ck;
RAM<4> m(a, d, we, ck, addr=4);
Output<4> y = m;

ROM

Read-only memory. List its contents as hexadecimal words separated by spaces in the data setting. Word 0 comes first.

In code
ROM
Inputs
A
Outputs
D
Default width
4 bits
Settings
  • bits (also written <bits>): data width, 1 to 16, default 4
  • addr: Address bits, default 4
  • data: Contents (hex words)
Input<4> a = 1;
ROM<4> r(a, addr=4, data="3 a f");
Output<4> y = r;

Input and output

Button

Outputs 1 while you hold it down with the Poke tool and 0 when you let go.

In code
Button (also btn)
Inputs
none
Outputs
1 unlabeled
Button b;
LED l = b;

Joystick

Drag inside it with the Poke tool to set X and Y. It rests in the middle.

In code
Joystick (also joy)
Inputs
none
Outputs
X, Y
Default width
4 bits
Settings
  • bits (also written <bits>): data width, 1 to 16, default 4

Refer to outputs as .x, .y or by number in square brackets.

Joystick<4> j;
Output<4> x = j.x;
Output<4> y = j.y;

Keyboard

Type while it is selected and the characters queue up. Each rising clock edge moves to the next character. Ch is the 7-bit ASCII code and Av is 1 when a character is waiting.

In code
Keyboard (also keyb)
Inputs
>
Outputs
Ch, Av

Refer to outputs as .char, .ready or by number in square brackets.

Clock ck;
Keyboard k(ck);
Output<7> c = k.char;
Output av = k.ready;

LED

A light that is on when its input is 1.

In code
LED
Inputs
1 unlabeled
Outputs
none
Input a = 1;
LED l = a;

7-segment display

Seven inputs, one for each segment (a to g). A segment lights when its input is 1.

In code
SevenSegment (also seg7)
Inputs
a, b, c, d, e, f, g
Outputs
none
Constant one = 1;
Constant zero = 0;
SevenSegment disp(one, one, one, one, one, one, zero);

Hex digit display

Shows a 4-bit number as a hexadecimal digit, 0 to F.

In code
HexDisplay (also hex)
Inputs
D
Outputs
none
Input<4> v = 10;
HexDisplay h(v);

LED matrix

A grid of LEDs driven by scanning. A light at column k and row r is on when bit k of C and bit r of R are both 1. Show a picture by switching rows quickly one after another. See the LED screen guide.

In code
LEDMatrix (also matrix)
Inputs
C, R
Outputs
none
Default width
5 bits
Settings
  • bits (also written <bits>): Columns, 1 to 16, default 5
  • rows: Rows, default 7
Input<5> c = 0b10101;
Input<7> r = 0b1111111;
LEDMatrix<5> m(c, r, rows=7);

TTY (terminal)

A small text terminal. On each rising clock edge it adds the character whose 7-bit ASCII code is on D. Code 8 deletes the last character and 13 or 10 starts a new line.

In code
TTY
Inputs
D, >
Outputs
none
Clocked
Acts on the rising edge of its clock pin
Input<7> d = 65;
Clock ck;
TTY t(d, ck);

LED screen

One part that holds a whole picture, up to 2048 by 2048 pixels, shown as solid square pixels like a monitor. A circuit draws on it with X, Y, D, WE and a clock, and you can also paint on it by hand. Read the LED screen guide.

In code
LEDScreen (also screen)
Inputs
X, Y, D, WE, CLR, >
Outputs
none
Default width
3 bits
Clocked
Acts on the rising edge of its clock pin
Settings
  • bits (also written <bits>): Color bits, 1 to 16, default 3
  • width: Width, default 16, 1 to 2048
  • height: Height, default 16, 1 to 2048
  • color: Color (hex), default "#ff5470"
Clock ck;
Counter<6> n(ck);
Splitter<6> sp(n);
Combiner<3> x(sp[0], sp[1], sp[2]);
Combiner<3> y(sp[3], sp[4], sp[5]);
Xor<3> d(x, y);
Constant we = 1;
LEDScreen<3> scr(x, y, d, we, None, ck, width=8, height=8);

Notes

Text note

A label you can place anywhere to explain your circuit. It does nothing in the simulation.

In code
Text
Inputs
none
Outputs
none
Settings
  • text: Text, default "text"
Text note("my circuit");