Instantiation: from Blueprint to Part

The intro to level 34: the same node is never drawn twice. A finished module is wired into a circuit by one line of text — the part appears on the blueprint from its own blueprint.

Experiment: a full adder built from gates

A full adder is five gates adding three bits: A, B and the carry-in. Walking through all eight combinations fills in the table. The extreme case: 1 + 1 + 1 = 11 in binary — a one in Sum and a carry into the next digit.

Transfer: reading a connection by name

The HalfAdder module has ports .a, .b, .sum and .carry. The record .sum(s1) means: the part's sum port is connected to wire s1. Before the parentheses is the blueprint's port, inside them is your wire. The port gets connected — not assigned a value and not renamed.

The rule: a part from a blueprint

A declared module is a blueprint; instantiation is the phrase "build a part from this blueprint and name it so-and-so": HalfAdder ha1 ( .a(x), .b(y), .sum(w), .carry(c) );. The part name (ha1, ha2) must be unique — that is how the part is found on the blueprint and wired to others. The same circuit works as many times as you like, and the code is shorter than wiring gates by hand.

Where it is used

On this level you describe a full adder in lines — the same circuit you drew from five gates before. Modules then nest: half adders make a full adder, adders make an ALU, and the ALU makes a processor.

Take the intro in the game · Level 34 guide · All intros