forked from skynatepro/MIPS32
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpu.v
More file actions
147 lines (130 loc) · 3.47 KB
/
Copy pathcpu.v
File metadata and controls
147 lines (130 loc) · 3.47 KB
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
`timescale 1ns / 1ps
module cpu(
input clk,
input rst
);
wire [31:0] alu_operand;
wire [31:0] alu_otp;
wire [31:0] pc_instaddr;
wire [31:0] instruction;
wire [31:0] sign_extend;
wire [31:0] reg1data;
wire [31:0] reg2data;
wire [31:0] regwrdata;
wire [31:0] data_mem_in;
wire [31:0] data_mem_out;
wire [1:0] pcControl;
wire [2:0] alu_op;
wire [4:0] reg_radd0;
wire [4:0] reg_radd1;
wire [4:0] reg_waddr;
wire [5:0] alu_control_otp;
wire reg_wr_add_control;
wire datamem_readen;
wire datawr_select;
wire datamemwriteen;
wire alusrcselect;
wire reg_wr_en;
wire branch_control;
wire jump_control;
wire alu_zero;
wire overflow_signal;
ProgramCounter prcount (
.clk(clk),
.reset(rst),
.zero(alu_zero),
.branch(branch_control),
.jump(jump_control),
.jumpAddress(instruction[25:0]),
.branchOffset(instruction[15:0]),
.regAddress(reg1data),
.pc(pc_instaddr)
);
InstructionMemoryModule instructionMemory(
.clk(clk),
.address(pc_instaddr),
.readEnable(1'b1),
.writeEnable(1'b0),
.dataIn(32'h000000),
.dataOut(instruction)
);
control_unit signals(
.instruction(instruction),
.RegDst(reg_wr_add_control),
.MemRead(datamem_readen),
.MemToReg(datawr_select),
.ALUOp(alu_op),
.MemWrite(datamemwriteen),
.ALUSrc(alusrcselect),
.RegWrite(reg_wr_en),
.Branch(branch_control),
.Jump(jump_control)
);
assign reg_radd0 = instruction[25:21];
assign reg_radd1 = instruction[20:16];
regmux2x1 reg_wr_dst(
.select(reg_wr_add_control),
.in0(reg_radd1),
.in1(instruction[15:11]),
.out(reg_waddr)
);
Register_File regfile(
.clk(clk),
.read_addr1(reg_radd0),
.read_addr2(reg_radd1),
.write_addr(reg_waddr),
.write_data(regwrdata),
.write_enable(reg_wr_en),
.read_data1(reg1data),
.read_data2(reg2data)
);
signExtension sign(
.in(instruction[15:0]),
.out(sign_extend)
);
mux2x1 alusrc_select(
.select(alusrcselect),
.in0(reg2data),
.in1(sign_extend),
.out(alu_operand)
);
alu_control alucntrl(
.instruction(instruction),
.ALUOp(alu_op),
.ALUFn(alu_control_otp)
);
ALU alu(
.clk(clk),
.a(reg1data),
.b(alu_operand),
.alufn(alu_control_otp),
.otp(alu_otp),
.zero(alu_zero),
.overflow(overflow_signal)
);
MainMemoryModule data_mem(.clk(clk),
.address(alu_otp),
.readEnable(datamem_readen),
.writeEnable(datamemwriteen),
.dataIn(data_mem_in),
.dataOut(data_mem_out)
);
mux2x1 write_select(.select(datawr_select),
.in1(data_mem_out),
.in0(alu_otp),
.out(regwrdata)
);
assign data_mem_in=reg2data;
always @(posedge clk)
begin
$display("reg_radd0- %d - reg_radd1 - %d",reg_radd0,reg_radd1);
$display("INSTRUCTION=%h - reg1data=%h - reg2data=%h - alu_control_otp=%d - datamemwriteen=%d - data_mem_in=%d - alu_otp=%h",
instruction,
reg1data,
reg2data,
alu_control_otp,
datamemwriteen,
data_mem_in,
alu_otp);
end
endmodule