For our exercises this week, we'll be working with a few different modeling
styles, focused around a 4-bit full adder. We'll be working with a model
where the 1 bit full adder circuit is explicitly defined, and break that down
into half adders, behavioral and structural models.
The full adder circuit can be constructed from 1-bit half adder circuits.
The truth table for the half adder is as follows.
A B | S Cout
=========
0 0 | 0 0
0 1 | 1 0
1 0 | 1 0
1 1 | 0 1
=========
S = A xor B
Cout = A and B
Two of these cells, plus an additional OR gate, can be used to implement a
full adder. The S output of the first half adder cell is connected to the
input of the second cell, as is the Cin. The S output of the second cell is
the sum S. The Cout is computed by ORing the Cout of both cells.
Likewise, the truth table for the Full Adder is as follows, for reference.
Cin A B | 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
================
To do
0) Copy the full adder codes below to files in your working directory.
Be sure to copy a makefile to the directory.
0.a) mkdir a new directory for this example. name it something useful, such as "adder_exercise"
0.b) create a new file for each verilog module, in the form modulename.v where module name is the name of the module. We'll need full_adder.v, full_adder_4bit.v, add test_adder.v.
0.c) copy and paste the code for each module into the file. be sure that anything in the file that isn't verilog code is commented out.
0.d) if your in the vm, type copymake.sh into the command line to copy a makefile into your working directory
1) Change the values of the makefile to test the full adder.
1.a) Change the line SRC and TESTBENCH to include only the .v files created earlier. if you need to add a new source to a project, add it to your makefile as well.
2) Verify the full adder works by simulation.
3) Write a description of the half adder, at gate level
4) Write a full adder description, using the half adders you wrote in step
3. Give this full adder module a different module name than the provided
model.
5) Write a 4 bit full adder module using the new 1 bit full adder. Be sure to
give it a module name different than the name of the provided module.
6) Take a break if you feel needed...or keep on coding
7) Write a 4 bit full adder module using the new 1 bit full adder from step 6.
Be sure to give it a module name different than the name of the provided
module.
8) One last adder - Write a 4 bit behavioral adder module. Use 4 bit inputs
and outputs in this module. Again, give it a new name.
9) Add the new models to the makefile.
-half adder
-full adder from half adders
-4 bit full adder from step 5
-full adder from step 6
-4 bit full adder from step 7
-4 bit full adder from step 8
9) Modify the testbench to instantiate the new modules. You'll need to
instantiate the 4 bit full adder from step 5, step 7 and step 8. This is why
they all need to have unique module names. You'll need to add three 4 bit
wires for connecting the sum output of these new adders, as well as
three 1 bit wires for connecting the cout output of these new adders.
10) Simulate and verify all of the models behave the same way.
Once this is done, and you have simulated the adders and shown that they all
behave the same way, you'll have built the following types of modules
- Structural Model (step 5)
- Behavioral & Hierarchical Model (step 7)
- Behavioral Model (step 8)
After that is done, people are encouraged to take the ALU presented in the
slides and are encouraged to expand the functionality of the ALU to 8 total
functions. The functions that should be added to the ALU are as follows:
- r = ~A (R equals the complement of A)
- r = A ^ B (R equals A xor B)
- r = A <<B(RequalsAleftshiftedBbits)
After this functionality has been added to the ALU model, the test bench used
for the 4 bit full adder can be modified to simulate the ALU.
Steps to do this
0) Copy the test bench and makefile to your working directory
1) Add/remove wires and regs as needed
2) Replace the DUT with the ALU
3) Expand the inputs in order to test all of the ALU functions.