-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMIPS.sv
162 lines (141 loc) · 3.79 KB
/
MIPS.sv
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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 00:02:43 05/10/2017
// Design Name:
// Module Name: MIPS
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module MIPS(
input clk,
input rst,
output [31:0] direccion,
output [31:0] palabra,
output [31:0] leer_dato,
output wr_en,
output [31:0] wr_addr,
output [31:0] wr_data
);
logic [31:0] Word; //salida del pc
logic [31:0] Word_4; //salida adder+4
logic [31:0] Address_branch; //salida Adder Branch
logic [31:0] Address_final; //Salida mux branch
logic [25:0] Address_jump; //Direccion a saltar con adress
logic [31:0] Address_jump_final; //Direccion final del jump
logic RegDst; //Salidas del control
logic Branch;
logic MemRead;
logic MemtoReg;
logic [1:0] Alu_op;
logic AluSrc;
logic RegWrite;
logic [4:0] Address1;
logic [4:0] Address2;
logic[4:0] Address3;
logic [15:0] extender;
logic J; //Salida si es tipo J
logic [31:0] ReadData1; //Salida banco de registros
logic [31:0] ReadData2; //Salida banco de registros
logic [4:0] Mux_Address3; //Mux antes del banco de registros
logic [31:0] Extend_32; //Salida extender 32 bits
logic [31:0] Shifter_32; //Salida del shifter
logic [31:0] Mux_Alu; // Salida de mux antes del alu
logic zero; //Salida zero del Alu
logic [31:0] result; //Resultado del Alu
logic And; //Salida del And
logic [31:0] Data_DataMemory; //Salida del DataMemory
logic [31:0] WriteData; //Datos que se escriben en el banco de registros
logic [31:0] Address; //Entrada pc
//Salidas extra
assign wr_en = RegWrite;
assign wr_addr= Mux_Address3;
assign wr_data = WriteData;
InstructionMemory InstructionMemory(
.Address(Address),
.Word(Word)
);
ControlInstructionMemory ControlInstructionMemory(
.ReadAddress(Word),
.RegDst(RegDst),
.Branch(Branch),
.MemRead(MemRead),
.MemtoReg(MemtoReg),
.Alu_op(Alu_op),
.MemWrite(MemWrite),
.AluSrc(AluSrc),
.RegWrite(RegWrite),
.J(J),
.Address1(Address1),
.Address2(Address2),
.Address3(Address3),
.extender(extender),
.AddressJ(Address_jump)
);
SignExtend_26X32 SignExtend_26x32(
.Input_26(Address_jump),
.Output_32(Address_jump_final)
);
RegisterBank RegisterBank(
.RegWrite(RegWrite),
.ReadRegister1(Address1),
.ReadRegister2(Address2),
.WriteRegister(Mux_Address3),
.clk(clk),
.rst(rst),
.WriteData(WriteData),
.ReadData1(ReadData1),
.ReadData2(ReadData2)
);
SignExtend_16X32 SignExtend_16X32(
.Input_16(extender),
.Output_32(Extend_32)
);
Shifter_2 Shifter_2(
.Input(Extend_32),
.Output(Shifter_32)
);
Alu_final Alu_final(
.a(ReadData1),
.b(Mux_Alu),
.Alu_op(Alu_op),
.funct(extender[5:0]),
.zero(zero),
.result(result)
);
DataMemory DataMemory(
.Address(result),
.WriteData(ReadData2),
.MemWrite(MemWrite),
.MemRead(MemRead),
.clk(clk),
.ReadData(Data_DataMemory)
);
assign Word_4 = Address + 4;
assign Address_branch = Word_4 + Shifter_32;
assign Address_final = (And) ? Address_branch:Word_4; //Parte de arriba
//Program Counter
always @(posedge clk) begin
if (rst == 1 ) Address <= 0;
else Address <= (J) ? Address_jump_final:Address_final;
end
//
assign Mux_Address3 = (RegDst) ? Address3:Address2;
assign Mux_Alu = (AluSrc) ? Extend_32:ReadData2;
assign direccion = Address;
assign And = (Branch & zero);
assign WriteData = (MemtoReg) ? Data_DataMemory:result;
assign palabra = Word;
assign leer_dato = WriteData;
endmodule