Files
dcb/dcb/src/game/exe/instruction/basic/lui.rs
Filipe Rodrigues 94bb2d780d Renamed some instructions' register names for consistency.
Made `BasicInst::Lui` it's own type.
Started working on `PseudoInst`.
Removed `dcb::game::exe` and `decompiler` binary temporarily.
Fixed the game file not being read / written correctly.
2020-11-05 15:59:59 +00:00

48 lines
861 B
Rust

//! Lui instruction
// Imports
use crate::game::exe::instruction::Register;
use int_conv::{Truncated, ZeroExtended};
/// Raw representation
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub struct LuiRaw {
/// Rt
pub t: u32,
/// Immediate
pub i: u32,
}
/// Load instructions
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
#[derive(derive_more::Display)]
#[display(fmt = "lui {dst}, {value:#x}")]
pub struct LuiInst {
/// Destination register, `rt`
pub dst: Register,
/// Value
pub value: u16,
}
impl LuiInst {
/// Decodes this instruction
#[must_use]
pub fn decode(raw: LuiRaw) -> Option<Self> {
Some(Self {
dst: Register::new(raw.t)?,
value: raw.i.truncated::<u16>(),
})
}
/// Encodes this instruction
#[must_use]
pub fn encode(self) -> LuiRaw {
LuiRaw {
t: self.dst.idx(),
i: self.value.zero_extended::<u32>(),
}
}
}