People like Logisim. It’s fun. Welcome… to fun.

You will make a circuit capable of adding or subtracting two 4-bit numbers. It will also be able to detect overflow for both the unsigned and signed interpretations of those two operations.

To make things interesting, you are only allowed to use a single adder component. It’s, uh, realistic?

-1. Logisim

First, go download Logisim on the software page! Make sure it’s version 2211_1019.

When you run Logisim, it looks like this:

The circuit diagram is where you do your work.

The parts library is just that - a collection of parts that you can add to the circuit diagram. (You can add your own, too!)

The properties panel is how you set the properties of parts in the circuit (changing their name, or appearance, or how many bits etc.).

And the toolbar contains the three main tools (hand, arrow, text) and shortcuts to commonly-used parts. (You can customize what parts are in the toolbar too!)

Zooming in

Chances are, everything is really tiny. In the bottom left corner, you’ll find the zoom control.

Zoom in with the up arrow. The dots to the right of the arrows toggle the dot grid in the circuit diagram.

The main toolbar tools

The hand is the poke tool (Ctrl+1 or Cmd+1). It’s used for looking at your circuit and interacting with it (changing input values, pushing buttons etc), but you can’t edit the circuit with it.

The arrow is the edit tool (Ctrl+2 or Cmd+2). This is what you change your circuit with. You can select things, move them around, copy and paste them, all kinds of stuff.

The A is the text tool (Ctrl+3 or Cmd+3). You can use it to create/edit “comments” on your circuits, and also to easily name inputs, outputs, probes etc. without having to use the property panel.

Inputs and outputs

To the right of those 3 tools, you see this. These are shortcuts for the input and output components. The square is an input, and the circle is an output.

Inputs and outputs are not interchangeable. I like to put all my inputs on the left, and all my outputs on the right. Then if you have an input or output on the wrong side, it will visually stand out as being incorrect.

To place one, click the button, then click in your circuit. Put one input and one output, like this:

You’ll see they have dots on their sides. Those are the pins, where you can connect wires.

With the arrow tool, click and drag from the pin on the input to the pin on the output. This connects them with a wire.

Now switch to the poke tool and poke the input (square). This will toggle it between 0 and 1.

Truly, this is the most exciting circuit. 😴

Now use the edit tool to drag a box around everything to select it, and hit delete on your keyboard to get rid of it. Let’s get started.


0. Getting started

First, let’s make this thing on the right.

  1. Place 3 inputs, and name them A, B, and sub. You can name them in 2 ways:
    • by clicking it, and then editing the “Label” in the properties; or
    • by using the text tool, clicking on it, and typing the name right there.
  2. Now select the A and B inputs. You can select multiple things in 2 ways;
    • by holding shift and clicking on them one at a time; or
    • by dragging a rectangle around them with the edit tool.
  3. With both of them selected, change the Data bits in the properties pane to 4.
    • This makes them 4-bit.
  4. Finally, create three tunnels from the “Wiring” folder.
    • Name them A, B, and sub to match the input names. (It’s not required by Logisim, but it’s helpful for you.)
    • Set the A and B tunnels’ Data bits to 4.
    • Connect them to the inputs as shown.
    • Also, you can change their color if you want :) It’s not required.

It’s a good habit to make a tunnel for each input (and output) of your circuit. It will make it so much easier to connect things up!


1. The basic adder

  1. Select your three tunnels and hit Ctrl+D/Cmd+D to Duplicate them.
    • You will now see a “ghost” of the tunnels attached to your mouse cursor. Move where you want to place them, and click to put the duplicates there.
    • Copying and pasting works the same way (Ctrl+C/Cmd+C to copy, Ctrl+V/Cmd+V to paste).
  2. Then hit the right arrow key on your keyboard.
    • This will make them face right.
      • (Try hitting the other arrow keys. Whee!)
    • You should now have what’s in the picture on the right.

  3. Place the following components into your circuit:
    • One adder from the “Arithmetic” folder
      • Set its Data Bits property to 4
    • One NOT gate
      • Set its Data Bits property to 4
    • One multiplexer from the “Plexers” folder
      • Set its Data Bits property to 4
      • Leave Select bits at 1
    • And one new tunnel named O for “output”
      • Set its Data Bits property to 4
  4. Connect things up like the image to the right.
    • Watch out for “solder bridges.” This is when two or more pins of a component are joined together by “hidden” wires. You can see them as those “wire intersection” circles on the pins. (This is a problem in real life, too.)

  5. Now test it!
    • Switch to the hand tool (Ctrl+1/Cmd+1) and poke the 0s and 1s in the inputs.
    • Poke the wire coming out of the adder (the one connected to O) to see what’s on that wire.
    • Switch between addition and subtraction with the sub input.
      • See how it’s hooked up to the adder’s carry in, so that it adds a 1 when subtracting?

  6. Poking wires to see their values is sometimes useful but often tedious. So instead, let’s add some probes. You’re trying to make the thing on the right.
    • Duplicate the A, B, and O tunnels.
    • Add three probes from the “Wiring” folder, and connect them to those tunnels.
    • Select all three probes and set their Radix property to Unsigned Decimal.
    • Then select that whole mess, duplicate it, and set the duplicated probes’ Radix to Signed Decimal.
    • Now you can see what values are being added/subtracted, and what the result is, in both the unsigned and signed interpretations! Neat!

Probes are just a debugging tool. They do not have any effect on the circuit, and cannot be used in place of outputs.


2. Detecting unsigned overflow

Unsigned overflow happens if we’re adding (sub == 0) and the carry out from the adder is 1; OR if we’re subtracting (sub == 1) and the carry out is 0. If we make a truth table:

sub Co UOV
0 0 0
0 1 1
1 0 1
1 1 0

This can be done with a single gate! (Look in the “Gates” folder for it.)

Let’s see if you can do it on your own now. Your goal is the picture on the right. Make tunnels as needed. The red circle is an LED from the “Input/Output” folder. Test that it detects overflow for both subtraction and addition.


3. Detecting signed overflow

  1. First, you need to get the sign bits of the operands and output.
    • You can do this with splitters.
    • Make a splitter and set its properties like so:
    • This will make something that looks like a little laser gun with a 3 on it.
      • The black side of the splitter accepts a 4-bit number.
      • The green side will output bit 3 (the MSB) from that 4-bit number.
  2. Now copy and paste that splitter a couple times. You want to get:
    • The MSB of A
    • The MSB of O
    • The MSB of the output of the MUX - important! Not B directly.
  3. Then, using those three sign bits, you have to implement the logic of the Signed Overflow truth table as shown in the Arithmetic and Making Decisions lecture slides. It can be tricky!
    • Maybe think about it like this: “there’s an overflow if the input signs are the same, AND the output sign differs from one of them.
      • One kind of gate outputs 1 if the inputs differ.
      • And if you logically NOT its output, you get 1 if the inputs are the same…
    • Or you can use the Window > Combinational Analysis tool to do it super easy, you CHEATER
      • No it’s not actually cheating ;)

Be sure to test all 8 possible combinations of signs (two inputs and one output)! And when you’re sure it works… you’re done.


Submitting

Once you’re sure your circuit works, you can submit.

Name your circuit file username_lab5.circ, like jfb42_lab5.circ.

Submit here.

Drag your asm file into your browser to upload. If you can see your file, you uploaded it correctly!

You can also re-upload if you made a mistake and need to fix it.