Skip to content

Commit 155c84f

Browse files
Implement ADD and SUB instructions
1 parent bc80713 commit 155c84f

File tree

2 files changed

+87
-3
lines changed

2 files changed

+87
-3
lines changed

documentation/Modules/Hart.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,58 @@ The instruction at the program pointer is requested from memory.
77
### Stage 1
88
The instruction is available from memory and the decoder is now emitting the decoded instruction. We store the decoded instructions in buffers for access in later stages. Most instructions can simply execute in this stage and then set the stage counter back to 0 and increase the program pointer.
99
## Stage 2
10-
Currently only the `LW` instruction uses stage 2, since in stage 1 `LW` requests the info from memory and then in stage 2 it takes the value from memory and writes it to the register.
10+
Currently only the `LW` instruction uses stage 2, since in stage 1 `LW` requests the info from memory and then in stage 2 it takes the value from memory and writes it to the register.
11+
## Implemented Instructions
12+
### Main Integer Instructions
13+
- [x] LUI
14+
- [x] AUIPC
15+
- [x] ADDI
16+
- [x] SLTI
17+
- [x] SLTIU
18+
- [x] XORI
19+
- [x] ORI
20+
- [x] ANDI
21+
- [ ] SLLI
22+
- [ ] SRLI
23+
- [ ] SRAI
24+
- [ ] ADD
25+
- [ ] SUB
26+
- [ ] SLL
27+
- [ ] SLT
28+
- [ ] SLTU
29+
- [ ] XOR
30+
- [ ] SRL
31+
- [ ] SRA
32+
- [ ] OR
33+
- [ ] AND
34+
- [ ] LB
35+
- [ ] LH
36+
- [x] LW
37+
- [ ] LBU
38+
- [ ] LHU
39+
- [ ] SB
40+
- [ ] SH
41+
- [x] SW
42+
- [ ] JAL
43+
- [ ] JALR
44+
- [ ] BEQ
45+
- [ ] BNE
46+
- [ ] BLT
47+
- [ ] BGE
48+
- [ ] BLTU
49+
- [ ] BGEU
50+
### Other Integer Instructions
51+
- [ ] FENCE
52+
- [ ] FENCEI
53+
- [ ] ECALL
54+
- [ ] EBREAK
55+
- [ ] SRET
56+
- [ ] MRET
57+
- [ ] WFI
58+
- [ ] SFENCEVMA
59+
- [ ] CSRRW
60+
- [ ] CSRRS
61+
- [ ] CSRRC
62+
- [ ] CSRRWI
63+
- [ ] CSRRSI
64+
- [ ] CSRRCI

src/main/scala/RISCV/Main.scala

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class Main() extends Module {
224224
program_pointer := program_pointer + 1.U;
225225
stage := 0.U;
226226

227-
printf("[XORI] Rs1: %d Rd: %d Immediate: %b\n", decoder.io.rs1, decoder.io.rd, decoder.io.immediate);
227+
printf("[ORI] Rs1: %d Rd: %d Immediate: %b\n", decoder.io.rs1, decoder.io.rd, decoder.io.immediate);
228228
}
229229

230230
// ANDI
@@ -238,7 +238,37 @@ class Main() extends Module {
238238
program_pointer := program_pointer + 1.U;
239239
stage := 0.U;
240240

241-
printf("[XORI] Rs1: %d Rd: %d Immediate: %b\n", decoder.io.rs1, decoder.io.rd, decoder.io.immediate);
241+
printf("[ANDI] Rs1: %d Rd: %d Immediate: %b\n", decoder.io.rs1, decoder.io.rd, decoder.io.immediate);
242+
}
243+
244+
// ADD
245+
is("b0000000_000_0110011".U) {
246+
registers.io.read_address_a := decoder.io.rs1;
247+
registers.io.read_address_b := decoder.io.rs2;
248+
249+
registers.io.write_address := decoder.io.rd;
250+
registers.io.write_enable := true.B;
251+
registers.io.in := registers.io.out_a + registers.io.out_b;
252+
253+
program_pointer := program_pointer + 1.U;
254+
stage := 0.U;
255+
256+
printf("[ADD] Rs1: %d Rs2: %d Rd: %d\n", decoder.io.rs1, decoder.io.rs2, decoder.io.rd);
257+
}
258+
259+
// SUB
260+
is("b0110000_000_0110011".U) {
261+
registers.io.read_address_a := decoder.io.rs1;
262+
registers.io.read_address_b := decoder.io.rs2;
263+
264+
registers.io.write_address := decoder.io.rd;
265+
registers.io.write_enable := true.B;
266+
registers.io.in := registers.io.out_a - registers.io.out_b;
267+
268+
program_pointer := program_pointer + 1.U;
269+
stage := 0.U;
270+
271+
printf("[SUB] Rs1: %d Rs2: %d Rd: %d\n", decoder.io.rs1, decoder.io.rs2, decoder.io.rd);
242272
}
243273
}
244274
}

0 commit comments

Comments
 (0)