I’ve covered tons of different scientific
applications you can run on your computer to do rather complex
calculations, but so far, I’ve not really given much thought to
the hardware on which this software runs. So in this article, I take a look at
a software package that lets you dive deep down to the level of the
logic gates used to build up computational units.
At a certain point,
you may find yourself asking your hardware to do too much work. In those cases,
you need to understand what your hardware is and how it works. So,
let’s start by looking at the lowest level: the lowly
logic gate. To that end, let’s use a software package named Logisim
in order to play with logic gates in various groupings.
Logisim should be available in most distributions’ package management
systems. For example, in Debian-based distros, install it
with the following command:
sudo apt-get install logisim
You then can start it from your desktop environment’s menu,
or you can open a terminal, type logisim and press
Enter. You should see a main section of the application
where you can start to design your logic circuit. On the left-hand side,
there’s a selection pane with all of the units you can use for your
design, including basic elements like wires and logic gates, and
more complex units like memory or arithmetic units.
Figure 1. When you first start Logisim, you get a blank project where
you can start to design your first logic circuit.
To learn how to start using Logisim, let’s look at how to set up one of
the most basic logic circuits: an AND gate.
Figure 2. You easily can add logic gates to your circuit to model
computations.
If you click the
Gates entry on the left-hand side, you’ll see a full list of available
logic gates. Clicking the AND gate allows you to add them to the design
pane by clicking on the location where you want them added. At the bottom
of the left-hand side, you’ll see a pane that displays the attributes
of the selected gate. You can use this pane to edit those attributes to
make the gate behave exactly the way you want. For this example,
let’s change the number of inputs value from 5 to 2. The next
step is to add an output pin in order to see when the output is either
1 or 0. You can find pins in the wiring section.
On the front side of the
AND gate, you’ll want to add pins so you can control input. In the
attributes for each of the pins, you’ll see that you can change whether
the pin is supposed to be an output pin. You also can set whether
the pin is supposed to be a three-state pin.
The last step is to
connect all of these pieces by simply clicking and dragging
between the separate components.
Figure 3. You can add extra items, like inputs and outputs, to your
logic circuit.
By default, the input pins
currently are set to 0, so once the wires are connected, you should see
that the output is set to 0. In order to toggle the input pins, you first need
to select the toggle tool from the toolbar at the top of the window
(the one shaped like a pointing hand). Once you have selected this tool,
you can click on the input pins to change their states. Once both inputs
are set to 1, you should see the output flip to 1 also.
While you can build your circuits up from first principles and see how
they behave, Logisim also lets you define the behavior first and generate
a circuit that gives you the defined behavior. Clicking the
Window→Combinational Analysis menu item pops up a new window where you can
do exactly that.
Figure 4. You can build up your logic circuits in reverse by defining
the behavior you wanted first, then allowing it to generate a circuit that
gives you this required behavior.
The first step is to provide a list of
inputs. You simply add a series of labels, one for each input. For this
example, you’ll define an x, y and z. Next, you’ll need to click
the outputs tab and do the same for the number of outputs you want to
model. Let’s just define a single output for this example.
The last step
is actually to define the behavior linking the inputs to the outputs. This
is done through a logic table. So here, you’ll have the output
as 0, unless either x and z or y and z are high.
Figure 5. Logisim includes a tool that allows you to generate logic circuits
based on a truth table that you define to handle the computation you’re
interested in modeling.
Once
you’re happy with the definition, click the Build Circuit
button at the bottom of the window. This pops up a new dialog window
where you can define the name and select the destination project, as
well as choosing whether to use only NAND gates or only 2-input
gates.
Figure 6. By using the Combinational Analysis window, you can create
more complex circuits based purely on their expected behavior.
You can click on the inputs to toggle them and
verify that everything behaves as you had planned.
The Combinational Analysis window has two other tabs: Expression and Minimized. The
Expression tab shows you the logical mathematical expression that
describes the truth table you defined. You can edit your
circuit further by editing this equation directly. The minimized tab gives you
the logical equation as either the sum of products or the product of sums.
Once you finish your circuit, you can save it in a .circ
file. These files define a complete circuit that can be reused as a single
unit. When you do want to reuse them in a larger, more complex circuit,
click Project→Load Library→Logisim Library and
select the saved file. This allows you to build up very
complicated computing circuits rather quickly.
You also can export the circuit itself
by clicking File→Export Image. This allows you
to save the circuit as an image that you can use in a report or
some other process.
This is just a brief introduction, but I hope Logisim helps you learn a bit more
about the fundamentals of computing and logical structures.