fix: align disasm output correctly

This commit is contained in:
2025-05-14 20:21:13 +09:00
parent 1aa3e2ba84
commit 22d7c5571f

View File

@@ -57,9 +57,18 @@ impl Instruction {
impl fmt::Display for Instruction { impl fmt::Display for Instruction {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:04x}: ", self.start).unwrap(); write!(f, "{:04x}: ", self.start).unwrap();
for b in self.raw.iter() {
write!(f, "{:02x}", b).unwrap(); write!(
} f,
"{:<10}",
self.raw
.iter()
.map(|b| format!("{:02x}", b))
.collect::<Vec<String>>()
.join("")
)
.unwrap();
write!(f, "\t\t{}", self.opcode) write!(f, "\t\t{}", self.opcode)
} }
} }
@@ -330,14 +339,14 @@ impl std::fmt::Display for Displacement {
match self { match self {
Self::IByte(b) => { Self::IByte(b) => {
if *b > 0 { if *b > 0 {
write!(f, " + {}", b) write!(f, " + {:#x}", b)
} else { } else {
write!(f, " - {:#x}", b * -1) write!(f, " - {:#x}", b * -1)
} }
} }
Self::IWord(w) => { Self::IWord(w) => {
if *w > 0 { if *w > 0 {
write!(f, " + {}", w) write!(f, " + {:#x}", w)
} else { } else {
write!(f, " - {:#x}", w * -1) write!(f, " - {:#x}", w * -1)
} }