Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
-page 1! of 41
!
Report
Table of Contents:
Signed Adder- My signed 8 bit binary adder functions quite similarly to a standard unsigned 8
bit binary adder. In order to create a signed 8 bit binary adder, I first utilized the XOR gate on the
second addend bits coupled with a carry in bit to produce a modified addend. The carry in bit
corresponded to the operation I desired to be performed. If the operation desired was addition,
the carry in bit was 0. If the operation desired was subtraction, the carry in bit was 1. Source
Next, I utilized a series of ripple full adders in order to execute the RTL logic for the
adder. I implemented a full adder using case statements within an always block. The case
statement performs similarly to a truth table. The source code for the logic of the full adder
A and B inputs in the full adder. In the first full adder, I use the proper carry in based on the
desired operation. The source code for the full adders is shown below. FIG.3
Finally, I needed to calculate the signed 7th bit of the signed adder. In order to do
this, I utilized a ternary statement to assign the 7th bit based on whether or not there was
overflow, the desired operation (mode), and a difference in the signs of the two addends. The
statement is crucial because it decides whether or not the sum is positive or negative. The source
assign result[7] = (!overflow2 && isOneNegative && !mode) || (overflow2 && !isOneNegative && !mode) || (!
overflow3 && isOneNegative && mode) || (overflow3 && !isOneNegative && mode) ? 1'b1 : 1’b0;
I now have all of the bits necessary for the signed adder to be fully operational.
Signed Multiplication- My signed truncated binary multiplier utilizes Booth’s algorithm for
signed binary multiplication in order to meet functionality standards. Booth’s algorithm gives a
procedure for multiplying binary integers in signed 2’s complement representation in efficient
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page 4! of 41
!
way, i.e., less number of additions/subtractions required. It operates on the fact that strings of 0’s
in the multiplier require no addition but just shifting and a string of 1’s in the multiplier from bit
weight 2^k to weight 2^m can be treated as 2^(k+1 ) to 2^m. Booth’s algorithm requires
examination of the multiplier bits and shifting of the partial product. Prior to the shifting, the
multiplicand may be added to the partial product, subtracted from the partial product, or left
assignment operator in order to determine which operation to perform on the partial product prior
to shifting. Source code for the ternary assignment operator is shown below. FIG.5
In order to receive the final correct answer, I needed to have eight of these ternary
assignment “if-else” operators. A figure describing process should be shown below [1]. FIG.6
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page 5! of 41
!
Unfortunately, this means that I must compute the entire 16 bit product in order to
algorithm for a truncated signed algorithm is a better solution than utilizing a Wallace Tree or
any other implementation that only computes the most significant 8 bits because:
2. The code itself is much more organized into 8 identical ternary operators instead of 64
“AND” gates
Since my implementation of the signed multiplier computes all 16 bits, I retrieved only
the most significant 8 bits in order to determine my final product. If you would like a more in
depth explanation of Booth’s algorithm, I would suggest perusing the wikipedia page on the
subject: https://en.wikipedia.org/wiki/Booth%27s_multiplication_algorithm
Dataflow Diagrams
Before drawing my first data flow diagram, I calculated the minimum number of
adders and multipliers necessary for the entire computation. According to the project guidelines,
in order to receive all of the inputs, 12 clock cycles are necessary. Additionally, 4 more clock
cycles are required to compute the f output vector. Therefore, the total number of clock cycles
necessary and 8 additions will be necessary due to each input and output vector being made of 4
indices. I can now determine the minimum number of adders and multipliers necessary. FIG.7/8
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page 6! of 41
!
Since I now know the minimum number of multipliers and adders, I can create a
allowed to have is 15 clock cycles. In FIG.9, it is clear that it will require 16 clock cycles for the
program to reach its final output from the first input. Therefore, FIG.9 is an incorrect data flow
diagram. In order to meet specifications, I will need to increase the number of adders and/or
multipliers I am using. Upon inspection of FIG.9, it is evident that if I had 2 adders instead of 1, I
could decrease the maximum number of clock cycles necessary because I could compute F1 after
E1 is computed (in clock cycle 10). Therefore, I will now create a new data flow diagram that
In the above data flow diagram of FIG.10, the number of clock cycles from first
input to final output is 13 clock cycles. Therefore, the latency of the FIG.10 diagram is 13 clock
cycles. Since the FIG.10 data flow diagram is below the maximum 15 clock cycles, I will be
Resource Scheduling
was 1 adder and 1 multiplier. Therefore, I created a resource scheduling chart that utilized 1
cycles for the data path to extend from the first input of A1 to the final output of F4.
Additionally, the initiation rate is 8 clock cycles because the minimum number of clock cycles
between the first input of 1 test vector and the first input of the next test vector is 8 clock cycles.
Unfortunately, this does not meet specifications because of the fact that the maximum latency we
are allowed to have is 15 clock cycles. In FIG.9/10 above, I determined from the data flow
diagram that having 2 adders and 1 multiplier allows the latency to reach 13 clock cycles, which
is below the maximum number of clock cycles allowed. Therefore, I will need to create a second
the data path to extend from the first input of A1 to the final output of F4. Additionally, the
initiation rate is 4 clock cycles because the minimum number of clock cycles between the first
input of 1 test vector and the first input of the next test vector is 4 clock cycles. Since this does
meet specifications, I will be attempting to use the resource management in FIG.12 for the
Datapath Inputs/Outputs
Datapath Diagram
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !11 of 41
!
Controller Inputs/Outputs
Controller ASM
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !12 of 41
!
Test Vector Criteria
1. (First Vector) For my first test vector, I simply chose the decimal value of 1 (8’b00000001)
for each input vector. The result of every input having the decimal value of 1 is easy to
compute in one’s head (the result should be zero). Therefore, I use my first test vector to
make sure all of the values of a1-4, b1-4, and d1-4 are all producing the same result.
2. (Vectors 2/3) For my second and third test vector, I chose values that were all positive and
large for my inputs (Ex: 8’b01110111). The large positive numbers would demonstrate that
3. (Vectors 4/5) For my fourth and fifth test vector, I chose values that were both negative and
small (8’b11111101). The small negative numbers would demonstrate that my multiplier is
4. (Vectors 6/7) For my sixth and seventh test vector, I chose values that are negative and large
(Ex: 8’b10000011). The large negative values demonstrate the my multiplier can handle large
signed negative values and that my adder can handle negative signed overflow.
5. (Vectors 8/9) For my eighth and ninth test vector, I chose values that were either large and
negative with small positive numbers or large and positive with small negative numbers. This
demonstrates that my multiplier can multiply when the signs of the multiplier and the
6. (Tenth Vector) The final test vector is made of random 8 bit signed binary numbers in order to
make sure that there were not any potential corner cases that I overlooked.
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !13 of 41
!
Problems Encountered
Early on, I had a lot of trouble determining how to create a signed binary 8 bit
multiplier. I had looked at multiple online sources in my attempt to determine how to create a
signed binary multiplier. My first attempt at creating the binary multiplier utilized 64 “AND”
gates. Unfortunately, I ended up creating an unsigned binary multiplier instead of a signed binary
multiplier. I could not find an easy way to modify this unsigned multiplier to be signed;
therefore, I gave up on the “AND” gate implementation. Next, I tried creating a Wallace Tree.
The implementation of the Wallace Tree was also quite difficult for me because it contained so
many gates that I could not keep track of. Finally, the implementation that allowed me to create
the signed multiplier was the implementation of Booth’s algorithm. I used several online sources
that explained Booth’s algorithm to facilitate my design. Each iteration of the multiplier took
several hours if not several days to implement, which unfortunately reduced the amount of time I
Functionality Claims
This project took a longer time than I ever expected it would. Alone, I believe I spent at
least 15 hours in the creation of my signed multiplier, 3 hours in the creation of my signed adder,
and 10 hours in the creation of my data path. I was able to get my signed multiplier working
correctly, my signed adder working correctly, and my data path working with 2 adders and
multiplier. Additionally, my data path meets spec by completing the vector in only 13 clock
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !14 of 41
!
cycles. Unfortunately, I did not get time to test my data path with more than 4 vectors, though I
am highly confident that it would work with any inputs as my 4 test vectors thoroughly ended up
covering all potential test cases for my signed adder and signed multiplier.
Additionally, I did not get the chance to create a top module nor controller in Verilog as
I simply did not have time to since I spent so long making sure that my data path and multiplier
Summary of Claims
1. Signed Adder and Signed Multiplier function perfectly under all test vectors
2. Data path functions correctly by utilizing 2 adders and 1 multiplier (see data path and
3. Data path meets spec due to latency only reaching 13 clock cycles at a maximum
4. NO top module nor controller as I simply did not have time. I have worked very hard on this
project and wanted to make sure everything that I completed was accurate. A theoretical
Timing Analysis
I was not able to determine timing for my model since I did not complete the top module
output Cout ;
output S ;
input clk;
input A ;
wire A ;
input B ;
wire B ;
input Cin ;
wire Cin ;
reg Cout;
reg S;
case ({A,B,Cin})
endcase
end
endmodule
module addsub8 (
output overflow ,
input [7:0] A ,
input [7:0] B ,
input mode ,
input clk
);
wire isOneNegative;
wire B0;
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !17 of 41
!
wire B1;
wire B2;
wire B3;
wire B4;
wire B5;
wire B6;
wire B7;
wire C0;
wire C1;
wire C2;
wire C3;
wire C4;
wire C5;
wire C6;
wire C7;
fa U0(A[0],B0,mode,C0,result[0], clk);
fa U1(A[1],B1,C0,C1,result[1], clk);
fa U2(A[2],B2,C1,C2,result[2], clk);
fa U3(A[3],B3,C2,C3,result[3], clk);
fa U4(A[4],B4,C3,C4,result[4], clk);
fa U5(A[5],B5,C4,C5,result[5], clk);
fa U6(A[6],B6,C5,C6,result[6], clk);
wire temp;
fa U7(A[7],B7,C6,C7,temp, clk);
xor v9(overflow,C5,C6);
wire overflow2;
wire overflow3;
assign result[7] = (!overflow2 && isOneNegative && !mode) || (overflow2 && !isOneNegative
&& !mode) || (!overflow3 && isOneNegative && mode) || (overflow3 && !isOneNegative &&
output busy;
reg [7:0] A, Q, M;
wire [7:0] A2, Q2, A3, Q3, A4, Q4, A5, Q5, A6, Q6, A7, Q7, A8, Q8, A9, Q9;
reg Q_1;
wire [7:0] sum, difference, sum2, difference2, sum3, difference3, sum4, difference4, sum5,
begin
if (start) begin
A = 8'b0;
M = mc;
Q = mp;
Q_1 = 1'b0;
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !20 of 41
!
count = 4'b0;
end
else begin
end
end
assign {A3, Q3, Q_3} = (Q2[0] && !Q_2) ? {difference2[7], difference2, Q2} :
assign {A4, Q4, Q_4} = (Q3[0] && !Q_3) ? {difference3[7], difference3, Q3} :
assign {A5, Q5, Q_5} = (Q4[0] && !Q_4) ? {difference4[7], difference4, Q4} :
assign {A6, Q6, Q_6} = (Q5[0] && !Q_5) ? {difference5[7], difference5, Q5} :
assign {A7, Q7, Q_7} = (Q6[0] && !Q_6) ? {difference6[7], difference6, Q6} :
assign {A8, Q8, Q_8} = (Q7[0] && !Q_7) ? {difference7[7], difference7, Q7} :
assign {A9, Q9, Q_9} = (Q8[0] && !Q_8) ? {difference8[7], difference8, Q8} :
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !23 of 41
!
((!Q8[0] && Q_8) ? {sum8[7], sum8, Q8} :
endmodule
module datapath(f1, f2, f3, f4, a1, a2, a3, a4, b1, b2, b3, b4, d1, d2, d3, d4, ld, clk, start);
input [7:0] a1, a2, a3, a4, b1, b2, b3, b4, d1, d2, d3, d4;
input start;
reg [7:0] c1, c2, c3, c4, e1, e2, e3, e4;
reg[3:0] count;
wire o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12;
wire[7:0] tempWire;
wire[7:0] addResult;
wire[7:0] addResult2;
begin
if (start)
begin
mc <= a1;
mp <= b1;
end
begin
mc <= a2;
mp <= b2;
end
begin
mc <= a3;
mp <= b3;
c1 <= multResult;
end
begin
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !26 of 41
!
mc <= a4;
mp <= b4;
c2 <= multResult;
end
begin
c3 <= multResult;
end
begin
e1 <= addResult;
c4 <= multResult;
end
begin
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !27 of 41
!
ad1 <= c3;
e2 <= addResult;
end
begin
f1 <= addResult2;
e3 <= addResult;
end
begin
e4 <= addResult;
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !28 of 41
!
f2 <= addResult2;
end
begin
f3 <= addResult2;
end
begin
f4 <= addResult2;
end
begin
end
end
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !29 of 41
!
endmodule
Appendix 2 (Testbenches)
module datapathfinal_tb();
reg [7:0] a1, a2, a3, a4, b1, b2, b3, b4, d1, d2, d3, d4;
datapath U1(f1, f2, f3, f4, a1, a2, a3, a4, b1, b2, b3, b4, d1, d2, d3, d4,ld, clk, start);
initial
begin
start = 1'b1;
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !30 of 41
!
clk = 1'b0;
ld = 1'b1;
#10;
a1 = 8'b01000000;
#10;
start = 1'b0;
clk = 1'b0;
#10;
a2 = 8'b11111111;
#10;
clk = 1'b0;
#10;
a3 = 8'b01111111;
#10;
clk = 1'b0;
#10;
a4 = 8'b01010011;
#10;
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !31 of 41
!
clk = 1'b0;
#10;
b1 = 8'b1010001;
#10;
clk = 1'b0;
#10;
b2 = 8'b10011000;
#10;
clk = 1'b0;
#10;
b3 = 8'b01001000;
#10;
clk = 1'b0;
#10;
b4 = 8'b10011111;
#10;
clk = 1'b0;
#10;
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !32 of 41
!
clk = 1'b1; // Ninth clock D(1)
d1 = 8'b10011000;
#10;
clk = 1'b0;
#10;
d2 = 8'b10011110;
#10;
clk = 1'b0;
#10;
d3 = 8'b10011111;
#10;
clk = 1'b0;
#10;
d4 = 8'b00111111;
#10;
clk = 1'b0;
#10;
#10;
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !33 of 41
!
clk = 1'b0;
#10;
#10;
clk = 1'b0;
#10;
clk = 1'b1;
End
Endmodule
module signed_adder_tb();
reg [7:0] A, B;
reg mode;
reg clk;
wire overflow;
initial
begin
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !34 of 41
!
#10;
clk = 1'b0;
mode = 1'b0;
#10;
clk = 1'b1;
A = 8'b11111111;
#10;
clk = 1'b0;
#10;
clk = 1'b1;
A = 8'b10000000;
#10;
clk = 1'b0;
#10;
clk = 1'b1;
A = 8'b10110000;
#10;
clk = 1'b0;
#10;
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !35 of 41
!
clk = 1'b1;
A = 8'b00111100;
#10;
clk = 1'b0;
#10;
clk = 1'b1;
A = 8'b00001000;
B = 8'b00010000;
#10;
clk = 1'b0;
#10;
clk = 1'b1;
A = 8'b01010000;
#10;
clk = 1'b0;
#10;
clk = 1'b1;
A = 8'b11111011;
B = 8'b11110110;
#10;
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !36 of 41
!
clk = 1'b0;
#10;
clk = 1'b1;
A = 8'b11111111;
#10;
end
endmodule
module testbench;
reg [7:0] a, b;
wire busy;
initial begin
clk = 0;
#10;
clk = 1'b1;
start = 1'b1;
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !37 of 41
!
a = 8'b11111111;
b = 8'b11111111;
#10;
clk = 1'b0;
#10;
clk = 1'b1;
a = 8'b01111111;
b = 8'b01111111;
#10;
clk = 1'b0;
#10;
clk = 1'b1;
a = 8'b10000000;
b = 8'b10000000;
#10;
clk = 1'b0;
#10;
clk = 1'b1;
a = 8'b10110110;
b = 8'b01100100;
end
endmodule
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !38 of 41
!
Appendix 3 (C++ Signed Binary Adder Verifier)
/C++ program
#include<iostream>
for(int i=31;i>=0;i--){
cout<<arr[i];
cout<<"\n";
if(n<0)n*=-1;
int i=0;
while(n){
arr[i++]=n%2;
n/=2;
int i=0;
while(arr[i]!=1){
i++;
i++;
for(;i<32;i++){
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !39 of 41
!
if(arr[i]==0)arr[i]=1;
else if(arr[i]==1)arr[i]=0;
int carry=0;
int s;
for(int i=0;i<32;i++){
s=num1[i]+num2[i]+carry;
sum[i]=s%2;
carry = s/2;
int main(){
int n1,n2;
cin>>n1;
cin>>n2;
int num1[32],num2[32],sum[32];
for(int i=0;i<32;i++){
num1[i]=0;
num2[i]=0;
sum[i]=0;
}
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !40 of 41
!
binary(n1,num1);
binary(n2,num2);
if(n1<0)twocomp(num1);
if(n2<0)twocomp(num2);
Add(num1,num2,sum);
else {
cout<<"\nnum1 : ";
display(num1);
cout<<"\n\n";
cout<<"\nnum2 : ";
display(num2);
cout<<"\n\n";
cout<<"\nSum : ";
display(sum);
cout<<"\n";
return 0;
}
Adam Christa 47362657 ECE 5387 Digital Systems Design Final Project Report 12/10/19
-page !41 of 41
!
References:
[1] https://www.geeksforgeeks.org/computer-organization-booths-algorithm/
[2] https://electrotrick.wordpress.com/2017/09/24/booth-algorithm-multiplication/