chore: align disasm output with intel spec
This commit is contained in:
@@ -325,6 +325,27 @@ impl fmt::LowerHex for Displacement {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Displacement {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::IByte(b) => {
|
||||
if *b > 0 {
|
||||
write!(f, " + {}", b)
|
||||
} else {
|
||||
write!(f, " - {:#x}", b * -1)
|
||||
}
|
||||
}
|
||||
Self::IWord(w) => {
|
||||
if *w > 0 {
|
||||
write!(f, " + {}", w)
|
||||
} else {
|
||||
write!(f, " - {:#x}", w * -1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A memory index operand is usually created by ModRM bytes or words.
|
||||
/// e.g. [bx+si]
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -340,22 +361,22 @@ impl fmt::Display for MemoryIndex {
|
||||
Some(base) => match &self.index {
|
||||
Some(index) => match &self.displacement {
|
||||
Some(displacement) => {
|
||||
write!(f, "[{}+{}+{:04x}]", base, index, displacement)
|
||||
write!(f, "[{} + {}{}]", base, index, displacement)
|
||||
}
|
||||
None => write!(f, "[{}+{}]", base, index),
|
||||
None => write!(f, "[{} + {}]", base, index),
|
||||
},
|
||||
None => match &self.displacement {
|
||||
Some(displacement) => write!(f, "[{}+{:04x}]", base, displacement),
|
||||
Some(displacement) => write!(f, "[{}{}]", base, displacement),
|
||||
None => write!(f, "[{}]", base),
|
||||
},
|
||||
},
|
||||
None => match &self.index {
|
||||
Some(index) => match &self.displacement {
|
||||
Some(displacement) => write!(f, "[{}+{:04x}]", index, displacement),
|
||||
Some(displacement) => write!(f, "[{}{}]", index, displacement),
|
||||
None => write!(f, "[{}]", index),
|
||||
},
|
||||
None => match &self.displacement {
|
||||
Some(displacement) => write!(f, "[{:04x}]", displacement),
|
||||
Some(displacement) => write!(f, "[{:#x}]", displacement),
|
||||
None => panic!("Memory Index without base, index and displacement"),
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user