-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalu.vhd
103 lines (94 loc) · 2.41 KB
/
alu.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
----------------------------------------------------------------------------------
--Amitesh 24/EC/14
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity fh is
port (
x:in std_logic;
y:in std_logic;
z:in std_logic;
s:out std_logic;
c:out std_logic
);
end ;
architecture structural of fh is
begin
s<= (x xor y xor z);
c<= (x xor y) or (x and y);
end structural;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mux4x1 is
port(
i0:in std_logic;
i1:in std_logic;
i2:in std_logic;
i3:in std_logic;
s0:in std_logic;
s1:in std_logic;
o0:out std_logic
);
end;
architecture structural of mux4x1 is
signal temp1,temp2,temp3,temp4:std_logic;
begin
temp1<=(s0 nand s1)and i0;
temp2<=(s0 and (not(s1)))and i1;
temp3<=((not(s0))and s1 and i2);
temp4<=(s0 and s1 and i3);
o0<=temp1 or temp2 or temp3 or temp4;
end structural;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity alu is
Port (
cin:in std_logic;
sel0 : in STD_LOGIC;
sel1 : in STD_LOGIC;
a0 : in STD_LOGIC;
a1 : in STD_LOGIC;
a2 : in STD_LOGIC;
a3 : in STD_LOGIC;
b0 : in STD_LOGIC;
b1 : in STD_LOGIC;
b2 : in STD_LOGIC;
b3 : in STD_LOGIC;
o0 : out STD_LOGIC;
o1 : out STD_LOGIC;
o2 : out STD_LOGIC;
o3 : out STD_LOGIC
);
end alu;
architecture structural of alu is
component mux4x1 is
port(
i0:in std_logic;
i1:in std_logic;
i2:in std_logic;
i3:in std_logic;
s0:in std_logic;
s1:in std_logic;
o0:out std_logic
);
end component;
component fh is
port (
x:in std_logic;
y:in std_logic;
z:in std_logic;
s:out std_logic;
c:out std_logic
);
end component;
signal t1,t2,t3,t4,ct0,ct1,ct2,ct3:std_logic;
begin
st1: mux4x1 port map(not(b0),'1','0',not(a0),sel0,sel1,t1);
st2: mux4x1 port map(not(b1),'1','0',not(a1),sel0,sel1,t2);
st3: mux4x1 port map(not(b2),'1','0',not(a2),sel0,sel1,t3);
st4: mux4x1 port map(not(b3),'1','0',not(a3),sel0,sel1,t4);
ft1:fh port map(a0,t1,cin,o0,ct0);
ft2:fh port map(a1,t2,ct0,o1,ct1);
ft3:fh port map(a2,t3,ct1,o2,ct2);
ft4:fh port map(a3,t4,ct2,o3,ct3);
end structural;