19-Data Flow Modeling and Test Bench-10-02-2023 PDF
19-Data Flow Modeling and Test Bench-10-02-2023 PDF
• The test bench has no input or output ports, because it does not interact with its
environment.
• Within the test bench, the inputs to the circuit are declared with keyword “reg”
and the outputs are declared with the keyword “wire”.
Test Bench for Half adder
Test Bench Code:
• Code: module tb_HA ();
module half_adder (S, C, A, B); reg a, b;
wire s, c;
input A, B; half_adder h1 (s, c, a, b);
output S, C; Initial
xor g1 (S, A, B); begin
a = 1’b0; b=1’b0;
and g2 (C, A, B); #100
endmodule a = 1’b0; b=1’b1;
#100
a = 1’b1; b=1’b0;
#100
a = 1’b1; b=1’b1;
end
endmodule
Test Bench for Full Adder
Test bench code:
• Code: module tb_fa ();
reg a,b,cin;
module full_adder (S,Co,A,B,Ci); wire s, co;
full_adder f1 (s,co,a,b,ci);
input A, B, Ci;
output S, Co; Initial
begin
wire w1, w2,w3;
a = 1’b0; b=1’b0; c=1’b0;
half_adder h1 (w1,w2,A,B); #100
half_adder h2 (S,w3,w1,Ci); a = 1’b0; b=1’b0; c=1’b1;
#100
or g3(Co, w2,w3); a = 1’b0; b=1’b1; c=1’b0;
endmodule #100
a = 1’b1; b=1’b0; c=1’b0;
#100
a = 1’b1; 1=1’b0; c=1’b0;
#100
end
endmodule