A "population count" circuit counts the number of '1's in an input vector. Build a population count circuit for a 255-bit input vector.
易错要点:不可用 assign out = 8'b0000_0000;因为assign表示out始终接入低电平
module top_module(
input [254:0] in,
output [7:0] out );
//assign out = 0;
always @(*) begin
out = 8'b0000_0000;
for (int i=0; i<255; i++)
if (in[i] == 1)
out = out + 1'b1 ;
else out = out + 1'b0;
end
endmodule