diff options
| author | taitep <taitep@taitep.se> | 2025-10-07 20:23:59 +0200 |
|---|---|---|
| committer | taitep <taitep@taitep.se> | 2025-10-07 20:23:59 +0200 |
| commit | ee5f5a2ec41ed426440346ff47339b63c2cf7c1d (patch) | |
| tree | edc61c079f6a0070ddee7813966ad30a04ee23da /src/instructions/rvi.rs | |
| parent | 361b36fbd1ba4a710abbc866da1c641545a6d53f (diff) | |
FIRST INSTRUCTION WORKING
Diffstat (limited to 'src/instructions/rvi.rs')
| -rw-r--r-- | src/instructions/rvi.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/instructions/rvi.rs b/src/instructions/rvi.rs new file mode 100644 index 0000000..8e7dade --- /dev/null +++ b/src/instructions/rvi.rs @@ -0,0 +1,28 @@ +use crate::{ + core::{Core, InstructionResult}, + decode::Instruction, + instructions::{ + OpcodeHandler, + gen_tools::insert_funct3_splitter, + opcodes::{FUNCT3_ADDI, OP_IMM}, + }, +}; + +pub(super) fn add_instrs(list: &mut [OpcodeHandler; 32]) { + let funct3_split_op_imm = insert_funct3_splitter(&mut list[OP_IMM as usize].splitter); + funct3_split_op_imm[FUNCT3_ADDI as usize].handler = + Some(super::InstructionHandler { runner: addi }); +} + +fn addi(core: &mut Core, instr: Instruction) -> InstructionResult { + eprintln!("Running ADDI"); + + core.reg_write( + instr.rd(), + core.reg_read(instr.rs1()).wrapping_add(instr.imm_i()), + ); + + core.pc = core.pc.wrapping_add(4); + + InstructionResult::Normal +} |
