module popcount8 #(
parameter I_WIDTH = 8,
parameter O_WIDTH = 3
)(
input [I_WIDTH-1:0] in,
output reg [O_WIDTH:0] count
);
integer i; // loop variable must be declared (synthesizable)
always @* begin
count = {(O_WIDTH + 1){1'b0}}; // default to avoid latch
// Use a for-loop to accumulate the number of '1' bits
for (i = 0; i < I_WIDTH; i = i + 1) begin
// Write code here
count = count + in[i];
end
end
endmodule