-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCLA_16_bit.vhdl
59 lines (45 loc) · 1.22 KB
/
CLA_16_bit.vhdl
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
USE IEEE.numeric_std.ALL;
ENTITY cla IS
GENERIC (
size : INTEGER := 16
);
PORT (
a : IN STD_LOGIC_VECTOR(size - 1 DOWNTO 0);
b : IN STD_LOGIC_VECTOR(size - 1 DOWNTO 0);
--
result : OUT STD_LOGIC_VECTOR(size DOWNTO 0)
);
END cla;
ARCHITECTURE arch OF cla IS
COMPONENT full_adder IS
PORT (
a : IN STD_LOGIC;
b : IN STD_LOGIC;
cin : IN STD_LOGIC;
sum : OUT STD_LOGIC;
cout : OUT STD_LOGIC
);
END COMPONENT full_adder;
SIGNAL G, P, sum : STD_LOGIC_VECTOR(size - 1 DOWNTO 0);
SIGNAL carry : STD_LOGIC_VECTOR(size DOWNTO 0);
begin
carry(0) <= '0';
result <= carry(size) & sum;
main_loop: for i in 0 to size - 1 generate
adder : full_adder
port map (
a => a(i),
b => b(i),
cin => carry(i),
sum => sum(i),
cout => open
);
end generate main_loop;
cla: for ii in 0 to size-1 generate
G(ii) <= a(ii) and b(ii);
P(ii) <= a(ii) or b(ii);
carry(ii+1) <= G(ii) or (P(ii) and carry(ii));
end generate cla;
END ARCHITECTURE; -- arch