Fixed wrong formatting for some instructions.

This commit is contained in:
2020-11-03 12:14:12 +00:00
parent 0e58b3df15
commit b974e89d74
6 changed files with 18 additions and 18 deletions

View File

@@ -57,7 +57,7 @@ pub struct AluImmInst {
/// Lhs argument, `rs`
pub lhs: Register,
/// Rhs immediate argument
/// Rhs argument, immediate
pub rhs: u32,
/// Opcode

View File

@@ -69,6 +69,6 @@ impl fmt::Display for JmpInst {
JmpKind::Link => "jal",
};
write!(f, "{mnemonic} {target}")
write!(f, "{mnemonic} {target:#x}")
}
}

View File

@@ -1,7 +1,7 @@
//! Load instructions
// Imports
use crate::game::exe::instruction::Register;
use crate::{game::exe::instruction::Register, util::SignedHex};
use int_conv::{Signed, Truncated, ZeroExtended};
use std::{convert::TryFrom, fmt};
@@ -104,6 +104,6 @@ impl fmt::Display for LoadInst {
LoadOpcode::WordRight => "lwr",
};
write!(f, "{mnemonic} {dest}, {offset}({source})")
write!(f, "{mnemonic} {dest}, {:#x}({source})", SignedHex(offset))
}
}

View File

@@ -39,14 +39,14 @@ pub struct ShiftImmRaw {
/// Shift immediate instructions
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub struct ShiftImmInst {
/// Source register, `rd`
pub source: Register,
/// Destination register, `rt`
pub dest: Register,
/// Immediate argument
pub arg: i16,
/// Lhs argument, `rd`
pub lhs: Register,
/// Rhs argument, immediate
pub rhs: i16,
/// Function
pub func: ShiftImmFunc,
@@ -59,9 +59,9 @@ impl ShiftImmInst {
let func = ShiftImmFunc::try_from(raw.f.truncated::<u8>()).ok()?;
Some(Self {
source: Register::new(raw.t)?,
lhs: Register::new(raw.t)?,
dest: Register::new(raw.d)?,
arg: raw.i.truncated::<u16>().as_signed(),
rhs: raw.i.truncated::<u16>().as_signed(),
func,
})
}
@@ -69,9 +69,9 @@ impl ShiftImmInst {
/// Encodes this instruction
#[must_use]
pub fn encode(self) -> ShiftImmRaw {
let t = self.source.idx();
let t = self.lhs.idx();
let d = self.dest.idx();
let i = self.arg.as_unsigned().zero_extended::<u32>();
let i = self.rhs.as_unsigned().zero_extended::<u32>();
let f = u8::from(self.func).zero_extended::<u32>();
ShiftImmRaw { f, t, d, i }
@@ -80,7 +80,7 @@ impl ShiftImmInst {
impl fmt::Display for ShiftImmInst {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let Self { source, dest, arg, func } = self;
let Self { lhs, dest, rhs, func } = self;
let mnemonic = match func {
ShiftImmFunc::LeftLogical => "sll",
@@ -88,6 +88,6 @@ impl fmt::Display for ShiftImmInst {
ShiftImmFunc::RightArithmetic => "sra",
};
write!(f, "{mnemonic} {dest}, {source}, {arg}")
write!(f, "{mnemonic} {dest}, {lhs}, {rhs:#x}")
}
}

View File

@@ -84,6 +84,6 @@ impl fmt::Display for SysInst {
SysFunc::Break => "break",
};
write!(f, "{mnemonic} {comment}")
write!(f, "{mnemonic} {comment:#x}")
}
}

View File

@@ -1,7 +1,7 @@
//! Store instructions
// Imports
use crate::game::exe::instruction::Register;
use crate::{game::exe::instruction::Register, util::SignedHex};
use int_conv::{Signed, Truncated, ZeroExtended};
use std::{convert::TryFrom, fmt};
@@ -101,6 +101,6 @@ impl fmt::Display for StoreInst {
StoreOpcode::WordLeft => "swl",
};
write!(f, "{mnemonic} {dest}, {offset}({source})")
write!(f, "{mnemonic} {dest}, {:#x}({source})", SignedHex(offset))
}
}