chore: align disasm print more with objdump(1)

This commit is contained in:
2025-05-20 11:28:23 +09:00
parent beccff0d79
commit 48eeff16fa
2 changed files with 30 additions and 30 deletions

View File

@@ -56,7 +56,7 @@ 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}:\t", self.start).unwrap();
write!( write!(
f, f,
@@ -65,11 +65,11 @@ impl fmt::Display for Instruction {
.iter() .iter()
.map(|b| format!("{:02x}", b)) .map(|b| format!("{:02x}", b))
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join("") .join(" ")
) )
.unwrap(); .unwrap();
write!(f, "\t\t{}", self.opcode) write!(f, "\t{}", self.opcode)
} }
} }
@@ -529,14 +529,14 @@ impl fmt::Display for Mnemonic {
Self::SAR_fromReg(target, reg) => write!(f, "sar {target}, {reg}"), Self::SAR_fromReg(target, reg) => write!(f, "sar {target}, {reg}"),
Self::IN_AL(byte) => write!(f, "in {}, {byte:#04x}", Register::AL), Self::IN_AL(byte) => write!(f, "in {}, {byte:#04x}", Register::AL),
Self::IN_AX(byte) => write!(f, "in :#04x{}, {byte:#04x}", Register::AX), Self::IN_AX(byte) => write!(f, "in {}, {byte:#04x}", Register::AX),
Self::IN_ALDX => write!(f, "in {}, :#04x{}", Register::AL, Register::DX), Self::IN_ALDX => write!(f, "in {}, {}", Register::AL, Register::DX),
Self::IN_AXDX => write!(f, "in {}, :#04x{}", Register::AX, Register::DX), Self::IN_AXDX => write!(f, "in {}, {}", Register::AX, Register::DX),
Self::OUT_AL(byte) => write!(f, "out :#04x{}, {byte:#04x}", Register::AL), Self::OUT_AL(byte) => write!(f, "out {}, {byte:#04x}", Register::AL),
Self::OUT_AX(byte) => write!(f, "out :#04x{}, {byte:#04x}", Register::AX), Self::OUT_AX(byte) => write!(f, "out {}, {byte:#04x}", Register::AX),
Self::OUT_ALDX => write!(f, "out {}, :#04x{}", Register::AL, Register::DX), Self::OUT_ALDX => write!(f, "out {}, {}", Register::AL, Register::DX),
Self::OUT_AXDX => write!(f, "out {}, :#04x{}", Register::AX, Register::DX), Self::OUT_AXDX => write!(f, "out {}, {}", Register::AX, Register::DX),
Self::INT(byte) => write!(f, "int {byte:#04x}"), Self::INT(byte) => write!(f, "int {byte:#04x}"),
Self::INTO => write!(f, "into"), Self::INTO => write!(f, "into"),

View File

@@ -66,22 +66,22 @@ impl Register {
impl fmt::Display for Register { impl fmt::Display for Register {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self { match self {
Self::AX => write!(f, "ax"), Self::AX => write!(f, "%ax"),
Self::BX => write!(f, "bx"), Self::BX => write!(f, "%bx"),
Self::CX => write!(f, "cx"), Self::CX => write!(f, "%cx"),
Self::DX => write!(f, "dx"), Self::DX => write!(f, "%dx"),
Self::AH => write!(f, "ah"), Self::AH => write!(f, "%ah"),
Self::AL => write!(f, "al"), Self::AL => write!(f, "%al"),
Self::BL => write!(f, "bl"), Self::BL => write!(f, "%bl"),
Self::BH => write!(f, "bh"), Self::BH => write!(f, "%bh"),
Self::CH => write!(f, "ch"), Self::CH => write!(f, "%ch"),
Self::CL => write!(f, "cl"), Self::CL => write!(f, "%cl"),
Self::DH => write!(f, "dh"), Self::DH => write!(f, "%dh"),
Self::DL => write!(f, "dl"), Self::DL => write!(f, "%dl"),
Self::DI => write!(f, "di"), Self::DI => write!(f, "%di"),
Self::SI => write!(f, "si"), Self::SI => write!(f, "%si"),
Self::BP => write!(f, "bp"), Self::BP => write!(f, "%bp"),
Self::SP => write!(f, "sp"), Self::SP => write!(f, "%sp"),
} }
} }
} }
@@ -113,10 +113,10 @@ impl SegmentRegister {
impl fmt::Display for SegmentRegister { impl fmt::Display for SegmentRegister {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self { match self {
Self::DS => write!(f, "ds"), Self::DS => write!(f, "%ds"),
Self::ES => write!(f, "es"), Self::ES => write!(f, "%es"),
Self::SS => write!(f, "ss"), Self::SS => write!(f, "%ss"),
Self::CS => write!(f, "cs"), Self::CS => write!(f, "%cs"),
} }
} }
} }