summaryrefslogtreecommitdiff
path: root/src/instructions/rvi.rs
blob: 8e7dadecc895f2b65e3597b51cb49401f11851a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
}