Skip to content

Commit 02f9734

Browse files
committed
improved handling on branching
1 parent 9d4bc46 commit 02f9734

File tree

6 files changed

+290
-125
lines changed

6 files changed

+290
-125
lines changed

pipelined/modules/register_file.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module register_file(
1313
assign read_data1 = (rs1 == 0) ? 64'b0 : registers[rs1];
1414
assign read_data2 = (rs2 == 0) ? 64'b0 : registers[rs2];
1515

16-
always @(*) begin
16+
always @(posedge clk) begin
1717
if (reg_write && rd != 0)
1818
registers[rd] <= write_data;
1919
end

pipelined/testcases/6.s

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
begin:
2+
addi x1, x0, 10
3+
addi x2, x1, 5
4+
addi x3, x1, 20
5+
add x4, x2, x3
6+
addi x5, x4, 5
7+
addi x6, x0, 100
8+
sub x7, x5, x6
9+
nop
10+
end:
11+
nop
12+

pipelined/testcases/7.s

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
begin:
2+
beq x0, x0, L1
3+
addi x7, x0, 4
4+
addi x8, x0, 5
5+
addi x9, x0, 6
6+
7+
L1:
8+
addi x5, x0, 4
9+
addi x6, x0, 5
10+
11+
end:
12+
nop

pipelined/testcases/assembler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def generate_testbench(instructions):
327327
328328
// Show ID stage activity
329329
$display("ID Stage: rs1=x%0d (%0d), rs2=x%0d (%0d), rd=x%0d",
330-
cpu.rs1, cpu.reg_read_data1, cpu.rs2, cpu.reg_read_data2, cpu.rd);
330+
cpu.rs1, cpu.reg_read_data1, cpu.rs2, cpu.reg_read_data2, cpu.reg_rd);
331331
332332
// Show EX stage activity (removed alu_control as it doesn't exist)
333333
$display("EX Stage: ALU Result=%0h", cpu.alu_result);
@@ -341,9 +341,9 @@ def generate_testbench(instructions):
341341
cpu.alu_result, cpu.mem_read_data);
342342
343343
// Show WB stage activity
344-
if (cpu.reg_write && cpu.rd != 0)
344+
if (cpu.reg_write && cpu.reg_rd != 0)
345345
$display("WB Stage: Writing %0d to register x%0d",
346-
cpu.reg_write_data, cpu.rd);
346+
cpu.reg_write_data, cpu.reg_rd);
347347
348348
// Control signals
349349
$display("Control signals: branch=%b, mem_read=%b, mem_to_reg=%b, mem_write=%b, alu_src=%b, reg_write=%b",

0 commit comments

Comments
 (0)