CS61C Summer 2018 Lab 5 - Introduction to Logisim


Launch the Logisim Evolution application to begin. To do this, click on logisim-evolution.jar or type 'java -jar logisim-evolution.jar' from the hive machines (the logisim-evolution.jar will be in the lab files).

If you would like to use Logisim Evolution on your own computer, you will need to install Logisim Evolution on your machine. There is also a copy of Logisim Evolution included in the lab 5 folder that you can copy from. To get these files run:

$ cp -r ~cs61c/labs/05/ ~/labs/05/

Or if you are on your own machine (remember to change the xxx to your login):

$ scp -r cs61c-xxx@hive21.cs.berkeley.edu:~cs61c/labs/05 .

You can learn about Logisim Evolution beyond the scope of this lab (or download it to use at home) from the Logisim Evolution website. Logisim Evolution can be a bit buggy; if the program starts to act strangely, it is possible that something internally crashed, so the best solution would be to restart it.

Note: We recommend copying Logisim Evolution to your local machine or physically interfacing with the hive machine. Running Logisim Evolution while accessing the hive machine remotely requires additional options while using ssh and makes Logisim Evolution appear to run more slowly.


Part 0: The Basics (Warm-Up)

We'll begin by creating a very simple circuit just to get the feel for placing gates and wires.

  1. Start by clicking the "AND gate" button. This will cause the shadow of an AND gate to follow your cursor around. Click once within the main schematic window to place an AND gate.
  2. Click the "Input Pin" button. Now, place two input pins somewhere to the left of your AND gate.
  3. Click the "Output Pin" button. Then place an output pin somewhere to the right of your AND gate. Your schematic should look something like this at this point:

  4. Click the "Select tool" button. Click and drag to connect the input pins to the left side of the AND gate. 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 down starting from the end of the wire to continue vertically. You can attach the wire to any pin on the AND gate on the left side. Repeat the same procedure to connect the output (right side) of the And Gate to the LED. After completing these steps your schematic should look roughly like this:

    You can also change the number of inputs of the "AND gate" by clicking it using the select tool and changing the properties in the bottom left segment of the window. This can also be done before you put down the component.

  5. Finally, click the "Poke" tool and try clicking on the input pins in your schematic. Observe what happens. Does this match with what you think an AND Gate should do?

