CS 202 - Homework 6 - 10/19/05

Due: Monday, 10/29/07, in class (or by 2pm the latest)

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. I only need one submission per group. Your submission should include printouts of all circuits and subcircuits. The printout of your top-level circuit should be a snapshot demonstrating that your circuit works, i.e., the displays should show the product of the two numbers entered on the keyboards.

On your submission, please write down how much time it took you.

Detailed instructions

In your circuit, you may only use the following parts: The circuit is composed of the following parts:
  1. One 5-bit and one 4-bit shift register
  2. One 4-bit adder
  3. Two hex keyboards and two hex displays
  4. Control circuitry, consisting of
    1. a clock
    2. four JK Flipflops
    3. various AND and OR gates

Shift registers

Start by implementing a 1-bit shift-register subcircuit using a JK flip flop:
   inputs:  D, Ld,  Si, Shift,  Clk,  Reset
   output:  Q (= Q of flipflop)

   inputs of JK flipflop:
     J = (D and Ld) or (Si and Shift)
     K = ((not D) and Ld) or ((not Si) and Shift) or Reset
     C = Clk
     S = 0
     R = 0
Then, construct a 4-bit shift register subcircuit from four of your 1-bit shift registers. Connect the output Q of one register to the shift-in input Si of the next. Only the "leftmost" Si input should be visible to the outside. All other control inputs should be connected to each other. Overall, your 4-bit shift register should have the following connectors:
   inputs:  D3, D2, D1, D0,    Ld,  Si, Shift,  Clk,  Reset
   outputs: Q3, Q2, Q1, Q0
In your main circuit, you will need a 4-bit and a 5-bit register. It is cleanest to create another subcircuit for a 5-bit register, but if you just want to hook up a 1-bit register to a 4-bit register, that's ok too (as long as you can lay it out in a reasonably clean way).

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 is connected to the CarryOut output of the adder.
Two hex keyboards will be used to enter the two numbers A and B to be multiplied. Use the keyboards with strobe output (i.e., the ones with an extra pin at the bottom). This strobe output creates a short "1"-pulse when a key is pressed, which we will use to start the multiplication process.

Let's call the 9 outputs of the shift registers Q8..Q0, left-to-right. We will ignore output Q8. Outputs Q7..Q4 form 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 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 Clk inputs of all flipflops to a common clock. The picture below shows a useful clock circuit constructed from a "SPDT Pushbutton", a clock, and a "SPDT Switch" (all from "Simulation IO.clf").
This circuit lets you step the clock manually (for debugging), or continuously. Note that you will have to add the numbers "1" and "0" by hand. Since LogicWorks's JK flipflops are negative edge-triggered, you should put the "1" at the top.

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    
        ShiftA  0   0  1  0  1  0  1  0  1     0    
        ResetA  1   0  0  0  0  0  0  0  0     0     

        LdB     1   0  0  0  0  0  0  0  0     0     
        ShiftB  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: SiB = Q4. The other control inputs have constant values: SiA = 0, ResetB = 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 start the counters when a key is pressed, we combine the strobe outputs of the two keyboards with an OR: start = (StrobeA or StrobeB), and use this signal to (asynchronously) set and reset the correct flipflops:
        S0 = start    S1 = start    S2 = start      S3 = 0
        R0 = 0        R1 = 0        R2 = 0          R3 = start      
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, ShiftA, ShiftB, and resetA from C0, C1, C2, C3. This is easy and left to you :)

General remarks