//==================================================
// Module: popcount8
// Description: Counts how many bits in an 8-bit input are '1'.
//==================================================
module popcount8 (
input wire [7:0] in,
output reg [3:0] count // Range: 0–8
);
integer i;
always @(*) begin
count = 4'd0; // Initialize to avoid latches
for (i = 0; i < 8; i = i + 1) begin
count = count + in[i];
end
end
endmodule