CS 202 - Homework 6

Due: Monday 4/9, at the beginning of class

The goal of this homework is to build a sequential circuit that implements a 4-bit multiplier. Details are included below and will also be discussed in class. You may work in groups of two, or by yourself if you prefer. If you choose to work in a pair, you should perform pair programming, that is, share a single computer and always work together. Each person must contribute equally.

Detailed instructions

Save your circuit in a file hw6.circ. In your circuit, you may only use the following parts:

The circuit is composed of the following parts:

Shift registers

Logisim's shift register unfortunately doesn't have labels on the pins. A 5-bit shift register (with Data Bits = 1, Number of Stages = 5, and Parallel Load = Yes) looks as follows:

Properly labeled, it would look like this:

This register stores 5 bits, which are displayed inside the rectangle and appear at the outputs q4..q0. The unlabeled output pin (let's call it "out") on the right edge is the same as q0. The register also has 5 data inputs d4..d0 at the top and the shift input "in" on the left. Finally, it has 3 control inputs ld, sh, clr, as well as a clock input. Upon receiving a clock tick it operates as follows:

In your main circuit, you will need a 4-bit and a 5-bit shift register. If you want, you can add labels manually (or define larger subcircuits with labels), but it's also fine to use the register unlabeled.

Overall structure

The high-level structure of the multiplier circuit is shown below. The arrows in this picture represent multiple wires (4 or 5) in most cases. The left shift register has 5 bits: its leftmost input (d4) is connected to the carry output of the adder.

Two 4-bit pins will be used to enter the two numbers A and B to be multiplied. Let's call the 9 outputs of the shift registers q8..q0, left-to-right. We will ignore output q8. Outputs q7..q4 from the left shift register loop back into one set of inputs to the adder.

The two shift registers initially hold the numbers 0 and B, and in the end hold the 8-bit product Y = A*B. The following sequence is executed four times to compute the product:

  1. If the right-most bit (q0) is set, add A3..A0 to q7..4
  2. Shift everything one bit to the right, i.e., q8..1 -> q7..0

Control circuitry

We will use a synchronous design, and connect the clock inputs of all flipflops to a common clock signal "clk". The picture below shows a useful clock circuit constructed from a button, a clock, an OR gate, and a tunnel with label clk.

This circuit lets you step the clock manually (for debugging), or continuously (Simulate -> Ticks Enabled).

The whole multiplication sequence consists of 9 steps. The necessary control signals for each step are shown below (the letters A and B refer to the left and right shift registers, respectively):

        step:  i   0  1  2  3  4  5  6  7    (done)
        ldA    0   X  0  X  0  X  0  X  0     0    
        shA    0   0  1  0  1  0  1  0  1     0    
        clrA   1   0  0  0  0  0  0  0  0     0     

        ldB    1   0  0  0  0  0  0  0  0     0     
        shB    0   0  1  0  1  0  1  0  1     0     

In this diagram, "i" is the initialization step, and steps 0..7 perform adding and shifting. "X" is 1 or 0 depending on whether or not A should be added to the current sum in the shift register. This depends on the rightmost bit, so X = q0. The two shift registers are connected so that bit 4 gets shifted into bit 3: inB = outA = q4. The other control inputs have constant values: inA = 0, clrB = 0.

To create the 9 states in sequence, we need a counter with at least 4 bits. We use four JK flipflops with outputs c0, c1, c2, c3. A clever encoding of states is to start counting at 7:

        step:  i   0  1  2  3  4  5  6  7    (done)

          c0   1   0  1  0  1  0  1  0  1     0
          c1   1   0  0  1  1  0  0  1  1     0
          c2   1   0  0  0  0  1  1  1  1     0
          c3   0   1  1  1  1  1  1  1  1     0

               7   8  9 10 11 12 13 14 15     0

To set everything in motion, we add a button to create a "start" signal, and use this signal to (asynchronously) set c0, c1, c2 (using input "1") and reset c3 (using input "0"). The "0" and "1" inputs are at the bottom edge of Logisim's JK flipflop; you can leave the other inputs unconnected.

The J and K inputs for flipflops 1-3 are the usual inputs for synchronous counters:

        J1, K1 = c0  
        J2, K2 = c0 AND c1
        J3, K3 = c0 AND c1 AND c2

For flipflop 0, however, we need to ensure that we stay in the "done" state (all flipflops = 0) once the product has been computed, and don't start over again. This can be achieved by setting

        J0 = c3
        K0 = 1

The only thing that remains to be done is to derive the equations for the control signals ldA, ldB, shA, shB, and clrA from c0, c1, c2, c3. This is easy and left to you :)

General remarks

Electronic submission

Once your circuit works and you've tested it thoroughly, submit both the .circ file for your circuit, and a PDF file containing screen shots of the top level circuit and all subcircuits (if you have defined any - which is not required). Before taking screen shots, be sure that each circuit is labeled with your name(s) and the circuit's function. If you define subcircuits, make sure you label all pins.

Note that I don't need to see the internals of your adder circuit - just make sure it functions correctly and that the top-level appearance looks good (i.e., has labeled pins). Be sure that your adder is contained in the circuit you are submitting - to be safe, copy your hw6.circ file to a new folder and make sure it still works before submitting. If you have loaded your adder circuit as a library, then you need to submit this circuit as well so we can test everything. In that case, please save your circuit from HW 5.2 as "adder.circ" and load it under this name as a library from your circuit hw6.circ. Again, please copy both files hw6.circ and adder.circ into a new folder and test that everything works when you open hw6.circ in Logisim.

The screenshot of your top-level circuit should demonstrate that your circuit works, i.e., your (unsigned decimal) probes should show the two 4-bit input numbers as well as their 8-bit product. Copy and paste your screenshot(s) into an editor, then save the whole thing in PDF. Please don't take full-screen screenshots, but only grab the relevant region.

Upload your files hw6.circ and hw6.pdf, and (if needed) adder.circ, using the HW 6 submission page by the beginning of your class section on the due date. As always, make sure your files contain your name and section, and that everything is properly documented. If you work in a pair, only one person should submit the files.