Goals
- Acquire hands-on practice in designing and debugging fundamental digital logic circuits using Logisim.
- Accumulate proficiency through experience in designing and troubleshooting circuits with both combinational logic gates and memory-based state elements.
- Cultivate expertise in designing Finite State Machines (FSMs) and effectively realizing them as digital logic implementations.
Lab 5
Computer Architecture I @ ShanghaiTech University
Exercises
Download the files for Lab 5 first.
Something you must know before you start:
- Logisim is a program with a GUI interface and please run it in your local environment. The local Python version should be greater than 3.6, and the Java version should be higher than 16.
- Please use the
.jarfile we have provided (Version 3.8.0) to avoid compatibility issues. Windows, Ubuntu and macOS systems can all run it. - Logicsim does not save your work as you go along. Remember to save when you start, and save frequently as you work. The
Command/Control + Sshortcut key allows for quick saving.
Exercise 1: Hello World in Logisim
You can launch Logicsim by running the following command in the terminal. If your environment is configured correctly, the program interface should appear after a few seconds. In the Windows OS, you can also open the program by double-clicking the .jar file with the left mouse button. If you launched Logisim from the command line, please keep the terminal open while it is running, otherwise the program will immediately exit.
$ java -jar logisim-evolution.jar
In this part of the lab, we will create an AND gate circuit together to help us get started quickly. Please pay attention to the zoom and grid functions located at the bottom left corner of the program, which will facilitate your wiring process during larger circuit designs.

