CS 33: Lab #02

CS 33: Computer Organization


LAB 02: Basic Circuits

Due 11:59pm Wednesday, Sept 17

The program handin33 will only submit files in the cs33/lab/02 directory. You should follow the guidelines below in choosing file names for your circuits.

For this second lab, you are encouraged to work with a partner; however, you may work alone if you choose to do so.

Each of these questions should be answered using the logisim program which you run by typing logisim.sh in the terminal window. You can test each of your programs using input and output pins as demonstrated in class. Be sure to save often: although I have never had logisim crash on me midway through designing a circuit, it's better to play it safe and just save often.

Many of the circuits build on one another. For example, you use your result of #2 in #3, your result of #3 in #4, etc. The logisim program will be helpful in identifying various inputs and outputs of the circuits you create only if you label each of your inputs and outputs helpfully... so be sure to fill in the Label field in the properties panel for every circuit you create.

As with any lab, be sure you test your solution by providing a number of different input values to your circuits and validating that your solution matches what you expect.

  1. Sign-extension (section 2.5.2) is an common operation performed inside a CPU. Create a circuit that takes a 4-bit 2's complement number and performs sign-extension so that the output is an equivalent 8-bit 2's complement number. For readability, be sure that any AND or OR gates you use have the appropriate number of inputs. (You can change the number of inputs in the properties panel on the left side after selecting a gate.) Save this file as "sext.circ".
  2. Using either the circuit on page 62 or your own design, create a one-bit full adder. Your full adder should take 3 inputs (A, B, CarryIn) and yield two outputs (Sum, CarryOut). Save this file as "fulladder.circ". Create 3-input AND gates (like the one on p.62) by changing the number of inputs for the gate.
  3. Using your Full Adder (stored in "fulladder.circ"), create a circuit which can add two 4-bit unsigned numbers.

    To use your full adder, you'll first have to load your full adder into the current circuit. To do that, first start a new circuit (File > New). Then, select Project > Load Library > Logisim Library... A dialog window will pop up. Navigate to your cs33/labs/02 directory and choose your fulladder.circ file. A new folder will appear in the top left panel with your full adder circuit in it.

    For now, do not worry about overflow. Save this file as "fulladder4.circ". NOTE: The 4-bit adder you are building adds two unsigned 4-bit values. These are not 2s complement representations. (The only difference has to do with overflow -- the addition is the same either way.)

  4. Using your 4-bit full adder (load it in as a library), create a circuit which adds +1 to its input. You do not need to worry about overflow. Save this file as "incrementer4.circ".
  5. Using your 4-bit incrementer (load it in as a library), create a circuit which negates a 4-bit two's complement number. So, an input of 0001 (+1) would yield an output of 1111 (-1), and an input of 1110 (-2) would yield an output of 0010 (+2). (An input of 1000 will yield 1000. Why?) Save this file as "negater4.circ".
  6. In this question, you will create a counter. We will create the counter in multiple steps. The final file should be called "counter.circ".
    1. Using 4 D flip-flops (you can use the built-in D Flip-Flop found by first loading the built-in Memory library and then choosing D Flip-Flop from the new folder that appears), create a 4-bit register similar to the one shown in Figure 3.20. At this point, do not connect the D inputs, but you should connect each of the Clock inputs together. The book calls the clock inputs "WE"; it looks like a triangle on the left of the flip-flop in logisim.
    2. Highlight the entire register you just created, then Copy, then Paste to make another copy. Place the copies side-by-side so there is one on the left and one on the right, but be sure to leave some space in between them. We'll call the copy on the left the Source register, and the copy on the right the Destination register.
    3. Our first logic step is to take the output of the Source register (the one on the left), send it through our 4-bit incrementer, and then send the output of the oncrementer into the input of the Destination register (the one on the right). This step allows us to add 1 to the value stored in the Source register and store that value in the Destination register.

      Note that the value will not be stored in the Destination register unless the Clock inputs (the Write-Enable inputs) are set to 1. Create an input and connect it to the Clock inputs of the Destination register. (Use the properties of the input to label this "Increment".)

    4. Next, we'll need a way of taking the resulting answer stored in the Destination register and copy it back into the Source register. To do this, take the output of the Destination register and wire it to the input of the Source register. Note again that the value will not copied into the register unless the Write-Enable is set, so wire an input pin to each of the Clock inputs on the Source register and name this input "Copy".
    5. Now, we'll need a way to visualize the result in the Destination register. Hook up appropriate output pins to display the result.
    6. To see the counter in action, click Copy, then Increment, then Copy, then Increment. Each Copy/Increment will cycle will increase the value in the output pins.
    7. Notice that the cycle of Copy/Increment are complementary. That is, you never press both at the same time, and you always press one then the other. Replace the Copy and Increment inputs with a Clock (found under the Base folder). Each 'poke' of the clock causes a single tick (either from 0 to 1, or from 1 to 0 depending on the state of the clock). You can enable continuous ticks of the clock by choosing "Simulate > Ticks Enabled" from the menu bar.
    8. (Extra Credit)Add a Reset input which, when set to 1, sets the Destination register to 0. To do this, you'll probably need to use some multiplexers (found by loading the built-in library called Plexers) to control how the input gets into the Destination register, and you'll need some new way of controlling the Write-Enable gate on the Destination register. This is somewhat tricky, but 15 minutes of thinking about the problem (and then 5 more to wire up a solution) should be all it takes.