Repository navigation
Expand file tree
/
Copy pathALU.vhd
More file actions
145 lines (104 loc) · 4.24 KB
/
Copy pathALU.vhd
File metadata and controls
145 lines (104 loc) · 4.24 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
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
use ieee.numeric_std.all;
use ieee.math_real.all;
--I considered one signal for immediate. I am not sure whether I should have used another signal for immediate address in jump ins.
entity ALU is
generic(
operand_width : integer :=32;
operation_type : integer :=5
);
port(
alu_input1 : in std_logic_vector(operand_width -1 downto 0);
alu_input2 : in std_logic_vector(operand_width -1 downto 0);
ALU_type : in std_logic_vector(2 downto 0);
alu_output : out std_logic_vector(operand_width -1 downto 0);
co : out std_logic
);
end ALU;
architecture structural of ALU is
component add_sub is
generic ( nbit : integer );
port (A: in std_logic_vector(NBIT-1 downto 0);
B: in std_logic_vector(NBIT-1 downto 0);
Cin: in std_logic;
as : in std_logic;
S: out std_logic_vector(NBIT-1 downto 0);
Co: out std_logic);
end component ;
component logic is
generic(nbit : integer);
port( a : in std_logic_vector(nbit-1 downto 0);
b : in std_logic_vector(nbit-1 downto 0);
sel : in std_logic_vector(3 downto 0);
o : out std_logic_vector(nbit-1 downto 0));
end component;
component shifter is
generic ( nbit : integer );
port ( input : std_logic_vector(nbit -1 downto 0);
sel : std_logic_vector(integer(log2(real(nbit)))-1 downto 0);
lr : std_logic; -- 0 per left, 1 per right
output : std_logic_vector(nbit-1 downto 0));
end component;
component register_1 is
generic ( n_bit : integer);
port (d_in : in std_logic_vector(n_bit-1 downto 0);
d_out : out std_logic_vector(n_bit-1 downto 0);
en : in std_logic);
end component;
component dec is
port ( opcode : in std_logic_vector(2 downto 0 );
add : out std_logic;
sub : out std_logic;
and_en : out std_logic;
or_en : out std_logic;
xor_en : out std_logic;
sl_en : out std_logic;
sr_en : out std_logic;
cmp : out std_logic);
end component;
component MUX41 is
Generic (NBIT: integer );
Port ( A: In std_logic_vector(NBIT-1 downto 0) ;
B: In std_logic_vector(NBIT-1 downto 0);
C: In std_logic_vector(NBIT-1 downto 0);
D: In std_logic_vector(NBIT-1 downto 0);
SEL:In std_logic_vector(1 downto 0);
Y: Out std_logic_vector(NBIT-1 downto 0));
end component;
component or_1 is
port ( x: in std_logic;
y: in std_logic;
z: out std_logic);
end component;
component final_mux_sel is
port ( a : in std_logic_vector(2 downto 0);
sel : out std_logic_vector(1 downto 0));
end component;
signal a_en,s_en,and_en,or_en,xor_en,sl_en,sr_en,cmp,a_or_s,logic_en,tmp1,shift_en : std_logic;
signal as_add,bs_add,as_logic,bs_logic,as_shift,bs_shift,as_out,logic_out,s_out : std_logic_vector(31 downto 0);
signal fm_sel : std_logic_vector(1 downto 0);
begin
aors : or_1 port map ( a_en,s_en,a_or_s);
and_or_or : or_1 port map ( and_en , or_en , tmp1);
andor_or_xor : or_1 port map ( tmp1 , xor_en , logic_en); --and_en or or_en or xor_en per logic_reg
shift_enable : or_1 port map ( sr_en , sl_en,shift_en);
reg_en_dec : dec port map(alu_type,a_en,s_en,and_en,or_en,xor_en,sl_en,sr_en,cmp);
as_reg_a : register_1 generic map(32) port map ( alu_input1, as_add, a_or_s);
as_reg_b : register_1 generic map(32) port map ( alu_input2, bs_add, a_or_s);
logic_reg_a : register_1 generic map(32) port map ( alu_input1 , as_logic,logic_en);
logic_reg_b : register_1 generic map(32) port map ( alu_input2, bs_logic,logic_en);
s_reg_a : register_1 generic map(32) port map ( alu_input1, as_shift,shift_en);
s_reg_b : register_1 generic map(32) port map ( alu_input2, bs_shift,shift_en);
add_sub1 : add_sub generic map(32) port map(as_add,bs_add,'0',s_en,as_out,co);
logic1 : logic generic map (32) port map ( a => as_logic ,b => bs_logic ,sel(3) => '0',sel(2 downto 0) => alu_type,o => logic_out);
shifter1 : shifter generic map (32) port map( as_shift, bs_shift(integer(log2(real(32))) -1 downto 0) , sr_en,s_out);
fms : final_mux_sel port map ( alu_type,fm_sel);
final_mux : mux41 generic map (32) port map(as_out,logic_out,s_out,"00000000000000000000000000000000",fm_sel, alu_output); -- karnough
end structural;
configuration cfg_alu_str of alu is
for structural
end for;
end configuration;