-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGates.vhdl
More file actions
174 lines (131 loc) · 3.45 KB
/
Gates.vhdl
File metadata and controls
174 lines (131 loc) · 3.45 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
library ieee;
use ieee.std_logic_1164.all;
package Gates is
component INVERTER is
port (A: in std_logic; Y: out std_logic);
end component INVERTER;
component AND_2 is
port (A, B: in std_logic; Y: out std_logic);
end component AND_2;
component NAND_2 is
port (A, B: in std_logic; Y: out std_logic);
end component NAND_2;
component OR_2 is
port (A, B: in std_logic; Y: out std_logic);
end component OR_2;
component NOR_2 is
port (A, B: in std_logic; Y: out std_logic);
end component NOR_2;
component XOR_2 is
port (A, B: in std_logic; Y: out std_logic);
end component XOR_2;
component XNOR_2 is
port (A, B: in std_logic; Y: out std_logic);
end component XNOR_2;
component HALF_ADDER is
port (A, B: in std_logic; S, C: out std_logic);
end component HALF_ADDER;
component FULL_ADDER is
port (A, B, Cin: in std_logic; S, Cout: out std_logic);
end component FULL_ADDER;
component FULL_ADDER_2Bit is
port(A, B: in std_logic_vector(1 downto 0);
Cin: in std_logic;
S: out std_logic_vector(2 downto 0));
end component FULL_ADDER_2Bit;
component FULL_ADDER_3Bit is
port(A, B: in std_logic_vector(2 downto 0);
Cin: in std_logic;
S: out std_logic_vector(3 downto 0));
end component FULL_ADDER_3Bit;
end package Gates;
library ieee;
use ieee.std_logic_1164.all;
entity INVERTER is
port (A: in std_logic; Y: out std_logic);
end entity INVERTER;
architecture Equations of INVERTER is
begin
Y <= not A;
end Equations;
library ieee;
use ieee.std_logic_1164.all;
entity AND_2 is
port (A, B: in std_logic; Y: out std_logic);
end entity AND_2;
architecture Equations of AND_2 is
begin
Y <= A and B;
end Equations;
library ieee;
use ieee.std_logic_1164.all;
entity NAND_2 is
port (A, B: in std_logic; Y: out std_logic);
end entity NAND_2;
architecture Equations of NAND_2 is
begin
Y <= not (A and B);
end Equations;
library ieee;
use ieee.std_logic_1164.all;
entity OR_2 is
port (A, B: in std_logic; Y: out std_logic);
end entity OR_2;
architecture Equations of OR_2 is
begin
Y <= A or B;
end Equations;
library ieee;
use ieee.std_logic_1164.all;
entity NOR_2 is
port (A, B: in std_logic; Y: out std_logic);
end entity NOR_2;
architecture Equations of NOR_2 is
begin
Y <= not (A or B);
end Equations;
library ieee;
use ieee.std_logic_1164.all;
entity XOR_2 is
port (A, B: in std_logic; Y: out std_logic);
end entity XOR_2;
architecture Equations of XOR_2 is
begin
Y <= A xor B;
end Equations;
library ieee;
use ieee.std_logic_1164.all;
entity XNOR_2 is
port (A, B: in std_logic; Y: out std_logic);
end entity XNOR_2;
architecture Equations of XNOR_2 is
begin
Y <= not (A xor B);
end Equations;
library ieee;
use ieee.std_logic_1164.all;
entity HALF_ADDER is
port (A, B: in std_logic; S, C: out std_logic);
end entity HALF_ADDER;
architecture Equations of HALF_ADDER is
begin
S <= (A xor B);
C <= (A and B);
end Equations;
library ieee;
use ieee.std_logic_1164.all;
library work;
use work.Gates.all;
entity FULL_ADDER is
port (A, B, Cin: in std_logic; S, Cout: out std_logic);
end entity FULL_ADDER;
architecture Equations of FULL_ADDER is
signal tC, tS, U, V: std_logic;
begin
HA1: HALF_ADDER
port map (A => A, B => B, S => tS, C => tC);
HA2: HALF_ADDER
port map (A => tS, B => Cin, S => S, C => V); -- Final Sum S
O1: OR_2
port map (A => V, B => tC, Y => Cout); -- Final Carry Cout
end Equations;