-
Notifications
You must be signed in to change notification settings - Fork 0
/
alu.vhd
97 lines (94 loc) · 3.28 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
-- Complete ALU
-- This code implement a entire ALU module for our procesor
-- Alexis Aceves & Esaú Acosta
--
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity alu is
port (
alu_in0: in STD_LOGIC_VECTOR(31 downto 0);
alu_in1: in STD_LOGIC_VECTOR(31 downto 0);
alu_control: in STD_LOGIC_VECTOR(3 downto 0);
alu_zero: out std_logic;
alu_cout: out std_logic;
alu_result: out STD_LOGIC_VECTOR(31 downto 0)
);
end alu;
architecture alu_structural of alu is
--
component alu_i
port (
alu_in0, alu_in1, alu_cin, alu_sign: in std_logic;
alu_cout, alu_result: out std_logic;
selector: in std_logic_vector(3 downto 0)
);
end component;
--
component alu_1
port (
alu_in0, alu_in1, alu_cin : in std_logic;
alu_cout, alu_sign, alu_result : out std_logic;
selector: in std_logic_vector(3 downto 0)
);
end component;
--
signal signal_sign: std_logic;
signal signal_carry: std_logic_vector(31 downto 0);
signal signal_result: std_logic_vector(31 downto 0);
--
begin
alus: for i in 0 to 31 generate
--
alu0: if i = 0 generate
alu_0: alu_i port map (
alu_in0 => alu_in0(i),
alu_in1 => alu_in1(i),
alu_result => signal_result(i),
alu_cin => alu_control(2),
alu_cout => signal_carry(i),
alu_sign => signal_sign,
selector(3) => alu_control(3),
selector(2) => alu_control(2),
selector(1) => alu_control(1),
selector(0) => alu_control(0)
);
end generate alu0;
--
alu_n_1: if i > 0 generate
alu_1_30: alu_i port map (
alu_in0 => alu_in0(i),
alu_in1 => alu_in1(i),
alu_result => signal_result(i),
alu_cin => signal_carry(i-1),
alu_cout => signal_carry(i),
alu_sign => '0',
selector(3) => alu_control(3),
selector(2) => alu_control(2),
selector(1) => alu_control(1),
selector(0) => alu_control(0)
);
end generate alu_n_1;
--
final_alu: if i = 31 generate
alu_31: alu_1 port map (
alu_in0 => alu_in0(i),
alu_in1 => alu_in1(i),
alu_result => signal_result(i),
alu_cin => signal_carry(i-1),
alu_cout => signal_carry(i),
alu_sign => signal_sign,
selector(3) => alu_control(3),
selector(2) => alu_control(2),
selector(1) => alu_control(1),
selector(0) => alu_control(0)
);
end generate final_alu;
--
end generate;
--
alu_result <= signal_result;
alu_cout <= signal_carry(31);
--sign
alu_zero <= '1' when signal_result = (signal_result'range => '0') else '0';
--
end alu_structural;--full alu structural