3-bit population count
题目如下:
A "population count" circuit counts the number of '1's in an input vector. Build a population count circuit for a 3-bit input vector.
代码如下:
module top_module(
input [2:0] in,
output [1:0] out );
integer i;
always@*begin
out=2'b0;
for(i=0;i<3;i=i+1)
begin
out=out+in[i];
end
end
endmodule

浙公网安备 33010602011771号