summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/instructions.rs1
-rw-r--r--src/instructions/rvi.rs10
2 files changed, 11 insertions, 0 deletions
diff --git a/src/instructions.rs b/src/instructions.rs
index 6e9fbd8..615dd7a 100644
--- a/src/instructions.rs
+++ b/src/instructions.rs
@@ -16,6 +16,7 @@ pub(crate) fn find_and_exec(instr: Instruction, core: &mut Core) -> Option<Instr
0b01100 => match (instr.funct7(), instr.funct3()) {
// OP
(0b0000000, 0b000) => Some(rvi::add(core, instr)),
+ (0b0100000, 0b000) => Some(rvi::sub(core, instr)),
(0b0000000, 0b111) => Some(rvi::and(core, instr)),
(0b0000000, 0b110) => Some(rvi::or(core, instr)),
_ => None,
diff --git a/src/instructions/rvi.rs b/src/instructions/rvi.rs
index 69670d0..df3d9d5 100644
--- a/src/instructions/rvi.rs
+++ b/src/instructions/rvi.rs
@@ -21,6 +21,16 @@ pub fn add(core: &mut Core, instr: Instruction) -> InstructionResult {
InstructionResult::Normal
}
+pub fn sub(core: &mut Core, instr: Instruction) -> InstructionResult {
+ core.reg_write(
+ instr.rd(),
+ core.reg_read(instr.rs1())
+ .wrapping_sub(core.reg_read(instr.rs2())),
+ );
+ core.advance_pc();
+ InstructionResult::Normal
+}
+
pub fn addi(core: &mut Core, instr: Instruction) -> InstructionResult {
core.reg_write(
instr.rd(),