-
Notifications
You must be signed in to change notification settings - Fork 4
/
Ripple_Carry_Adder.vhd
106 lines (92 loc) · 2.22 KB
/
Ripple_Carry_Adder.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Ripple_Carry_Adder is
Port ( SUB: in STD_LOGIC; -- '0' = add, '1' = sub
A : in STD_LOGIC_VECTOR (7 downto 0);
B : in STD_LOGIC_VECTOR (7 downto 0);
S : out STD_LOGIC_VECTOR (7 downto 0);
COUT : out STD_LOGIC;
V : out STD_LOGIC
);
end Ripple_Carry_Adder;
architecture Behavioral of Ripple_Carry_Adder is
component Full_Adder
port(
A : IN std_logic;
B : IN std_logic;
CIN : IN std_logic;
COUT : OUT std_logic;
Z : OUT std_logic
);
end component;
signal C : std_logic_vector (8 downto 0):= "000000000"; -- intermediate carry out
signal B_PRIME : STD_LOGIC_VECTOR (7 downto 0); -- B XOR SUB
begin
C(0) <= '0' XOR SUB;
B_PRIME(7) <= B(7) XOR SUB;
B_PRIME(6) <= B(6) XOR SUB;
B_PRIME(5) <= B(5) XOR SUB;
B_PRIME(4) <= B(4) XOR SUB;
B_PRIME(3) <= B(3) XOR SUB;
B_PRIME(2) <= B(2) XOR SUB;
B_PRIME(1) <= B(1) XOR SUB;
B_PRIME(0) <= B(0) XOR SUB;
U0: Full_Adder PORT MAP (
A => A(0),
B => B_PRIME(0),
CIN => C(0),
Z => S(0),
COUT => C(1)
);
U1: Full_Adder PORT MAP (
A => A(1),
B => B_PRIME(1),
CIN => C(1),
Z => S(1),
COUT => C(2)
);
U2: Full_Adder PORT MAP (
A => A(2),
B => B_PRIME(2),
CIN => C(2),
Z => S(2),
COUT => C(3)
);
U3: Full_Adder PORT MAP (
A => A(3),
B => B_PRIME(3),
CIN => C(3),
Z => S(3),
COUT => C(4)
);
U4: Full_Adder PORT MAP (
A => A(4),
B => B_PRIME(4),
CIN => C(4),
Z => S(4),
COUT => C(5)
);
U5: Full_Adder PORT MAP (
A => A(5),
B => B_PRIME(5),
CIN => C(5),
Z => S(5),
COUT => C(6)
);
U6: Full_Adder PORT MAP (
A => A(6),
B => B_PRIME(6),
CIN => C(6),
Z => S(6),
COUT => C(7)
);
U7: Full_Adder PORT MAP (
A => A(7),
B => B_PRIME(7),
CIN => C(7),
Z => S(7),
COUT => C(8)
);
COUT <= C(8) XOR SUB;
V <= C(7) XOR SUB;
end Behavioral;