-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMIPS_processor.vhd
More file actions
176 lines (154 loc) · 6.86 KB
/
MIPS_processor.vhd
File metadata and controls
176 lines (154 loc) · 6.86 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
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
library ieee;
use ieee.std_logic_1164.all;
entity MIPS_processor is
port (
clk : in std_logic;
reset : in std_logic
);
end MIPS_processor;
architecture Behavioral of MIPS_processor is
-- MIPS blocks components
component pc is
port (
d : in std_logic_vector (31 downto 0);
q : out std_logic_vector (31 downto 0);
reset : in std_logic;
clk : in std_logic
);
end component;
component adder is
port (
a : in std_logic_vector(31 downto 0);
b : in std_logic_vector(31 downto 0);
c : out std_logic_vector(31 downto 0)
);
end component;
component alu is
port (
a : in std_logic_vector(31 downto 0);
b : in std_logic_vector(31 downto 0);
cntrl : in std_logic_vector(2 downto 0);
zero : out std_logic;
result : out std_logic_vector(31 downto 0)
);
end component;
component data_memory is
port (
read_enable: in std_logic;
write_enable: in std_logic;
enable: in std_logic;
CLK: in std_logic;
address: in std_logic_vector(31 downto 0);
write_data: in std_logic_vector(31 downto 0);
read_data: out std_logic_vector(31 downto 0)
);
end component;
component instruction_memory is
port (
direccion : in std_logic_vector(31 downto 0);
dato : out std_logic_vector(31 downto 0)
);
end component;
component mux_5bits is
port (
selector: in std_logic; -- selector line
input_1: in std_logic_vector (4 downto 0); -- input 1
input_2: in std_logic_vector (4 downto 0); -- input 2
output: out std_logic_vector (4 downto 0) -- output
);
end component;
component mux_32bits is
port (
selector: in std_logic; -- selector line
input_1: in std_logic_vector (31 downto 0); -- input 1
input_2: in std_logic_vector (31 downto 0); -- input 2
output: out std_logic_vector (31 downto 0) -- output
);
end component;
component register_file is
port (
clk : in std_logic;
write_reg, read_reg_1, read_reg_2 : in std_logic_vector(4 downto 0);
reg_write : in std_logic;
write_data : in std_logic_vector(31 downto 0);
read_data_1, read_data_2 : out std_logic_vector(31 downto 0)
);
end component;
component control_unit is
port (
opcode: in std_logic_vector(5 downto 0);
reg_dest, jump, branch, mem_read, mem_to_reg, mem_write, alu_src, reg_write: out std_logic;
alu_op: out std_logic_vector(2 downto 0)
);
end component;
component alu_control is
port (
funct: in std_logic_vector(5 downto 0);
alu_op: in std_logic_vector(2 downto 0);
alu_ctrl: out std_logic_vector(2 downto 0);
JR: out std_logic
);
end component;
component shift_left_32bits is
port (
input : in std_logic_vector (31 downto 0);
output : out std_logic_vector (31 downto 0)
);
end component;
component shift_left_28bits is
port (
input : in std_logic_vector (25 downto 0);
output : out std_logic_vector (27 downto 0)
);
end component;
component sign_extender is
port (
num : in std_logic_vector (15 downto 0);
signed_num : out std_logic_vector (31 downto 0)
);
end component;
-- signals
signal instruction_address: std_logic_vector(31 downto 0);
signal next_address: std_logic_vector(31 downto 0);
signal instruction: std_logic_vector(31 downto 0);
signal read_data_1, read_data_2, write_data, next_pc, extended_immediate, shifted_immediate, add_pc_immediate: std_logic_vector(31 downto 0);
signal mux_registers_out, alu_result, mux_add_1_res, mux_add_2_res, mem_read_data, jump_and_pc: std_logic_vector(31 downto 0);
signal shifted_jump_address: std_logic_vector(27 downto 0);
signal jump_address: std_logic_vector(25 downto 0);
signal immediate: std_logic_vector(15 downto 0);
signal opcode, funct: std_logic_vector(5 downto 0);
signal rs, rt, rd, write_reg, mux_registers: std_logic_vector(4 downto 0);
signal alu_ctrl: std_logic_vector(2 downto 0);
signal reg_dest, jump, branch, mem_read, mem_to_reg, mem_write, alu_src, reg_write, alu_zero, branch_and_alu_zero, JR: std_logic;
signal alu_op: std_logic_vector(2 downto 0);
begin
-- MIPS instruction format
opcode <= instruction(31 downto 26);
rs <= instruction(25 downto 21);
rt <= instruction(20 downto 16);
rd <= instruction(15 downto 11);
funct <= instruction(5 downto 0);
immediate <= instruction(15 downto 0);
jump_address <= instruction(25 downto 0);
branch_and_alu_zero <= branch and alu_zero;
jump_and_pc <= next_pc (31 downto 28) & shifted_jump_address;
-- wire each block according to the MIPS processor block diagram
ProgramCounter: pc port map (next_address, instruction_address, reset, clk);
InstructionMemory: instruction_memory port map (instruction_address, instruction);
AddPC4: adder port map (instruction_address, "00000000000000000000000000000100", next_pc);
Shift28: shift_left_28bits port map (jump_address, shifted_jump_address);
ControlUnit: control_unit port map (opcode, reg_dest, jump, branch, mem_read, mem_to_reg, mem_write, alu_src, reg_write, alu_op);
MuxRegisters: mux_5bits port map (reg_dest, rt, rd, mux_registers);
RegisterFile: register_file port map (clk, mux_registers, rs, rt, reg_write, write_data, read_data_1, read_data_2);
SignExtend: sign_extender port map (immediate, extended_immediate);
Shift32: shift_left_32bits port map (extended_immediate, shifted_immediate);
AddImmediatePC: adder port map (next_pc, shifted_immediate, add_pc_immediate);
MuxRegistersOut: mux_32bits port map (alu_src, read_data_2, extended_immediate, mux_registers_out);
ALUControl: alu_control port map (funct, alu_op, alu_ctrl, JR);
ALUModule: alu port map (read_data_1, mux_registers_out, alu_ctrl, alu_zero, alu_result);
MuxAdd1: mux_32bits port map (branch_and_alu_zero, next_pc, add_pc_immediate, mux_add_1_res);
MuxAdd2: mux_32bits port map (jump, mux_add_1_res, jump_and_pc, mux_add_2_res);
MuxAdd3: mux_32bits port map (JR, mux_add_2_res, read_data_2, next_address);
DataMemory: data_memory port map (mem_read, mem_write, '0', clk, alu_result, read_data_2, mem_read_data);
MuxDataMemory: mux_32bits port map (mem_to_reg, alu_result, mem_read_data, write_data);
end Behavioral;