diff --git a/src/parser/instruction/encoding/primary_operand.rs b/src/parser/instruction/encoding/primary_operand.rs index 84784a5..28ada4a 100644 --- a/src/parser/instruction/encoding/primary_operand.rs +++ b/src/parser/instruction/encoding/primary_operand.rs @@ -126,20 +126,21 @@ impl From for PrimaryOperand { } impl Display for PrimaryOperand { + // Turn the operand back into a form which parses into the same type fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::Direct(r) => write!(f, "{r}"), + Self::Direct(r) => Display::fmt(r, f), Self::Indirect(r) => write!(f, "@{r}"), Self::PostInc(r) => write!(f, "@{r}+"), Self::Indexed(r, idx) => write!(f, "{idx}({r})"), Self::Absolute(n) => write!(f, "&{n}"), Self::Immediate(n) => write!(f, "#{n}"), - Self::Four => write!(f, "#4"), - Self::Eight => write!(f, "#8"), - Self::Zero => write!(f, "#0"), - Self::One => write!(f, "#1"), - Self::Two => write!(f, "#2"), - Self::MinusOne => write!(f, "#-1"), + Self::Four => Display::fmt("#4", f), + Self::Eight => Display::fmt("#8", f), + Self::Zero => Display::fmt("#0", f), + Self::One => Display::fmt("#1", f), + Self::Two => Display::fmt("#2", f), + Self::MinusOne => Display::fmt("#-1", f), } } } diff --git a/src/parser/instruction/encoding/secondary_operand.rs b/src/parser/instruction/encoding/secondary_operand.rs index f94574a..b393983 100644 --- a/src/parser/instruction/encoding/secondary_operand.rs +++ b/src/parser/instruction/encoding/secondary_operand.rs @@ -85,11 +85,11 @@ impl Parsable for SecondaryOperand { impl Display for SecondaryOperand { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::Direct(r) => write!(f, "{r}"), + Self::Direct(r) => Display::fmt(r, f), Self::Indexed(r, idx) => write!(f, "{idx}({r})"), Self::Absolute(n) => write!(f, "&{n}"), - Self::Zero => write!(f, "#0"), - Self::One => write!(f, "#1"), + Self::Zero => Display::fmt("#0", f), + Self::One => Display::fmt("#1", f), } } }