Skip to content

Commit fb287ce

Browse files
implement jalr
1 parent 4d62b5e commit fb287ce

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

documentation/Modules/Hart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Currently only the `LW` instruction uses stage 2, since in stage 1 `LW` requests
4040
- [ ] SH
4141
- [x] SW
4242
- [x] JAL
43-
- [ ] JALR
43+
- [x] JALR
4444
- [ ] BEQ
4545
- [ ] BNE
4646
- [ ] BLT

src/main/scala/RISCV/Main.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,20 @@ class Main() extends Module {
442442

443443
printf("[JAL] Rd: %d Immediate: %b\n", decoder.io.rd, decoder.io.immediate);
444444
}
445+
446+
// JALR
447+
is("b000_1100111".U) {
448+
registers.io.read_address_a := decoder.io.rs1;
449+
450+
registers.io.write_address := decoder.io.rd;
451+
registers.io.write_enable := true.B;
452+
registers.io.in := program_pointer + 1.U;
453+
454+
program_pointer := (registers.io.out_a.zext + decoder.io.immediate.asSInt).asUInt;
455+
stage := 0.U;
456+
457+
printf("[JALR] RS1: %d Rd: %d Immediate: %b\n", decoder.io.rs1, decoder.io.rd, decoder.io.immediate);
458+
}
445459
}
446460
}
447461

src/test/scala/RISCV/MainSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ class MainSpec extends AnyFreeSpec with Matchers with ChiselSim {
99
"Main should execute LUI correctly" in {
1010
simulate(new Main()) { dut =>
1111
dut.io.debug_write.poke(true.B);
12-
dut.io.debug_write_data.poke("b000000000110_00000_000_00001_0010011".U(32.W));
12+
dut.io.debug_write_data.poke("b000000000011_00000_000_00001_0010011".U(32.W));
1313
dut.io.debug_write_addressess.poke(0.U);
1414

1515
dut.clock.step(1);
1616

1717
dut.io.debug_write.poke(true.B);
18-
dut.io.debug_write_data.poke("b00000000001000000000_00001_1101111".U(32.W));
18+
dut.io.debug_write_data.poke("b000000000000_00001_000_00001_1100111".U(32.W));
1919
dut.io.debug_write_addressess.poke(1.U);
2020

2121
dut.clock.step(1);

0 commit comments

Comments
 (0)