Lab 4

CprE 305

An adder is a simple, basic component of a microprocessor. A 1-bit adder takes 3 inputs and produces two outputs. The inputs are the two operands and the carry-in. The outputs are the sum and carry out.

Here are the formulas for the 1-bit adder: Notice the equations for Carry-out. They are all equivalent.

            Sum = a Å b Å carry-in = (a Å b) Å carry-in

            Carry-out = (a*b) + (a*carry-in) + (b*carry-in) = (a*b) + (a + b) *carry-in = (a*b) + (a Å  b) *carry-in

(where Å is the symbol for exclusive or).

 

1. Write the Verilog code for a 1-bit adder.

2. Test the code and show the result to the TA. Your test should show the output for all possible combinations of the inputs.

3. Write the Verilog code for a 16-bit adder, by cascading 1-bit adders. Test the code for the following inputs:

            (0 + 0), (1 + -1), (1 + 1), and (-1 + -1)

Show the results to the TA.

4. Write the Verilog code for a 4-bit 1's complement adder. The numbers are given in 4 bits1's complement. You add the operands and bring the Carry-out bit from the MSB around to become the carry for the 1st bit. Verfify that the result is correct by adding 4 combinations of 5 and 2 (both +ve and -ve). 

* Be sure you utilize the Verilog tutorial on the web. As always, your design should not only WORK, but also it should work EFFICIENTLY. You should use data types in this lab that are more than 1 bit wide.