Using subcircuits

Now suppose we want to build a 4-to-1 multiplexer using instances of our 2-to-1 multiplexer. Of course, we would first create a new circuit, which we'll call "4:1 MUX." To add 2-to-1 multiplexers into our circuit, we click the 2:1 MUX circuit once in the explorer pane to select it as a tool, and then we can add copies of it, represented as boxes, by clicking within the canvas.

If you were to double-click the 2:1 MUX circuit in the explorer pane, then the window would switch to editing the 2:1 MUX circuit instead.

After building up the circuit, we end up with the following.

Our circuit for a 4-to-1 multiplexer uses three copies of the 2-to-1 multiplexer, each drawn as a box with pins along the side. The pins on this box correspond to the input and output pins in the 2:1 MUX circuit. The two pins on the west side of the box correspond to the two pins that face east in the 2:1 MUX circuit; the pin on the box's east side corresponds to the 2:1 MUX's west-facing pin (which happens to be an output pin); and the pin on the box's south side corresponds to the 2:1 MUX's north-facing pin. The order of the two pins on the box's west side correspond to the same top-down ordering from the subcircuit's design. (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.)

If the pins in the subcircuit's layout have labels associated with them, then Logisim will display that label in a tip (that is, a temporary text box) when the user hovers the mouse over the corresponding location of the subcircuit component. (If you find these tips irritating, you can disable them via the Preferences window's Layout tab.)

Several other components will display these tips, too: For some of the pins of a built-in flip-flop, for example, hovering over it explains what that pin does.

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 (at least, in the current version).

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 4-to-1 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: Editing subcircuit appearance.