Verilog刷题笔记28
题目:
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.
解题:
module top_module(
input [254:0] in,
output [7:0] out );
int i;
always@(*)begin
out=8'b0;
for(i=0;i<255;i++)
if(in[i]==1)
out=out+1'b1;
else
out=out;
end
endmodule
结果正确: