Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align assembly? #370

Open
pozix604 opened this issue Feb 8, 2025 · 2 comments
Open

Align assembly? #370

pozix604 opened this issue Feb 8, 2025 · 2 comments

Comments

@pozix604
Copy link

pozix604 commented Feb 8, 2025

A lot of assembly listings align instruction operands to aid in reading. For example:

        and r8d, -86
        imul r8, rax
        or r8, r9
        and r8, rcx
        movzx r9d, byte ptr [rdi + rsi + 6]
        mov r10d, r9d
        and r10d, 85
        imul r10, rax

to

        and      r8d, -86
        imul     r8, rax
        or       r8, r9
        and      r8, rcx
        movzx    r9d, byte ptr [rdi + rsi + 6]
        mov      r10d, r9d
        and      r10d, 85
        imul     r10, rax

I'd like to suggest a feature enhancement to align operands via an option, e.g. --align.

@pacak
Copy link
Owner

pacak commented Feb 8, 2025

I thought about it. This only works for instructions that are one word long, but there are instructions that go with prefixes:

lock inc word [edi + r10d*4] 

or

rep stosb

Those should be aligned to the second space if present at all...

@pozix604
Copy link
Author

pozix604 commented Feb 8, 2025

I've made the following change for myself. Works okay for me.

$ git diff
diff --git a/src/asm/statements.rs b/src/asm/statements.rs
index 0635431..7e3fa0f 100644
--- a/src/asm/statements.rs
+++ b/src/asm/statements.rs
@@ -104,7 +104,7 @@ impl std::fmt::Display for Instruction<'_> {
         if self.op.starts_with("#DEBUG_VALUE:") {
             write!(f, "{}", color!(self.op, OwoColorize::blue))?;
         } else {
-            write!(f, "{}", color!(self.op, OwoColorize::bright_blue))?;
+            write!(f, "{:8}", color!(self.op, OwoColorize::bright_blue))?;
         }
         if let Some(args) = self.args {
             let args = demangle::contents(args, display);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants