-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCARRY_LOOKAHEAD.vhd
65 lines (49 loc) · 1.7 KB
/
CARRY_LOOKAHEAD.vhd
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
60
61
62
63
64
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.all;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
LIBRARY work;
USE work.ALL;
entity CARRY_LOOKAHEAD is Port(
A : in STD_LOGIC_VECTOR(3 DOWNTO 0);
B : in STD_LOGIC_VECTOR(3 DOWNTO 0);
C0 : in STD_LOGIC;
S : out STD_LOGIC_VECTOR(3 DOWNTO 0);
CARRY_OUT : out STD_LOGIC);
end entity;
architecture mista of CARRY_LOOKAHEAD is
component HALF_ADDER is Port(
A : in STD_LOGIC;
B : in STD_LOGIC;
G : out STD_LOGIC;
P : out STD_LOGIC);
end component;
signal C1, C2, C3 : STD_LOGIC;
signal P,G : STD_LOGIC_VECTOR(3 downto 0);
begin
HA1 : HALF_ADDER port map(A(0), B(0), P(0), G(0));
HA2 : HALF_ADDER port map(A(1), B(1), P(1), G(1));
HA3 : HALF_ADDER port map(A(2), B(2), P(2), G(2));
HA4 : HALF_ADDER port map(A(3), B(3), P(3), G(3));
S(0) <= C0 xor P(0);
--S(1) <= ((C0 and P(0)) or G(0)) xor P(1);
C1 <= G(0) or (C0 and P(0));
S(1) <= C1 xor P(1);
C2 <=
G(1) or
(P(1) and G(0)) or
(P(1) and P(0) and C0);
S(2) <= C2 xor P(2);
C3 <=
G(2) or
(P(2) and G(1)) or
(P(2) and P(1) and G(0)) or
(P(2) and P(1) and P(0) and C0);
S(3) <= C3 xor P(3);
CARRY_OUT <=
G(3) or
(P(3) and G(2)) or
(P(3) and P(2) and G(1)) or
(P(3) and P(2) and P(1) and G(0)) or
(P(3) and P(2) and P(1) and P(0) and C0);
end mista;