-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathM_datapath.v
153 lines (137 loc) · 3.9 KB
/
M_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
144
145
146
147
148
149
150
151
152
153
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 15:08:34 05/23/2017
// Design Name:
// Module Name: path
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module M_datapath(input clk,
input reset,
input MIO_ready,
input IorD,
input IRWrite,
input [1:0] RegDst,
input RegWrite,
input [1:0]MemtoReg,
input ALUSrcA,
input [1:0]ALUSrcB,
input [1:0]PCSource,
input PCWrite,
input PCWriteCond,
input Branch,
input [2:0]ALU_operation,
output [31:0]PC_Current,
input [31:0]data2CPU,
output [31:0]Inst,
output [31:0]data_out,
output [31:0]M_addr,
output zero,
output overflow
);
wire pc_ce;
wire [31:0] ALUout_Q;
wire [31:0] Imm_32;
wire [31:0] MDR;
wire [31:0] notuse;
wire [4: 0] NotUse;
wire [31:0] res;
wire [4: 0] Wt_addr;
wire [31:0] Wt_data;
wire [31:0] rdata_A;
wire [31:0] pc_next;
wire [31:0] offset;
wire [31:0] four;
wire [31:0] branch_pc;
wire [31:0] j_reg_r;
wire [31:0] jump_addr;
wire [31:0] ALU_A;
wire [31:0] ALU_B;
assign pc_ce = MIO_ready & (PCWrite | (PCWriteCond & (~(Branch ^ zero))));
assign offset[31:0] = {Imm_32[29:0],2'b00};
assign four[31:0] = 32'h00000004;
assign branch_pc[31:0] = ALUout_Q[31:0];
assign j_reg_r[31:0] = ALUout_Q[31:0];
assign jump_addr[31:0] = {PC_Current[31:28], Inst[25:0], 2'b00};
REG32 ALUOut(.CE(1'b1),
.clk(clk),
.D(res[31:0]),
.rst(1'b0),
.Q(ALUout_Q[31:0]));
REG32 IR(.CE(IRWrite),
.clk(clk),
.D(data2CPU[31:0]),
.rst(reset),
.Q(Inst[31:0]));
REG32 regMDR(.CE(1'b1),
.clk(clk),
.D(data2CPU[31:0]),
.rst(1'b0),
.Q(MDR[31:0]));
REG32 PC(.CE(pc_ce),
.clk(clk),
.D(pc_next[31:0]),
.rst(reset),
.Q(PC_Current[31:0]));
MUX4T1_32 pc_select(.I0(res[31:0]),
.I1(branch_pc[31:0]),
.I2(jump_addr[31:0]),
.I3(j_reg_r[31:0]),
.s(PCSource[1:0]),
.o(pc_next[31:0]));
MUX4T1_5 Wt_addr_select(.I0(Inst[20:16]),
.I1(Inst[15:11]),
.I2(5'b11111),
.I3(5'b00000),
.s(RegDst[1:0]),
.o(Wt_addr[4:0]));
MUX2T1_32 ALU_dataA(.I0(PC_Current[31:0]),
.I1(rdata_A[31:0]),
.s(ALUSrcA),
.o(ALU_A[31:0]));
MUX4T1_32 ALU_dataB(.I0(data_out[31:0]),
.I1(four[31:0]),
.I2(Imm_32[31:0]),
.I3(offset[31:0]),
.s(ALUSrcB[1:0]),
.o(ALU_B[31:0]));
MUX2T1_32 M_addr_select(.I0(PC_Current[31:0]),
.I1(ALUout_Q[31:0]),
.s(IorD),
.o(M_addr[31:0]));
MUX4T1_32 Wt_data_select(.I0(ALUout_Q[31:0]),
.I1(MDR[31:0]),
.I2({Inst[15:0],16'h0000}),
.I3(PC_Current[31:0]),
.s(MemtoReg[1:0]),
.o(Wt_data[31:0]));
ALU U1(.A(ALU_A[31:0]),
.ALU_operation(ALU_operation[2:0]),
.B(ALU_B[31:0]),
.overflow(overflow),
.res(res[31:0]),
.zero(zero));
Regs U2(.clk(clk),
.L_S(RegWrite),
.rst(reset),
.R_addr_A(Inst[25:21]),
.R_addr_B(Inst[20:16]),
.Wt_addr(Wt_addr[4:0]),
.Wt_data(Wt_data[31:0]),
.rdata_A(rdata_A[31:0]),
.rdata_B(data_out[31:0]));
Ext_32 ext(.imm_16(Inst[15:0]),
.Imm_32(Imm_32[31:0]));
endmodule