-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathnBitCarryLookAheadAdder.v
42 lines (34 loc) · 1.01 KB
/
nBitCarryLookAheadAdder.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020 Akilesh Kannan <[email protected]>
//
// File: nBitCarryLookAheadAdder.v
// Modified: 2020-07-16
// Description: N-Bit Carry Look Ahead Adder
//
//
// License: MIT
//
////////////////////////////////////////////////////////////////////////
`default_nettype None
`timescale 1ns/1ps
module nBitCarryLookAheadAdder #(parameter n = 4)(output[n:0] total, input[n-1:0] A, input[n-1:0] B);
wire[n-1:0] gi, pi, sum;
wire[n:0] ci;
assign ci[0] = 1'b0;
genvar i;
generate
for(i = 0;i < n;i = i+1) begin: giAndpi
assign gi[i] = A[i]&B[i];
assign pi[i] = A[i]^B[i];
assign ci[i+1] = gi[i]|(pi[i]&ci[i]);
end
endgenerate
genvar j;
generate
for(j = 0;j < n;j = j+1) begin: calculation
FA adder(.Cout(), .sum(sum[j]), .A(A[j]), .B(B[j]), .Cin(ci[j]));
end
endgenerate
assign total = {ci[n], sum[n-1:0]};
endmodule