ft(interpreter): impl SAR

This commit is contained in:
2025-07-08 08:54:57 +09:00
parent be0b928a55
commit ecbe478dcd
3 changed files with 78 additions and 33 deletions

View File

@@ -9,7 +9,7 @@ use crate::{disasm::DisasmError, register::Register};
use core::fmt;
use std::{
cmp::Ordering,
ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Not, Shl, Shr, Sub},
ops::{Add, BitAnd, BitOr, BitXor, Div, Not, Shl, Shr, Sub},
};
pub type Byte = u8; // b
@@ -72,6 +72,20 @@ impl ImmediateOperand {
}
}
/// Sets or removes sign.
pub fn set_sign(self, sign: bool) -> Self {
match self {
Self::Byte(b) => {
let msb = 1 << 7;
Self::Byte(if sign { b | msb } else { b & !msb })
}
Self::Word(w) => {
let msb = 1 << 15;
Self::Word(if sign { w | msb } else { w & !msb })
}
}
}
/// Check if inner value is zero.
pub fn zero(&self) -> bool {
match self {
@@ -92,7 +106,7 @@ impl ImmediateOperand {
}
/// Check if least significant bit is set.
pub fn _lsb(&self) -> bool {
pub fn lsb(&self) -> bool {
match self {
Self::Byte(byte) => return byte & 1 == 1,
Self::Word(word) => return word & 1 == 1,