半加器:没有进位输入的加法器电路,是实现两个一位二进制数的加法运算电路。
module half_adder
(
input wire in1 ,
input wire in2 ,
output wire sum ,
output wire co
);
assign {co, sum} = in1 + in2;
//assign co = in1 & in2;
//assign sum = in1 ^ in2;
endmodule
`timescale 1ns/1ns
module tb_half_adder();
reg in1, in2;
wire sum, co;
initial begin
in1 <= 1'b0;
in2 <= 1'b0;
end
always #10 in1 <= {$random} % 2;
always #10 in2 <= {$random} % 2;
initial begin
$timeformat(-9, 0, "ns", 6);
$monitor("@time %t:in1=%b in2=%b sum=%b co=%b", $time, in1, in2, sum, co);
end
half_adder half_adder_inst
(
.in1 (in1),
.in2 (in2),
.sum (sum),
.co (co)
);
endmodule