-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingle_cycle_top.sv
118 lines (106 loc) · 2.34 KB
/
single_cycle_top.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
`include "pc.sv"
`include "mux2x1.sv"
`include "PC_Adder.sv"
`include "ALU_Decoder.sv"
`include "Main_Decoder.sv"
`include "Control_unit_top.sv"
`include "alu.sv"
`include "data_mem.sv"
`include "instr_mem.sv"
`include "Reg_file.sv"
`include "mux4x1.sv"
`include "sign_extend.sv"
module single_cycle_top(clk,rst);
input clk,rst;
wire [31:0] PC, PCPlus4 ,RD_instr, RD1_top,RD2_top, Imm_Ext_top,ALU_Result,ReadData,SrcB,Result,PCTarget,PCNext ;
wire RegWrite_top, MemWrite,ALUSrc;
wire [1:0]ImmSrc,ResultSrc;
wire [2:0] ALUControl_top;
P_C pc(
.PC_NEXT(PCNext),
.PC(PC),
.rst(rst),
.clk(clk)
);
Mux2x1 mux_PC_select(
.a(PCPlus4), // S0
.b(PCTarget), // S1
.s(PCSrc),
.y(PCNext)
);
PC_Adder pc_plus4(
.a(PC),
.b(32'd4),
.c(PCPlus4)
);
PC_Adder branch_offset_adder(
.a(PC),
.b(Imm_Ext_top),
.c(PCTarget)
);
Instr_mem IM(
.A(PC),
.rst(rst),
.RD(RD_instr)
);
reg_file RF(
.WE3(RegWrite_top), // write enable
.clk(clk),
.rst(rst),
.WD3(Result), //(write back data)
.A1(RD_instr[19:15]), //RS1
.A2(RD_instr[24:20]), // RS2
.A3(RD_instr[11:7]), // RD;
.RD1(RD1_top),
.RD2(RD2_top)
);
sign_extend signextnd(
.In(RD_instr),
.ImmSrc(ImmSrc),
.Imm_Ext(Imm_Ext_top)
);
Mux2x1 mux_regfile_2_alu(
.a(RD2_top),
.b(Imm_Ext_top),
.s(ALUSrc),
.y(SrcB)
);
alu ALU(
.A(RD1_top),
.B(SrcB),
.ALUControl(ALUControl_top),
.Result(ALU_Result) ,
.Negative(),
.Zero(Zero),
.Carry(),
.OverFlow()
);
Control_Unit_Top cntrl_unit_top(
.Op(RD_instr[6:0]),
.Zero(Zero),
.PCSrc(PCSrc),
.ResultSrc(ResultSrc),
.MemWrite(MemWrite),
.ALUSrc(ALUSrc),
.ImmSrc(ImmSrc),
.RegWrite(RegWrite_top),
.funct3(RD_instr[14:12]),
.funct7(RD_instr[31:25]),
.ALUControl(ALUControl_top)
);
data_mem DATA_MEM (
.A(ALU_Result),
.WD(RD2_top),
.clk(clk),
.WE(MemWrite),
.rst(rst),
.RD(ReadData)
);
Mux4x1 mux_data_mem_2_regfile(
.a(ALU_Result),
.b(ReadData),
.c(PCPlus4),
.s(ResultSrc),
.y(Result)
);
endmodule