use crate::instruction::embive::CJ;
use crate::interpreter::{memory::Memory, Error, Interpreter, State};
use super::super::Execute;
impl<M: Memory> Execute<M> for CJ {
#[inline(always)]
fn execute(&self, interpreter: &mut Interpreter<'_, M>) -> Result<State, Error> {
interpreter.program_counter = interpreter.program_counter.wrapping_add_signed(self.0.imm);
Ok(State::Running)
}
}
#[cfg(test)]
mod tests {
use crate::{
format::{Format, TypeCJ},
instruction::embive::InstructionImpl,
interpreter::memory::SliceMemory,
};
use super::*;
#[test]
fn test_cj() {
let mut memory = SliceMemory::new(&[], &mut []);
let mut interpreter = Interpreter::new(&mut memory, 0);
let jal = TypeCJ { imm: 0xc };
let result = CJ::decode(jal.to_embive()).execute(&mut interpreter);
assert_eq!(result, Ok(State::Running));
assert_eq!(interpreter.program_counter, 0xc);
}
}