Skip to content

Instantly share code, notes, and snippets.

@mcandre
Created October 11, 2021 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcandre/d9bf346c02238d4b5063fed944e5ae54 to your computer and use it in GitHub Desktop.
Save mcandre/d9bf346c02238d4b5063fed944e5ae54 to your computer and use it in GitHub Desktop.
full adder chain
`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