-
Notifications
You must be signed in to change notification settings - Fork 3
/
adder.vhd
63 lines (47 loc) · 1.16 KB
/
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
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
-- single bit adder
ENTITY my_adder IS
PORT (
a, b, cin : IN STD_LOGIC;
s, cout : OUT STD_LOGIC);
END my_adder;
ARCHITECTURE a_my_adder OF my_adder IS
BEGIN
s <= a XOR b XOR cin;
cout <= (a AND b) OR (cin AND (a XOR b));
END a_my_adder;
--_________________________________________________________________
-- ALU_ADDER
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY ALU_ADDER IS
GENERIC (n : INTEGER := 16);
PORT (
A, B : IN STD_LOGIC_VECTOR (n - 1 DOWNTO 0);
cin : IN STD_LOGIC;
C, Z, Ne : OUT STD_LOGIC;
F : OUT STD_LOGIC_VECTOR (n - 1 DOWNTO 0)
);
END ALU_ADDER;
ARCHITECTURE ALU_ADDER_arch OF ALU_ADDER IS
COMPONENT my_adder IS
PORT (
a, b, cin : IN STD_LOGIC;
s, cout : OUT STD_LOGIC);
END COMPONENT;
SIGNAL carry : STD_LOGIC_VECTOR(n DOWNTO 0);
SIGNAL F1, zeroResult : STD_LOGIC_VECTOR (n - 1 DOWNTO 0);
BEGIN
zeroResult <= (OTHERS => '0');
carry(0) <= '0';
loop1 : FOR i IN 0 TO n - 1 GENERATE
fx : my_adder PORT MAP(A(i), B(i), carry(i), F1(i), carry(i + 1));
END GENERATE;
F <= F1;
C <= carry(n);
Ne <= F1(n - 1);
Z <= '1' WHEN F1 = zeroResult
ELSE
'0';
END ALU_ADDER_arch;