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
posted @ 2024-03-07 18:02  江左子固  阅读(15)  评论(0)    收藏  举报