HDLBits

100位的全加器,使用always的组合逻辑实现。

module top_module( 
    input [99:0] a, b,
    input cin,
    output [99:0] cout,
    output [99:0] sum );
    
    reg [100:0] tmp;
    reg [7:0] i;
    reg [3:0] sum2;
    always @ (*) begin
        cout = 100'b0;
        tmp = a + b + cin;
        sum[99:0] = tmp[99:0];
        // 计算每一位
        for (i = 0; i < 100; i++) begin
            if (i == 0) sum2 = a[i] + b[i] + cin;
            else sum2 = a[i] + b[i] + cout[i - 1];
            cout[i] = sum2[1];
        end
    end

endmodule