-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrdenador.vhd
198 lines (159 loc) · 4.28 KB
/
Ordenador.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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
-- Quartus II VHDL Template
-- Unsigned Adder
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity Ordenador is
port
(
v1 : in std_logic_vector (7 downto 0);
v2 : in std_logic_vector (7 downto 0);
v3 : in std_logic_vector (7 downto 0);
v4 : in std_logic_vector (7 downto 0);
clk : in std_logic;
rst : in std_logic;
comp1 : out std_logic;
comp2 : out std_logic;
comp3 : out std_logic;
r1 : out std_logic_vector (7 downto 0);
r2 : out std_logic_vector (7 downto 0);
r3 : out std_logic_vector (7 downto 0);
r4 : out std_logic_vector (7 downto 0)
);
end entity;
architecture rtl of Ordenador is
signal reg1: std_logic_vector (7 downto 0);
signal reg2: std_logic_vector (7 downto 0);
signal reg3: std_logic_vector (7 downto 0);
signal reg4: std_logic_vector (7 downto 0);
signal regComp1: std_logic;
signal regComp2: std_logic;
signal regComp3: std_logic;
signal outComp1: std_logic;
signal outComp2: std_logic;
signal outComp3: std_logic;
signal outMuxReg1: std_logic_vector (7 downto 0);
signal outMuxReg2: std_logic_vector (7 downto 0);
signal outMuxReg3: std_logic_vector (7 downto 0);
signal outMuxReg4: std_logic_vector (7 downto 0);
signal enReg1 : std_logic;
signal enReg2 : std_logic;
signal enReg3 : std_logic;
signal enReg4 : std_logic;
signal enComp1 : std_logic;
signal enComp2 : std_logic;
signal enComp3 : std_logic;
signal selReg1 : std_logic_vector (1 downto 0);
signal selReg2 : std_logic_vector (1 downto 0);
signal selReg3 : std_logic_vector (1 downto 0);
signal selReg4 : std_logic_vector (1 downto 0);
signal selComp : std_logic;
component PC is
port(
clk : in std_logic;
reset : in std_logic;
comp1 : in std_logic;
comp2 : in std_logic;
comp3 : in std_logic;
enReg1 : out std_logic;
enReg2 : out std_logic;
enReg3 : out std_logic;
enReg4 : out std_logic;
enComp1 : out std_logic;
enComp2 : out std_logic;
enComp3 : out std_logic;
selReg1 : out std_logic_vector (1 downto 0);
selReg2 : out std_logic_vector (1 downto 0);
selReg3 : out std_logic_vector (1 downto 0);
selReg4 : out std_logic_vector (1 downto 0);
selComp : out std_logic
);
end component;
begin
outComp1 <= '1' when reg1 < reg2 else
'0';
outComp2 <= '1' when reg2 < reg3 else
'0';
outComp3 <= '1' when reg3 < reg4 else
'0';
regComp1 <= outComp1 when selComp = '0' else
'0';
regComp2 <= outComp2 when selComp = '0' else
'0';
regComp3 <= outComp3 when selComp = '0' else
'0';
outMuxReg1 <= v1 when selReg1 = "00" else
reg2 when selReg1 = "01" else
"00000000";
outMuxReg2 <= v2 when selReg2 = "00" else
reg1 when selReg2 = "01" else
reg3 when selReg2 = "10" else
"00000000";
outMuxReg3 <= v3 when selReg3 = "00" else
reg2 when selReg3 = "01" else
reg4 when selReg3 = "10" else
"00000000";
outMuxReg4 <= v4 when selReg4 = "00" else
reg3 when selReg4 = "01" else
"00000000";
r1 <= reg1;
r2 <= reg2;
r3 <= reg3;
r4 <= reg4;
process(clk, rst)is
begin
if (rst = '1') then
reg1 <= "00000000";
reg2 <= "00000000";
reg3 <= "00000000";
reg4 <= "00000000";
comp1 <= '0';
comp2 <= '0';
comp3 <= '0';
else
if (rising_edge(clk)) then
if (enReg1 = '1') then
reg1 <= outMuxReg1;
end if;
if (enReg2 = '1') then
reg2 <= outMuxReg2;
end if;
if (enReg3 = '1') then
reg3 <= outMuxReg3;
end if;
if (enReg4 = '1') then
reg4 <= outMuxReg4;
end if;
if (enComp1 = '1') then
comp1 <= regComp1;
end if;
if (enComp2 = '1') then
comp2 <= regComp2;
end if;
if (enComp3 = '1') then
comp3 <= regComp3;
end if;
end if;
end if;
end process;
Controle: PC
port map (
clk => clk,
reset => rst,
comp1 => regComp1,
comp2 => regComp2,
comp3 => regComp3,
enReg1 => enReg1,
enReg2 => enReg2,
enReg3 => enReg3,
enReg4 => enReg4,
enComp1 => enComp1,
enComp2 => enComp2,
enComp3 => enComp3,
selReg1 => selReg1,
selReg2 => selReg2,
selReg3 => selReg3,
selReg4 => selReg4,
selComp => selComp
);
end rtl;