`timescale 1ns/1ps
module tb_example5;
reg x1;
reg x2;
reg s;
wire f;
initial
begin
x1 =0;
x2 =0;
s =0;
#20
x1 =0;
x2 =0;
s =1;
#20
x1 =0;
x2 =1;
s =0;
#20
x1 =0;
x2 =1;
s =1;
#20
x1 =1;
x2 =0;
s =0;
#20
x1 =1;
x2 =0;
s =1;
#20
x1 =1;
x2 =1;
s =0;
#20
x1 =1;
x2 =1;
s =1;
#20
x1 =1;
x2 =1;
s =1;
end
example5 example(.x1(x1),.x2(x2),.s(s),.f(f));
endmodule
Figure 2.45
adder.v
module adder(a,b,s1,s0);
input a,b;
output s1,s0;
assign s1 = a & b;
assign s0 = a ^ b;
endmodule
testbench
`timescale 1ns/1ps
module tb_adder;
reg a;
reg b;
wire s0;
wire s1;
initial
begin
a =0;
b =0;
#20
a =0;
b =1;
#20
a =1;
b =0;
#20
a =1;
b =1;
#20
a =1;
b =1;
end
adder adder(.a(a),.b(b),.s0(s0),.s1(s1));
endmodule