Created
October 11, 2021 15:39
-
-
Save mcandre/d9bf346c02238d4b5063fed944e5ae54 to your computer and use it in GitHub Desktop.
full adder chain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`include "fulladder.sv" | |
module fulladder_chain #(parameter WIDTH)(input carry_in, [WIDTH-1:0] a, [WIDTH-1:0] b, output carry_out, [WIDTH-1:0] sum); | |
const int sizes[] = {WIDTH-2, 0}; | |
const int CARRY_WIDTH = sizes.max; | |
wire [CARRY_WIDTH:0] carries; | |
fulladder fa_head(carry_in, a[0], b[0], carries[0], sum[0]); | |
fulladder fa_tail(carries[WIDTH-2], a[WIDTH-1], b[WIDTH-1], carry_out, sum[WIDTH-1]); | |
genvar i; | |
generate | |
for (i = 1; i < WIDTH - 1; i++) | |
fulladder fa(carries[i-1], a[i], b[i], carries[i], sum[i]); | |
endgenerate | |
endmodule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment