In the previous lesson, you installed Logisim and created half and full adders.
Now it's time to build an ALU or Arithmetic Logic Unit.
To keep things easy-to-follow and straightforward, we'll be building a 4-bit ALU with four operations:
AND, OR, NOT, and addition/subtraction.
The first step is to create a new Logisim file.
Save this file as 4-bit ALU.circ.
Once you have a blank canvas, let's create sub-circuits for the adders, the AND and the OR.
Next, right-click on the main folder (4-bit ALU) and select Add Circuit, as shown in Figure 1:
Name the circuit Full Adder.
Repeat to add the following circuits as mentioned below:
4-bit Adder/Subtractor, 4-bit AND, 4-bit OR
Your Logisim explorer window should look as follows:
Save your work!
Now, let's build the sub-circuits.
The following diagrams show the setup for the adders.
To open the canvas, double-click on the Full Adder circuit.
Add the following:
1 input pin, labeled In, facing South 2 input pins, labeled A and B, facing East
1 output pin, labeled Result, facing West
1 output pin, labeled Out, facing North
2 XOR gates, facing East (2 inputs, 1 data bit)
2 AND gates, facing South (2 inputs, 1 data bit) and
1 OR gate, facing South (2 inputs, 1 data bit)
Arrange and connect them, referring to this next figure appearing here:
The Adder/Subtractor shown in that previous figure might look complicated,
but we will actually be able to add in the adders we created previously.
You can click an element from the explorer menu on the left
(e.g., Full Adder), and drag it onto your canvas.
In the 4-bit Adder/Subtractor circuit, add the following:
Drag and drop 4 of the Full Adders you created earlier onto the canvas
(the will have + signs on them); arrange vertically
An East-facing pin called Add/Subtract Control (add this to the top left)
A North-facing Pin called B, with 4 data bits
A South-facing pin called A, with 4 data bits
4 East-facing XOR gates, each with 2 inputs
3 South-facing NOT gates, each 1 data bit
2 East-facing AND gates, each 1 Data bit and 3 inputs
3 splitters with 4 inputs
Output pins for Carry out and Overflow
Connect All Elements
Next, connect all elements as shown in this next figure appearing here.
This figure, which we'll call figure 3, is the completed 4-bit adder/subtractor will all components.
In this sub-circuit, we add the following:
Two Inputs, A and B, with 4 data bits
Two splitters with 4 bits
4 AND gates with two inputs each
Another splitter with 4 bits and finally,
An output pin, Result with 4 bits
Add elements and connect as shown in this next figure appearing here:
The 4-Bit AND matches the 4-Bit OR subcircuit, except you add 4 AND gates, as shown in this next figure
Now, let's build the final ALU.
We build the circuit it from left to right, showing the final output at the end.
Step 1: Add the Two Input Pins
Drop two East-facing input pins on the canvas 4-bits each.
Label them A and B, and ensure that each input is 4-bits.
Step 2: Add the Adder/Subtractor and Gates
Now we add the sub-circuits created earlier.
Select the circuits under the main project folder, referring to the diagram appearing here now:
Then click on the canvas to drop them.
Drop each of the following:
The 4-Bit Adder/Subtractor The 4-Bit AND and The 4-Bit OR
Step 3: Add the Multiplexers
Recall that an ALU needs multiplexers, or (MUX).
These take on or more data inputs and generate a single output.
In Logisim, multiplexers are under the Plexers folder.
Click the Multiplexer icon and drop two of them onto our canvas.
Each has one Select Bit and 4 Data Bits:
Step 4: Add Controls
Now we need our controls for the multiplexers.
Drop two pins on the canvas, north-facing, with 1 data bit.
Label them 0 and 1, respectively.
Step 5: Add a Splitter
Next, we add a splitter into our circuit that takes one line from the second
multiplexer and split to 4 inputs to an OR gate - for a 4-bit ALU.
Step 6: Add Another OR Gate And a Not Gate
Now we add an OR gate after the splitter, which has 4 inputs
(from the splitter; we'll add the lines later).
To the right of the OR gate, add a NOT gate.
This arrangement accounts for Zero output when ALL of the bits result in zero.
The NOT gate following the OR gate achieves this.
Finally, add a single-bit pin after the NOT gate to store the result.
Label it ZERO.
Step 7: Add a Result Pin for the MUX
We handled the zeroes coming from the MUX,
but we also need to account for valid combinations of inputs from A, B, and the Control inputs.
Add a 4-bit pin to the right of the MUX.
It should be West-facing!
Step 8: Add Negative, Carry, and Overflow Pins
We're almost there!
Let's recall from the ALU design, that when the most significant bit is 1, the final result is negative.
In situations where the result is large enough to not fit into our bit allowance, we get a carry.
Finally, if our signs are mixed up and you get a result of -1, you need a catch for overflow.
Add three more pins for each, below the Zero pin, and allow space to connect them all.
Step 9: Connecting the Circuits
Now it gets interesting.
We need to connect all the parts to finally build our first 4-bit ALU.
Make your connections carefully; remember you can Undo if something goes awry!
You may have to shift some of the components around the canvas; this might make your lines look funny.
There's no harm in deleting and re-adding the lines.
Also, you can click on the middle of any line and start a new one
(see the line from Input A down to the 4-bit Adder as an example).
And finally, Step 10: Perform Final Test!
Now let's test this out!
Click the hand icon in the toolbar.
Try the following, watching the output result pins as you do.
Click the input pin A, selecting individual bits, changing from 1 to 0.
What happens?
And Click the Control inputs 0 and 1 to change values
Note: If you messed up any connections, or didn't set the bit values right,
the lines change their color to red, and you might get errors.
Be sure to check your gates and inputs so that the bits are accurate.
That was a lot, so let's briefly review what we've learned.
In this lesson, we've constructed a 4-bit ALU (or the Arithmetic Logic Unit),
building upon the knowledge gained in designing adders and half-adders.
Using Logisim, we put together each piece, including sub-circuits, control inputs,
and outputs to account for valid values, zero, negative, and overflow output.
After completing this exercise,
you should feel more confident in your ability to design logical circuits in Logisim,
especially if you remember to follow the steps we covered.
For a quick refresher, they included the following:
Step 1: Add the Two Input Pins
Step 2: Add the Adder/Subtractor and Gates
Step 3: Add the Multiplexers
Step 4: Add Controls
Step 5: Add a Splitter
Step 6: Add Another OR Gate And a Not Gate
Step 7: Add a Result Pin for the MUX
Step 8: Add Negative, Carry, and Overflow Pins
Step 9: Connecting the Circuits
And finally, Step 10: Perform Final Test!