submit hw4-2
This is not a partnership assignment -- hand in your own work, and don't collaborate with anyone else.
a b cin s cout
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
Inspecting the table, we see that s is 1 if and only if the number of 1's in the input is odd. We may recognize this as the xor of a, b, and cin. The carry-out signal is also an easily recognizable function. It is the majority function: cout takes on the value of the majority of its inputs. As a Boolean function, cout = ab + acin + bcin. This function says that the output cout is 1 if at least two of its inputs are 1.
module add4 (A, B, R, overflow);
input [3:0] A,B;
output [3:0] R;
output overflow;
Your test-bench should print out the adder input and output values, and the expected output values. For this exercise, it is simplest to display, specify in your test-bench, and print your input and output values all in binary instead of decimal. Debug and verify the correct operation of your adder with at least the following test cases:
a) 0 + 0
b) 1 + (-1)
c) positive + positive (without overflow)
d) positive + positive (with overflow)
e) positive + negative
f) negative + positive
g) negative + negative (without overflow)
h) negative + negative (with overflow)
iverilog -tvvp -Wall -o outputfile.vvp inputfile.vOption -tvvp indicates that the output is a complete program that simulates the design but must be run using the command vvp. By convention, we name the output file with extension vvp. After your modules compiles sucessfully, you can simulate the design with the following command:
vvp file.vvpFor more information on iverilog and vvp, try man verilog and man vvp.