summaryrefslogtreecommitdiff
path: root/src/instructions/rvi.rs
diff options
context:
space:
mode:
authortaitep <taitep@taitep.se>2025-12-21 16:29:28 +0100
committertaitep <taitep@taitep.se>2025-12-21 16:29:28 +0100
commitc05ba60c3c6ebe89a3db666c316929e0d0d2fdfa (patch)
tree89f33937b3702e14eab06ade1f00b456df8a1144 /src/instructions/rvi.rs
parentacc267a460464c3dffa59a62f900965cfd342e61 (diff)
Implement ANDI and BEQ
Diffstat (limited to 'src/instructions/rvi.rs')
-rw-r--r--src/instructions/rvi.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/instructions/rvi.rs b/src/instructions/rvi.rs
index a212b8d..3aadc10 100644
--- a/src/instructions/rvi.rs
+++ b/src/instructions/rvi.rs
@@ -32,6 +32,14 @@ pub fn addiw(core: &mut Core, instr: Instruction) -> InstructionResult {
InstructionResult::Normal
}
+pub fn andi(core: &mut Core, instr: Instruction) -> InstructionResult {
+ core.reg_write(instr.rd(), core.reg_read(instr.rs1()) & instr.imm_i());
+
+ core.advance_pc();
+
+ InstructionResult::Normal
+}
+
// TODO: Support misaligned memory access
pub fn sd(core: &mut Core, instr: Instruction) -> InstructionResult {
let addr = core.reg_read(instr.rs1()).wrapping_add(instr.imm_s());
@@ -115,6 +123,16 @@ pub fn jal(core: &mut Core, instr: Instruction) -> InstructionResult {
InstructionResult::Normal
}
+pub fn beq(core: &mut Core, instr: Instruction) -> InstructionResult {
+ if core.reg_read(instr.rs1()) == core.reg_read(instr.rs2()) {
+ core.pc = core.pc.wrapping_add(instr.imm_b());
+ } else {
+ core.advance_pc();
+ }
+
+ InstructionResult::Normal
+}
+
pub fn slli(core: &mut Core, instr: Instruction) -> InstructionResult {
core.reg_write(instr.rd(), core.reg_read(instr.rs1()) << instr.imm_shamt());