Using subcircuits

Now suppose we want to build a 2x4 multiplexer using instances of our 1x2 multiplexer. Of course, we would first create a new circuit, which we'll call "2x4 MUX."

To add 1x2 multiplexers into our circuit, we click the 1x2 MUX circuit in the explorer pane and click in the circuit to add copies of it. (If you double-click the 1x2 MUX circuit, incidentally, then the window would display that circuit's contents instead.) After building up the circuit, we end up with the following.

Our circuit for a 2x4 multiplexer uses three copies of the 1x2 multiplexer; each is drawn as a box with pins along the side. The pins on this box correspond to the input and output pins in the 1x2 MUX circuit. The two pins on the west side of the box correspond to the two pins that face east in the 1x2 MUX circuit; the pin on the box's east side corresponds to the 1x2 MUX's west-facing pin (which happens to be an output pin); and the pin on the box's south side corresponds to the 1x2 MUX's north-facing pin. The order of the two pins on the box's west side correspond to the same top-down ordering that apears in the subcircuit. (If there were several pins on the box's north or south side, they would correspond to the same left-right order in the subcircuit.)

Incidentally, every pin to a circuit must be either an input or an output. Many manufactured chips have pins that behave as an input in some situations and as an output in others; you cannot construct such chips within Logisim.

Logisim will maintain different state information for all subcircuits appearing in a circuit. For example, if a circuit contains a flip-flop, and that circuit is used as a subcircuit several times, then each subcircuit's flip-flop will have its own value when simulating the larger circuit.

Now that we have the 2x4 multiplexer defined, we can now use it in other circuits. Logisim has no limits on how deeply circuits can be nested - though it will object to nesting circuits within themselves!

Note: There's nothing wrong with editing a circuit that is being used as a subcircuit; in fact, this is quite common. Be aware, though, that any changes to a circuit's pins (adding, deleting, or moving them) will rearrange them also in the containing circuit. Thus, if you change any pins in a circuit, you will also need to edit any circuits using it as a subcircuit.

Next: Debugging subcircuits.