My exercise was to modify a testbench code to perform a full checking on the results produced by the 4-bit adders in both structural and behavioral models. Please help explain the below verilog testbench coding for 4-bit adder, the answer is from my friend but I don't understand. Please explain line by line why it is needed and how does the testbench function to test the adders that were wrote in verilog code. Codes are attached below for easier copy and paste you want to test in edaplayground. Please help, I really don't understand, everyone hates me, I am failing the class, I will rate you 5 stars I promise 4-Bit Adder Structural Module Testbench for Structural 4-Bit Adder Module module adder1(A, B, Cin, Sum, Cout);   input [3:0] A,B;   input Cin;   output [3:0] Sum;   output Cout;     wire C0, C1, C2;     fulladder M1(A[0], B[0], Cin, Sum[0], C0);   fulladder M2(A[1], B[1], Cin, Sum[1], C1);   fulladder M3(A[2], B[2], Cin, Sum[2], C2);   fulladder M4(A[3], B[3], Cin, Sum[3], Cout);   endmodule   module fulladder(A, B, Cin, Sum, Cout);   input A, B, Cin;   output Sum, Cout;     wire n1, n2, x1;   xor u1 (x1, A, B);   xor u2 (Sum, x1, Cin);   and u3 (n1, Cin, x1);   and u4 (n2, A, B);   or u5 (Cout, n1, n2);   endmodule `timescale 1us / 100ns //total duration 5.12ms   module adder1_tb();   reg [3:0] A, B; reg Cin; wire [3:0] Sum; wire Cout;   adder1 u1 (A, B, Cin, Sum, Cout); integer i;   initial begin   Cin=0; for (i=0; i<256; i=i+1) begin {B,A}=i; #10; end   Cin=1; for (i=0; i<256; i=i+1) begin {B,A}=i; #10; end   end endmodule   4-Bit Adder Behavioral Module Testbench for Behavioral 4-Bit Adder Module module adder2(A, B, Cin, Sum, Cout);   input [3:0] A, B;   input Cin;   output [3:0] Sum;   output Cout;     assign {Cout, Sum} =A+B+{3'b0,Cin};   endmodule `timescale 1us / 100ns //total duration 5.12ms   module adder2_tb();   reg [3:0] A, B; reg Cin; wire [3:0] Sum; wire Cout;   adder2 u1 (A, B, Cin, Sum, Cout); integer i;   initial begin   Cin=0; for (i=0; i<256; i=i+1) begin {B,A}=i; #10; end   Cin=1; for (i=0; i<256; i=i+1) begin {B,A}=i; #10; end   end endmodule

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

My exercise was to modify a testbench code to perform a full checking on the results produced by the 4-bit adders in both structural and behavioral models. Please help explain the below verilog testbench coding for 4-bit adder, the answer is from my friend but I don't understand. Please explain line by line why it is needed and how does the testbench function to test the adders that were wrote in verilog code. Codes are attached below for easier copy and paste you want to test in edaplayground. Please help, I really don't understand, everyone hates me, I am failing the class, I will rate you 5 stars I promise

4-Bit Adder Structural Module

Testbench for Structural 4-Bit Adder Module

module adder1(A, B, Cin, Sum, Cout);

  input [3:0] A,B;

  input Cin;

  output [3:0] Sum;

  output Cout;

 

  wire C0, C1, C2;

 

  fulladder M1(A[0], B[0], Cin, Sum[0], C0);

  fulladder M2(A[1], B[1], Cin, Sum[1], C1);

  fulladder M3(A[2], B[2], Cin, Sum[2], C2);

  fulladder M4(A[3], B[3], Cin, Sum[3], Cout);

 

endmodule

 

module fulladder(A, B, Cin, Sum, Cout);

  input A, B, Cin;

  output Sum, Cout;

 

  wire n1, n2, x1;

  xor u1 (x1, A, B);

  xor u2 (Sum, x1, Cin);

  and u3 (n1, Cin, x1);

  and u4 (n2, A, B);

  or u5 (Cout, n1, n2);

 

endmodule

`timescale 1us / 100ns

//total duration 5.12ms

 

module adder1_tb();

 

reg [3:0] A, B;

reg Cin;

wire [3:0] Sum;

wire Cout;

 

adder1 u1 (A, B, Cin, Sum, Cout);

integer i;

 

initial begin

 

Cin=0;

for (i=0; i<256; i=i+1) begin

{B,A}=i;

#10;

end

 

Cin=1;

for (i=0; i<256; i=i+1) begin

{B,A}=i;

#10;

end

 

end

endmodule

 

4-Bit Adder Behavioral Module

Testbench for Behavioral 4-Bit Adder Module

module adder2(A, B, Cin, Sum, Cout);

  input [3:0] A, B;

  input Cin;

  output [3:0] Sum;

  output Cout;

 

  assign {Cout, Sum} =A+B+{3'b0,Cin};

 

endmodule

`timescale 1us / 100ns

//total duration 5.12ms

 

module adder2_tb();

 

reg [3:0] A, B;

reg Cin;

wire [3:0] Sum;

wire Cout;

 

adder2 u1 (A, B, Cin, Sum, Cout);

integer i;

 

initial begin

 

Cin=0;

for (i=0; i<256; i=i+1) begin

{B,A}=i;

#10;

end

 

Cin=1;

for (i=0; i<256; i=i+1) begin

{B,A}=i;

#10;

end

 

end

endmodule

Expert Solution
steps

Step by step

Solved in 10 steps

Blurred answer
Knowledge Booster
Binary numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education