EER-018 Laboratory #4
Design and Simulation of an Adder/Subtractor Circuit

Objective

In this lab you will use MSI devices in the MAX+plus II library as well as primitive gates to implement an adder/subtractor circuit.
 

Equipment

Prelab

Recall that in 2's complement representation, all negative numbers start with a 1, and positive numbers start with a 0.
  1. Fill in the missing entries in the table below with the signed decimal equivalent of each 4-bit 2's complement number.
  2. 2's complement decimal 2's complement decimal
    0000 0 1000 -8
    0001   1001  
    0010   1010  
    0011   1011  
    0100   1100  
    0101 5 1101 -3
    0110   1110  
    0111   1111  
    Table 1. 4-bit 2's complement numbers

    An adder/subtractor circuit will add or subtract 2's complement binary integers and produce a correct 2's complement result. The value of a single control signal, we will call add_sub, determines whether addition or subtraction is performed. Some examples for 4-bit numbers are shown below.

    Addition
        3 0011   -7   1001   -7   1001                        7   0111
       +2 0010   +6   0110  +-8   1000                      +-6   1010
        - ----   -- ------   -- ------                       -- ------
        5 0101   -1   1111  -15 1 0001(result overflows)      1 1 0001
    Subtraction
        3 0011    7   0111   -7   1001     7   0111
       -6 0110   -6   0110  --8   1000   --6   1010
        - ----   -- ------   -- ------    -- ------
       -3 1101    1   0001    1 1 0001    13 1 0001(result overflows)
    Notice that whenever the result of an operation produces a number larger than 7 or smaller than -8, there is an overflow because these numbers cannot be represented in 4-bit 2's complement.

    To design the adder/subtractor circuit we will use the basic idea that

    A - B = A + (-B)
    Therefore, we will accomplish subtraction by simply adding the negative of the second number. The negative of B will be implemented using the 2's complement.

    The 7483A Adder is a 4-bit adder that we will use to design the adder/subtractor circuit. Figure 1 is a top level block diagram of the adder/subtractor circuit and the function table that defines the add_sub control signal. When add_sub=1, the plus/minus block generates the 1's complement of B and the carry in (CI) is one. This converts B to -B. When add_sub=0, the plus/minus circuit does not change B, and CI=0.

    Figure 1. Adder/Subtractor Block Diagram
  3. Using the truth table for plus/minus, find the expression for Bpm(i) as a function of B(i) and the add_sub input.
  4. Using this equation, draw the logic for the "plus/minus" block. Make use of XOR gates to reduce the number of gates required.

Procedure

Enter Circuit

  1. Using the block diagram that you produced in for the prelab as a guide, enter the adder/subtractor circuit. Use the following hints:

Test the Circuit

Create waveform file:
  1. Using the procedure from Lab #2, create a waveform file to test your circuit. Group the signals so that you have A[3..0], B[3..0], add_sub, F[3..0] and Cout signals.
  2. Since this circuit has many more inputs than the circuit in Lab #2, we will have to run the simulation much longer to test it. Choose "File - End time" and set the end of simulation to 3.2us.
  3. First we will generate inputs using a simple method of assigning count sequences.
 
add_sub A input B input F  expected (hex) F  actual (hex) F (decimal)
0 0 F      
0 1 E      
0 2 D      
0 3 C      
1 0 F      
1 1 E      
1 2 D      
1 3 C      
 
  1. What is the total number of tests that would be applied if all combinations of the 9 inputs were applied?___________ Give the formula for the number of test combinations (T) in terms of the number of inputs (I).
  2.  Notice that although it was easy to create the test vectors in the previous test, not all cases (negative + negative, positive + positive, positive - negative, etc) were tested.
  3. To enter different simulation values, follow this procedure:
  4. Bring up the simulator and  test the circuit for the following input combinations and record the results. Indicate whether there was an overflow or not.
  5. Print the waveform.

  6.  
    add_sub
    A input
    B input
    F (hex)
    F (decimal)
    Overflow?
    0
    0
    3
     
     
     
    0
    5
    5
     
     
     
    0
    -6
    3
     
     
     
    0
    -4
    -3
     
     
     
    0
    -2
    -7
     
     
     
    1
    3
    4
     
     
     
    1
    7
    5
     
     
     
    1
    -3
    7
     
     
     
    1
    7
    -3
     
     
     
    1
    -1
    -7
     
     
     
    Table 2. Simulation Results

Simulation of 8-bit Adder-subtractor


In this section we will examine an 8-bit  version of the adder-subtractor circuit. This circuit has already been constructed for you.

Examine the 8-bit circuit

  1. Choose "File - Open" and navigate to the  c:\EE18\Lab3  folder.
  2. Open the add_sub8.gdf file. Notice that it is composed of two 4-bit add_sub components.
  3. Double-click on one of the add_sub components to examine the internal structure of the component.
  4. How does this 4-bit circuit differ from the circuit that you designed?
  5. Why is this modification necessary to create the 8-bit version?
Simulate the 8-bit circuit
  1. To prepare for simulation, choose "File - Project - Set Project to Current File".
  2. Now compile the circuit.
  3. Follow the procedures in this lab for simulating the circuit. Here are some hints:
  4. Fill in the values that you get for the following input cases.
  5. Print the waveform results.
  6. If you save the waveform, be sure to save it on your floppy disk, and not on the hard drive. If you accidentally save it (the add_sub8.snf file) to the hard drive, be sure to remove it so that the next lab section can have the joy of creating it.
     
    add_sub
    A input
    (decimal)
    A input 
    (hex)
    B input
    (decimal)
    B input 
    (hex)
    F (hex)
    F (decimal)
    Overflow?
    0
    0
    0
    17
     11
     
     
     
    0
    95
    5F
    59
     3B
     
     
     
    0
    -68
    BC
    32
     20
     
     
     
    0
    -44
    D4
    -13
     F3
     
     
     
    0
    -99
    9D
    -79
     B1
     
     
     
    1
    33
    21 
    44
     2C
     
     
     
    1
    79
     4F
    56
     38
     
     
     
    1
    -39
     D9
    79
     4F
     
     
     
    1
    27
     1B
    -39
     D9
     
     
     
    1
    -100
     9C
    -7
     F9
     
     
     
     

Report