-
Notifications
You must be signed in to change notification settings - Fork 0
/
datapath.v
143 lines (136 loc) · 2.23 KB
/
datapath.v
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
`include "mux2.v"
`include "mux4.v"
`include "flopr.v"
`include "adder.v"
`include "regfile.v"
`include "additional_hw.v"
`include "alu.v"
module datapath (
clk,
reset,
RegSrc,
RegWrite,
ImmSrc,
ALUSrc,
ALUControl,
MemtoReg,
PCSrc,
ALUFlags,
PC,
Instr,
ALUResult,
WriteData,
ReadData,
RegByte
);
input wire clk;
input wire reset;
input wire [1:0] RegSrc;
input wire RegWrite;
input wire [1:0] ImmSrc;
input wire ALUSrc;
input wire [2:0] ALUControl;
input wire MemtoReg;
input wire PCSrc;
input wire RegByte;
output wire [3:0] ALUFlags;
output wire [31:0] PC;
input wire [31:0] Instr;
output wire [31:0] ALUResult;
output wire [31:0] WriteData;
input wire [31:0] ReadData;
wire [31:0] PCNext;
wire [31:0] PCPlus4;
wire [31:0] PCPlus8;
wire [31:0] ExtImm;
wire [31:0] SrcA;
wire [31:0] SrcB;
wire [31:0] Result;
wire [31:0] MenResult;
wire [7:0] byteResult;
wire [3:0] RA1;
wire [3:0] RA2;
mux2 #(32) pcmux(
.d0(PCPlus4),
.d1(Result),
.s(PCSrc),
.y(PCNext)
);
flopr #(32) pcreg(
.clk(clk),
.reset(reset),
.d(PCNext),
.q(PC)
);
adder #(32) pcadd1(
.a(PC),
.b(32'b100),
.y(PCPlus4)
);
adder #(32) pcadd2(
.a(PCPlus4),
.b(32'b100),
.y(PCPlus8)
);
mux2 #(4) ra1mux(
.d0(Instr[19:16]),
.d1(4'b1111),
.s(RegSrc[0]),
.y(RA1)
);
mux2 #(4) ra2mux(
.d0(Instr[3:0]),
.d1(Instr[15:12]),
.s(RegSrc[1]),
.y(RA2)
);
regfile rf(
.clk(clk),
.we3(RegWrite),
.ra1(RA1),
.ra2(RA2),
.wa3(Instr[15:12]),
.wd3(Result),
.r15(PCPlus8),
.rd1(SrcA),
.rd2(WriteData)
);
mux2 #(32) prevmux(
.d0(ALUResult),
.d1(ReadData),
.s(MemtoReg),
.y(MenResult)
);
mux4 #(8) muxlbr(
.d0(ReadData[7:0]),
.d1(ReadData[15:8]),
.d2(ReadData[23:16]),
.d3(ReadData[31:24]),
.s(ALUResult[1:0]), //lo que pasa es que el offset es solo de 0 a 3
.y(byteResult)
);
mux2 #(32) resmux(
.d0(MenResult),
.d1({24'b000000000000000000000000,byteResult}),
.s(RegByte),
.y(Result)
);
extend ext(
.Instr(Instr[23:0]),
.ImmSrc(ImmSrc),
.ExtImm(ExtImm)
);
mux2 #(32) srcbmux(
.d0(WriteData),
.d1(ExtImm),
.s(ALUSrc),
.y(SrcB)
);
alu alu(
.a(SrcA),
.b(SrcB),
.ALUControl(ALUControl),
.Result(ALUResult),
.ALUFlags(ALUFlags)
);
endmodule