Start by clicking the ANDgate button. This will cause the shadow of anANDgate to follow your cursor around. Click once within the main schematic window to place anANDgate.
Click the Input Pinbutton. Now, place two input pins somewhere to the left of yourANDgate.
Click the Output Pinbutton. Then place an output pin somewhere to the right of yourANDgate. Your schematic should look something like this at this point:
Click the Selecttool button. Click and drag to connect the input pins to the left side of theANDgate. This will take several steps, as you can only draw vertical and horizontal wires. Just draw a wire horizontally, release the mouse button, then click and drag starting from the end of the wire to continue vertically. You can attach the wire to any pin on theANDgate on the left side. Repeat the same procedure to connect the output of theANDGate (right side) to the output pin. Double-click these three pins to name them labels. After completing these steps your schematic should look roughly like this:
Click the Poketool and try clicking on the input pins in your schematic. Observe what happens. Does this match with what you think anANDGate should do? Note that poking the wires themselves tells you the current value on that wire; this will be very useful later when you build more complex circuits.Save your circuit named as
ex1.circ. ClickSimulate -> Test Vector...and load vector selecting thetestvector_ex1.txtfile from thelab5_starterfolder. If everything goes well, you should see that all four test vectors passed.
Show your test vector result to your TA.
Exercise 2: Build Sub-circuits
Just as C programs can contain helper functions, a schematic can contain subcircuits. In this part of the lab, we will create several subcircuits to demonstrate their use.
IMPORTANT NOTE: Logisim Evolution guidlines say you cannot name a subcircuit after a keyword (e.g. NAND), also circuit names must start with “A-Za-z”, so no numbers.
ACTION ITEM:
Follow the steps below and show your final circuit to your TA at checkoff (remember to save!).
Open up the Exercise 2 schematic (
File -> Open -> ex2.circ).Open up the
NAND1empty subcircuit by double clicking on the nameNAND1in the circuit selector in the left menu. (note the1at the end; because there is a component calledNAND, we cannot call itNAND).In the new schematic window that you see create a simple
NANDcircuit with the 2 input pins on the left side and the output pin on the right side. Do this without using the built-inNANDgate from the Gates folder (i.e. only use theAND,OR, andNOTgates provided next to the selection tool icon). You can change the labels for the inputs and output by selecting the input/output using the select tool and changing the propertyLabelin the bottom left of the window.Repeat these steps to create several more subcircuits:
NOR,XOR,2-to-1 MUX,4-to-1 MUXandHALF ADDERin the given skeletons. Please do not change the names of the subcircuits or create new ones; do you work in the respectively named circuit or else the autograder will not work properly. Do not use any built-in gates other thanAND,OR, andNOT. Once you’ve built a subcircuit, you may (and are encouraged to) use it to build others. You can do this by clicking and placing your created subcircuit like you would any other component. Note: for the4-to-1 MUX,Sel1andSel2correspond to the 1st and 2nd bits of the 2-bit selector, respectively.Build your
4-to-1 MUXaccording to the following rule in this lab:Sel1: 0,Sel2: 0 -> SelectASel1: 1,Sel2: 0 -> SelectBSel1: 0,Sel2: 1 -> SelectCSel1: 1,Sel2: 1 -> SelectDHint: Try writing a truth table. You might also find the lecture slides useful for a refresher on how to build these. You may want to consider using some of your custom subcircuits when designing the others.
Show your five circuits (NAND, NOR, XOR, 2-to-1 MUX, 4-to-1 MUX and HALF ADDER) to your TA.
Exercise 3: Storing State
Let’s implement a circuit that increments a value ad infinitum. The difference between this circuit and the circuits you’ve built for lab so far is that it will store this value in the state of a register.
ACTION ITEM:
The following steps will show you how to add registers to your circuit. Complete the steps and show the final circuit to your TA (remember to save!):
Open up the Exercise 3 schematic (
File -> Open -> ex3.circ) and go to the emptyAddMachinecircuit.Select the
Addersubcircuit from theArithmeticlibrary and place theAdderinto yourAddMachinesubcircuit.Select the register from the
Memoryfolder and place one register into your subcircuit. Below is an image diagraming the parts of a register.
Connect a
clockto your register. You can find the clock circuit element in theWiringfolder in the circuit browser.Connect the output of the
Adderto the input of the register, and the output of the register to the input of theAdder.- You may get a “Incompatible widths” error when you try to connect components. This means that your wire is trying to connect two pins together with different bit widths. If you click on the
Adderwith theSelectiontool, you will notice that there is aData Bit Widthproperty in the bottom left field of the window. This value determines the number of bits each input and output theAdderhas. Change this field to8and the “Incompatible widths” error should be resolved.
- You may get a “Incompatible widths” error when you try to connect components. This means that your wire is trying to connect two pins together with different bit widths. If you click on the
Wire an 8-bit constant
1to the second input of theAdder. You can find theConstantcircuit element in theWiringlibrary.Connect the two output pins to your circuit so that you may monitor what comes out of the
Adderand the register. The output of theAddershould be connected toADD_OUTand the output of the register toREG_OUT.Select the
Comparatorsubcircuit from theArithmeticlibrary and place theComparatorinto yourAddMachinesubcircuit. The first input of theComparatorshould be connected toREG_OUT. Wire an 8-bit constant255to the second input of theComparator.Create an output pin at the right of the
Comparatorand name its label ashalt. Connect the second output of theComparatorto thehalt. It is used as a flag indicating the end of the simulation. Thus, by the end, your circuit should look like as follows:
Now start running your circuit by going to
Simulate->Ticks Enabled(orCommand/Control + K). Your circuit should now be outputting a counter in binary form.If you want to run your circuit faster, you can change the tick frequency in
Simulate->Tick Frequency.
Show your AddMachine circuit to your TA.
Exercise 4: FSMs to Digital Logic
In this part of lab, we’re ready to do something really cool: translate a FSM into a digital logic circuit. FSM’s keep track of inputs given, moves between states based on these inputs, and outputs something everytime something is input. We use a register to store the state of the FSM we’re currently in, and combinational logic to map FSM input & current register state to FSM output & next register state.
ACTION ITEM:
Load the given starter file ex4.circ into Logisim. Modify this circuit’s subcircuits StateBitZero and StateBitOne to implement this Moore FSM: Detecting 010 pattern in a bit sequence(use overlapping). Show this completed circuit to your TA (remember to save!)
Note that the FSM is implemented by the following diagram (the four state names
00,01,10,11are just names written in binary - they have no direct relationship with the actual zeros and ones of the FSM input/output). Take some time to understand how this diagram implements the FSM:
Observe that the following is a truth table for the FSM (convince yourself of this):
st1 st0 input next st1 next st0 output 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 1 0 0 1 1 1 0 0 1 0 0 1 1 0 1 0 1 0 0 0 1 1 0 0 1 1 1 1 1 1 0 1 We’ve provided you with a starter Logisim circuit to start out in
ex4.circ.Note that the top level of the circuit looks almost exactly the same as our previous adder circuit, but now there’s a
FSMLogicblock instead of an adder block.FSMLogicis the combinational logic block for this FSM. We have handled the output bit for you. You should complete the circuit by completing theStateBitOneandStateBitZerosubcircuits, which produces the next state bits.
Show your StateBitZero circuit & StateBitOne circuit to your TA and demonstrate that they behave correctly.
Testing
To test, run the testing script test.sh. Since Logisim will be running in one terminal window already, make sure to open up a new window to run the testing script. This script will copy your circuits into a testing harness, run your circuits on different inputs, and compare your results to ours. Therefore, please do not touch anything in the testing folder unless a TA instructs you to do so. However, you are more than welcome to check out the circuitry involved in testing your code as you will encounter it again when working on Project 2.
The following TA(s) are responsible for this lab:
Zhaojun Ni