use super::Encoding::{self, T1};
use super::Instruction;
use super::{
ArmVersion::{V6M, V7EM, V7M, V8M},
Pattern,
};
use crate::{
core::ItState,
core::{Effect, Processor, RunError},
decoder::DecodeError,
helpers::BitAccess,
instructions::{unpredictable, DecodeHelper},
registers::RegisterIndex,
};
pub struct Bx {
rm: RegisterIndex,
ns: bool,
}
impl Instruction for Bx {
fn patterns() -> &'static [Pattern] {
&[
Pattern {
encoding: T1,
versions: &[V6M, V7M, V7EM],
expression: "010001110xxxx(0)(0)(0)",
},
Pattern {
encoding: T1,
versions: &[V8M],
expression: "010001110xxxxx(0)(0)",
},
]
}
fn try_decode(encoding: Encoding, ins: u32, state: ItState) -> Result<Self, DecodeError> {
debug_assert_eq!(encoding, T1);
unpredictable(state.in_it_block_not_last())?;
Ok(Self {
rm: ins.reg4(3),
ns: ins.bit(2),
})
}
fn execute(&self, proc: &mut Processor) -> Result<Effect, RunError> {
if self.ns {
todo!()
}
let target = proc[self.rm];
proc.bx_write_pc(target)?;
Ok(Effect::Branch)
}
fn name(&self) -> String {
if self.ns { "bxns" } else { "bx" }.into()
}
fn args(&self, _pc: u32) -> String {
self.rm.to_string()
}
}