Skip to content

Commit 893e83a

Browse files
authored
Merge pull request #24 from quantumxiaol/CPU_Liu
8'd58
2 parents c986ca3 + 6961871 commit 893e83a

6 files changed

Lines changed: 31 additions & 19 deletions

File tree

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,14 @@ Dec 11 Liu 添加了/lib/decoder_2_4
4141

4242
Dec 26 Liu 添加了缺失的逻辑运算指令的实现
4343
添加Stall,多过了1条指令。
44-
验证跳转指令,修改sel_alu_src,在验证8'd36中出现环路,模拟无法停止,
44+
45+
Dec 27 Liu 验证跳转指令,修改sel_alu_src,在验证8'd36中出现环路,模拟无法停止,
4546
猜测代码因为逻辑环路导致某个寄存器的值在一个时钟周期内反复横跳无法仿真,
4647
或者是一些奇奇怪怪的写回情况会导致仿真程序一直运行下去。
4748

48-
Dec 26 Liu 添加hi lo寄存器 hi_lo_reg.v,
49+
Dec 27 Liu 添加hi lo寄存器 hi_lo_reg.v,
4950
数据移动指令(mfhi,mflo,mthi,mtlo),
50-
完善除法、乘法。
51+
完善除法。到达8'd45。
52+
53+
完善乘法。到达8'd58。
5154

Sample/EX.v

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,16 @@ module EX(
235235

236236
assign mul_signed = inst_mult;
237237

238-
reg [31:0] mul_ina;
239-
reg [31:0] mul_inb;
238+
// reg [31:0] mul_ina;
239+
// reg [31:0] mul_inb;
240240

241241

242242
mul u_mul(
243243
.clk (clk ),
244244
.resetn (~rst ),
245245
.mul_signed (mul_signed ),
246-
.ina (mul_ina ), // 乘法源操作数1
247-
.inb (mul_inb ), // 乘法源操作数2
246+
.ina (rf_rdata1 ), // 乘法源操作数1
247+
.inb (rf_rdata2 ), // 乘法源操作数2
248248
.result (mul_result ) // 乘法结果 64bit
249249
);
250250

Sample/ID.v

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ module ID(
2626
input wire [`EX_TO_RF_WD-1:0] ex_to_rf_bus,
2727
//
2828
input wire [`MEM_TO_RF_WD-1:0] mem_to_rf_bus,
29-
30-
output wire [71:0] id_hi_lo_bus,
29+
3130
input wire [65:0] ex_hi_lo_bus,
31+
output wire [71:0] id_hi_lo_bus,
32+
3233

3334
output wire [`LoadBus-1:0] id_load_bus,
3435
output wire [`SaveBus-1:0] id_save_bus,
@@ -153,7 +154,14 @@ module ID(
153154
.rdata2 (rdata2 ),
154155
.we (wb_rf_we ),
155156
.waddr (wb_rf_waddr ),
156-
.wdata (wb_rf_wdata )
157+
.wdata (wb_rf_wdata )//,
158+
// .hi_we (hi_we ),
159+
// .lo_we (lo_we ),
160+
// .hi_wdata (hi_wdata ),
161+
// .lo_wdata (lo_wdata ),
162+
// .hi_rdata (hi_rdata ),
163+
// .lo_rdata (lo_rdata )
164+
157165
);
158166

159167
wire [31:0] hi, hi_rdata;
@@ -171,9 +179,9 @@ module ID(
171179
} = ex_hi_lo_bus;
172180

173181
hi_lo_reg u_hi_lo_reg(
174-
.clk (clk ),
175-
.hi_we (hi_we ),
176-
.lo_we (lo_we ),
182+
.clk (clk ),
183+
.hi_we (hi_we ),
184+
.lo_we (lo_we ),
177185
.hi_wdata (hi_wdata ),
178186
.lo_wdata (lo_wdata ),
179187
.hi_rdata (hi_rdata ),
@@ -219,10 +227,10 @@ module ID(
219227
wire inst_sltiu;// 将寄存器 rs 的值与有符号扩展至 32 位的立即数 imm 进行无符号数比较,
220228
// 如果寄存器 rs 中的值小,则寄存器 rt 置 1;否则寄存器 rt 置 0。
221229

222-
wire inst_mult;
223-
wire inst_multu;
224-
wire inst_div;
225-
wire inst_divu;
230+
wire inst_mult; // 有符号乘法,寄存器 rs 的值乘以寄存器 rt 的值,乘积的低半部分和高半部分分别写入 LO 寄存器和 HI 寄存器。
231+
wire inst_multu; // 无符号乘法,寄存器 rs 的值乘以寄存器 rt 的值,乘积的低半部分和高半部分分别写入 LO 寄存器和 HI 寄存器。
232+
wire inst_div; // 有符号除法,寄存器 rs 的值除以寄存器 rt 的值,商写入 LO 寄存器中,余数写入 HI 寄存器中。
233+
wire inst_divu; // 无符号除法,寄存器 rs 的值除以寄存器 rt 的值,商写入 LO 寄存器中,余数写入 HI 寄存器中。
226234

227235

228236

Sample/MEM.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ module MEM(
106106
assign rf_wdata = sel_rf_res & data_ram_en ? mem_result : ex_result;
107107

108108
assign mem_to_wb_bus = {
109+
109110
mem_pc, // 69:38
110111
rf_we, // 37
111112
rf_waddr, // 36:32

Sample/lib/regfile.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ module regfile(
1010
input wire [4:0] waddr,
1111
input wire [31:0] wdata
1212
);
13-
reg [31:0] reg_array [31:0];
13+
reg [31:0] reg_array [31:0];
1414
// write
1515
always @ (posedge clk) begin
1616
if (we && waddr!=5'b0) begin
1717
reg_array[waddr] <= wdata;
18-
end
18+
end
1919
end
2020

2121
// read out 1

screenshot/error0xbfc371a0.jpg

353 KB
Loading

0 commit comments

Comments
 (0)