代码:
//加法器
`timescale 1ns/10ps
module add(
a,
b,
y
);
input a;
input b;
output[1:0] y;
assign y=a+b;
endmodule
//testbench
module add_tb;
reg a;
reg b;
wire[1:0] y;
add add(
.a(a),
.b(b),
.y(y)
);
initial begin
a<=0;b<=0;
#10 a<=1;b<=0;
#10 a<=0;b<=1;
#10 a<=1;b<=1;
#10 $stop;
end
endmodule
实验波形:
小结