-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.v
91 lines (83 loc) · 1.99 KB
/
controller.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
`timescale 1ns / 1ps
`include "define_instr_dec.vh"
`include "define_alu_control.vh"
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 2017/10/23 15:21:30
// Design Name:
// Module Name: controller
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module controller(
input wire clk,rst,
//decode stage
input wire [31:0] instrD,
output wire pcsrcD,branchD,equalD,jumpD,
output wire is_IMM,
//execute stage
input wire flushE,
output wire memtoregE,alusrcE,
output wire regdstE,regwriteE,
output wire[4:0] alucontrolE,
//mem stage
output wire memtoregM,memwriteM,
regwriteM,hilo_writeM,hi_to_regM,lo_to_regM,
//write back stage
output wire memtoregW,regwriteW,hilo_writeW
);
//decode stage
wire memtoregD,memwriteD,alusrcD,
regdstD,regwriteD;
wire hilo_writeD;
wire hi_to_regD; //是否将hilo中数据写入寄存器
wire lo_to_regD;
wire[4:0] alucontrolD;
//execute stage
wire memwriteE;
wire hilo_writeE;
wire hi_to_regE;
wire lo_to_regE;
maindec md(
instrD,
memtoregD,memwriteD,
branchD,alusrcD,
regdstD,regwriteD,
jumpD,
is_IMM,
hilo_writeD,
hi_to_regD,
lo_to_regD
);
aludec ad(instrD,alucontrolD);
assign pcsrcD = branchD & equalD;
//pipeline registers
floprc #(13) regE(
clk,
rst,
flushE,
{memtoregD,memwriteD,alusrcD,regdstD,regwriteD,alucontrolD,hilo_writeD,hi_to_regD,lo_to_regD},
{memtoregE,memwriteE,alusrcE,regdstE,regwriteE,alucontrolE,hilo_writeE,hi_to_regE,lo_to_regE}
);
flopr #(8) regM(
clk,rst,
{memtoregE,memwriteE,regwriteE,hilo_writeE,hi_to_regE,lo_to_regE},
{memtoregM,memwriteM,regwriteM,hilo_writeM,hi_to_regM,lo_to_regM}
);
flopr #(8) regW(
clk,rst,
{memtoregM,regwriteM,hilo_writeM},
{memtoregW,regwriteW,hilo_writeW}
);
endmodule