본문 바로가기

Verilog/HDLbits

[HDLBits] Popcount255

1. 문제 및 설명

  • 255 비트 입력에 대해서 1의 개수를 세는 회로를 만드시.
     

2. 모듈 정의

module top_module( 
    input [254:0] in,
    output [7:0] out );

 

 

 

3. 답

module top_module( 
    input [254:0] in,
    output [7:0] out );
    
    integer i;
    always@(*)
        begin
            out = 255'd0;
            for( i = 0; i < $bits(in); i = i + 1)
                begin
                    out = out + in[i];
                end
        end
    

endmodule

'Verilog > HDLbits' 카테고리의 다른 글

[HDLBits] Bcdadd100  (0) 2025.12.07
[HDLBits] Adder100i  (0) 2025.12.07
[HDLBits] Vector100r  (0) 2025.12.07
[HDLBits] Gates100  (0) 2025.12.07
[HDLBits] Reduction  (0) 2025.12.07