Implement DIV

This commit is contained in:
2025-12-30 17:27:42 +01:00
parent e5c5312566
commit 6a0e5e63c1
2 changed files with 8 additions and 0 deletions

View File

@@ -40,6 +40,7 @@ pub(crate) fn find_and_exec(instr: Instruction, core: &mut Core) -> Result<(), E
(0b101, 0b0100000) => rvi::sra(core, instr), (0b101, 0b0100000) => rvi::sra(core, instr),
(0b111, 0b0000000) => rvi::and(core, instr), (0b111, 0b0000000) => rvi::and(core, instr),
(0b100, 0b0000000) => rvi::xor(core, instr), (0b100, 0b0000000) => rvi::xor(core, instr),
(0b100, 0b0000001) => rvm::div(core, instr),
(0b110, 0b0000000) => rvi::or(core, instr), (0b110, 0b0000000) => rvi::or(core, instr),
_ => illegal(instr), _ => illegal(instr),
}, },

View File

@@ -6,4 +6,11 @@
// //
use crate::{core::Core, decode::Instruction, exceptions::Exception}; use crate::{core::Core, decode::Instruction, exceptions::Exception};
// multiplication
instr_op_r!(mul, u64::wrapping_mul); instr_op_r!(mul, u64::wrapping_mul);
// division
instr_op_r!(div, |a, b| match b {
0 => -1,
_ => i64::wrapping_div(a as i64, b as i64),
} as u64);