Implement ADD
This commit is contained in:
@@ -13,6 +13,11 @@ use crate::{
|
||||
|
||||
pub(crate) fn find_and_exec(instr: Instruction, core: &mut Core) -> Option<InstructionResult> {
|
||||
match instr.opcode_noncompressed() {
|
||||
0b01100 => match (instr.funct7(), instr.funct3()) {
|
||||
// OP
|
||||
(0b0000000, 0b000) => Some(rvi::add(core, instr)),
|
||||
_ => None,
|
||||
},
|
||||
0b00100 => match instr.funct3() {
|
||||
// OP_IMM
|
||||
0b000 => Some(rvi::addi(core, instr)),
|
||||
|
||||
@@ -11,6 +11,16 @@ use crate::{
|
||||
mem::PageNum,
|
||||
};
|
||||
|
||||
pub fn add(core: &mut Core, instr: Instruction) -> InstructionResult {
|
||||
core.reg_write(
|
||||
instr.rd(),
|
||||
core.reg_read(instr.rs1())
|
||||
.wrapping_add(core.reg_read(instr.rs2())),
|
||||
);
|
||||
core.advance_pc();
|
||||
InstructionResult::Normal
|
||||
}
|
||||
|
||||
pub fn addi(core: &mut Core, instr: Instruction) -> InstructionResult {
|
||||
core.reg_write(
|
||||
instr.rd(),
|
||||
|
||||
Reference in New Issue
Block a user