Part 1: 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.
  1. Create a new schematic (File->New) for your work.
  2. Create a new subcircuit (Project->Add Circuit ). You will be prompted for a name for the subcircuit; call it NAND_ (note the underscore at the end, you cannot call it NAND).
  3. In the new schematic window that you see create a simple NAND circuit with 2 input pins on the left side and an output pin on the right side. Do this without using the built-in NAND gate from the Gates folder (i.e. only use the AND, OR, and NOT gates 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 property "Label" in the bottom left of the window.
  4. Go back to your "main" schematic by double-clicking "main" in the circuit selector at the left of the screen. Your original (blank) schematic will now be displayed, but your NAND circuit has been stored.
  5. Now, single click the word "NAND_" in the list. This will tell Logisim that you wish to add your "NAND_" circuit into your "main" circuit.
  6. Try placing your NAND circuit into the "main" schematic. If you did it correctly, you should see a gate with 2 input pins on the left and one output pin on the right. Try hooking input pins and output pins up to these and see if it works as you expect.
  7. Repeat these steps to create several more subcircuits: NOR, XOR, 2-to-1 MUX, and 4-to-1 MUX. Do not use any built in gates other than AND, OR, and NOT. However, once you've built a subcircuit, you may use it to build others.
  8. Hint: 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.


Part 2: Storing State

Let's implement the circuit we've been talking about in lecture that increments a value ad infinitum. The difference between this circuit and the circuits you've built for lab so far is that you need some registers. The following will show you how to add registers to your circuit.

  1. Create a new subcircuit (Project->Add Circuit). Name this new subcircuit, AddMachine.
  2. Load in the Arithmetic Library if it is not already loaded (go to Project->Load Library->Built in Library and select "Arithmetic"). This library contains elements that will perform basic mathematical operations. When you load the library, the circuit browser at left will have a new "Arithmetic" folder.

  3. Select the adder subcircuit from the "Arithmetic" library and place the adder into your AddMachine subcircuit.
  4. Load in the Memory Library if it is not already loaded (go to Project->Load Library->Built in Library and select "Memory"). This library contains memory elements used to keep state in a circuit. A new "Memory" folder will appear in the circuit browser.
  5. Select the register from the "Memory" folder and place one register into your subcircuit. Below is an image diagraming the parts of a register.

  6. Connect a clock to your register. You can find the clock circuit element in the "Wiring" folder in the circuit browser.
  7. Connect the output of the adder to the input of the register and the output of the register to the input of the adder.

    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 adder with the "Selection" tool, you will notice that there is a "Data Bit Width" property in the bottom left field of the window. This value determines the number of bits each input and output the adder has. Change this field to 8 and the "Incompatible widths" error should be resolved.

  8. Wire an 8-bit constant 1 to the second input of the adder. You can find the "constant" circuit element in the "Wiring" library.

  9. Add two output pins to your circuit so that you may monitor what comes out of the adder and the register. Make sure the output is 8 bits. Thus, by the end, your circuit should look like as follows:

Now let's see if you built your circuit correctly.

  1. Go back to the "main" subcircuit by double clicking on "main" in the circuit browser.
  2. Single click on your "AddMachine" circuit to select it.
  3. Change the "Facing" property to another direction. Any circuit with the "Facing" property can be rotated to accomodate wires as you need them. This will definitely be useful when you do your project.
  4. Place your AddMachine subcircuit into the main subcircuit.
  5. Select the AddMachine subcircuit you just placed into main.
  6. Connect output pins to the AddMachine subcircuit. Output pins are ordered top to bottom, left to right. Thus, if you followed the schematic above, then the top pin on the right side outputs the value of the adder, and the bottom pin is the output of the register.
  7. Right click on your AddMachine subcircuit, and select "View AddMachine. This is the ONLY method to preserve state (i.e. keep register values at its current value). Double-clicking on the circuit at the circuit browser at left makes logisim think you want to edit the circuit instead of just checking what state the circuit has.

    Note: You can use Simulate->Go In To State->*Circuit Name*, but that allows you go into the first circuit of that type. If you placed two Fib8 circuits down, it only takes you to the first Fib8 circuit you put down.

  8. Initialize the register value to 1. You can do this by first, clicking on the register value with the poke tool. Then, type the hex value in.
  9. To return to the main circuit while preserving state, go to Simulate->Go Out To State->main. Alternatively, you can hold the Command key (control on windows) and press Up-Arrow.
  10. Now start running your circuit by going to Simulate->Ticks Enabled (or Command/Control + K). Your circuit should now be outputting a counter in binary form.
  11. If you want to run your circuit faster, you can change the tick frequency in Simulate->Tick Frequency.


Part 3: FSMs to digital logic

Now we're ready to do something really cool; translate a FSM into a digital logic circuit.

For those of you who need a reminder, FSM stands for Finite State Machine. FSM's keep track of inputs given, moves between states based on these inputs, and outputs something everytime something is input.

If you've been paying attention in lecture you've noticed that the circuit we built in part 2 looks eerily similar to the diagram of a general FSM circuit. The skeleton file we give you contains a similar circuit. Modify this circuit to implement the following FSM:

If two ones in a row or two zeroes in a row have ever been seen, output zeros forever. Otherwise, output a one.

  1. Note that the FSM is implemented by the following diagram:

  2. Observe that the following is a truth table for the FSM:

    st1 st0 input | next st1 next st0 output

  3. We've provided you with a starter Logisim circuit to start out. If you haven't already copied the directory, the following command will get the file for you, given that you're on a hive machine.

    $ cp ~cs61c/labs/05/FSM.circ ~/labs/05/FSM.circ
  4. Note that the top level of the circuit looks almost exactly the same as our previous adder circuit, but now there's a FSMLogic block instead of an adder block. FSMLogic is the combinational logic block for this FSM. We have handled the output bit for you, as it's the most complicated to simplify and implement. You should complete the circuit by completing the StateBitOne and StateBitZero subcircuits, which produces the next state bits.

    You could go from the truth table to SOP to a circuit, or you could notice that for each state bit, there are only two situations in which it is zero. This could make your life easier if you think a bit outside the box...


Advanced Logisim


Feel free to do each part as separate sub-circuits in the same Logisim file.

The following parts will introduce you to more advanced techniques/concepts in Logisim.

Advanced Features

Here are two logisim features you will find useful, especially for the NEXT PROJECT.


A tunnel allows you draw an "invisible wire" to bind two points together. Tunnels are grouped by case-sensitive labels give to a wire. They are used to connect wires like so:

Which has an effect such as the following:

Some care should be taken as to which wires are connected with tunnels to which other wires, such as in this case:

Which in turn has the following effect:

We strongly recommend you use tunnels with Logisim, because they make your circuits much cleaner looking, and therefore easier to debug.


When changing the width of a wire, you should use a bit extender for clarity. For example, consider the following implementation of extending an 8-bit wire into a 16-bit wire:

Whereas the following is much simpler, easier to read, and less error-prone:

Additionally consider the case of throwing out bits. In this example, an 8-bit wire is being converted into a 4-bit wire by throwing out the other bits:

Despite the implications of its name, a bit extender can also do this same operation:

Part 4: Splitters

This is the last essential tool you will need in this class. To demonstrate its use you will construct a circuit that manipulates an 8-bit number.
  1. Create a new subcircuit and name it "Ex4".
  2. Add an 8-bit input pin to your circuit and label it "In".
  3. Add a 1-bit output pin labeled "Out1" and an 8-bit output pin labeled "Out2" to your circuit.
  4. Go to the Wiring folder and select the Splitter circuit. This circuit will take a wire and split it into a set of wires of smaller width. Conversely, it can also take many sets of wires and combine them into a larger bus.
  5. Before you place your circuit, change the "Bit Width In" property (bus width) to 8, and "Fan Out" property (# of branches) to 3. If you move your cursor over the schematic, your cursor should look as follows:
  6. Now, select which bits to send out to which part of your fan. The least significant bit is bit 0 and the most significant bit is bit 7. Change bits 1, 2, and 6 to be coming out on fan arm 1 (the middle one). Have all the other bits come out of the default fan arm. FYI: the "None" option means that the selected bit will not come out on ANY of the fan arms.
  7. Once you configure your splitter, you can place your splitter into your circuit.
  8. Route "In" to the splitter. Attach a 2-input AND gate to fan arms 0 and 2 and route the output of the AND gate to Out1.
  9. Now, interpret the input as a "sign and magnitude" number. Place logic gates and other circuits to make Out2 to be the negative "sign and magnitude" value of the input. Sign and magnitude is an alternate way of representing signed values - like 2s complement, but simpler! The combinational logic should be straight-forward.
  10. We will need another splitter to recombine the fans into a single 8-bit bus. Place another splitter with the proper properties (Bit Width In: 8, Fan Out: 3, correct fan widths). Play with the Facing and Appearance properties to make your final circuit as clean-looking as possible.


  • Show your Ex4 circuit to your TA.
  • If we decide to take the input and interpret it as a 2's complement number, what inputs will produce Out1 = 1? Hint: What do the first and last bits of a two's complement number being 1 tell you about the number?

Part 5: Rotate Right

With your knowledge of splitters and your knowledge and experience with multiplexers from the last lab, you are ready to implement a non-trivial combinational logic block: rotr, which stands for "Rotate Right". The idea is that rotr A,B will "rotate" the bit pattern of input A to the right by B bits. So, if A were 0b1011010101110011 and B were 0b0101 (5 in decimal), the output of the block would be 0b1001110110101011. Notice that the rightmost 5 bits were rotated off the right end of the value and back onto the left end. In RTL, the operation would be something like "R = A >> B | A << (16 - B)".

You must implement a subcircuit named "rotr" with the following inputs:

The output should be A rotated right by B bit positions, as outlined above. You are NOT allowed to use Logisim shifters in your solution, though all other combinational logic (MUXes, constants, gates, adders, etc.) is allowed. Show off your rotr subcircuit in the main subcircuit.

Hint: Before you start wiring, you should think veeeery carefully about how you might decompose this problem into smaller ones and join them together. You should feel very free to use subcircuits when implementing rotr. If you don't, expect to regret it.

Hint, the second: Just because we gave you an RTL representation doesn't mean it's the best way to look at this problem. Think about the input bits of B and think about how to effectively use splitters! Can you do something with the binary form, like with the envelopes in exercise 5 of lab0?

Tip: If your wiring from a large splitter is getting messy, sometimes chaining splitters can keep things more localized and cleaner. For example, a 1 to 16 split can be achieved by a fan out of 4 connected to 4 more splitters of fan out 4.


  • Show your TA your rotr circuit and verify that it works.