chore: prettify printing
This commit is contained in:
@@ -22,6 +22,15 @@ impl fmt::Display for Operand {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::LowerHex for Operand {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Byte(b) => fmt::LowerHex::fmt(b, f),
|
||||
Self::Word(v) => fmt::LowerHex::fmt(v, f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[allow(dead_code)]
|
||||
/// A single 'line' of executable ASM is called an Instruction, which
|
||||
@@ -49,7 +58,7 @@ impl fmt::Display for Instruction {
|
||||
for b in self.raw.iter() {
|
||||
write!(f, "{:02x}", b).unwrap();
|
||||
}
|
||||
write!(f, "\t{}", self.opcode)
|
||||
write!(f, "\t\t{}", self.opcode)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,6 +281,7 @@ impl fmt::Display for Mnemonic {
|
||||
Self::ADD_FromReg(mem, reg) => write!(f, "add {}, {}", mem, reg),
|
||||
Self::ADD_ToReg(mem, reg) => write!(f, "add {}, {}", reg, mem),
|
||||
Self::CMP_Iv(mem, imm) => write!(f, "cmp {}, {:04x}", mem, imm),
|
||||
Self::CMP_Ib(target, imm) => write!(f, "cmp {}, {:04x}", target, imm),
|
||||
Self::LEA(mem, reg) => write!(f, "lea {}, {}", reg, mem),
|
||||
Self::MOV_BXIv(word) => write!(f, "mov bx, {:04x}", word),
|
||||
Self::MOV_FromReg(target, reg) => write!(f, "mov {}, {}", target, reg),
|
||||
@@ -311,18 +321,20 @@ impl fmt::Display for MemoryIndex {
|
||||
match &self.base {
|
||||
Some(base) => match &self.index {
|
||||
Some(index) => match &self.displacement {
|
||||
Some(displacement) => write!(f, "[{} + {} + {}]", base, index, displacement),
|
||||
Some(displacement) => {
|
||||
write!(f, "[{}+{}+{:04x}]", base, index, displacement)
|
||||
}
|
||||
None => write!(f, "[{}+{}]", base, index),
|
||||
},
|
||||
None => match &self.displacement {
|
||||
Some(displacement) => write!(f, "[{} + {}]", base, displacement),
|
||||
None => write!(f, "[{} + 0]", base),
|
||||
Some(displacement) => write!(f, "[{}+{:04x}]", base, displacement),
|
||||
None => write!(f, "[{}]", base),
|
||||
},
|
||||
},
|
||||
None => match &self.index {
|
||||
Some(index) => match &self.displacement {
|
||||
Some(displacement) => write!(f, "{} + {}", index, displacement),
|
||||
None => write!(f, "[{} + 0]", index),
|
||||
Some(displacement) => write!(f, "[{}+{:04x}]", index, displacement),
|
||||
None => write!(f, "[{}]", index),
|
||||
},
|
||||
None => panic!("Invalid MemoryIndex encountered"),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user