cargo-show-asm icon indicating copy to clipboard operation
cargo-show-asm copied to clipboard

Feature Request: Option to show "hand-written style" assembly output

Open alloc33 opened this issue 6 months ago • 1 comments

Currently cargo asm shows optimized assembly with compiler-generated symbols and linker optimizations, which can be hard to understand when learning.

Example:

#[no_mangle]
pub fn multiply_tuple(x: i32, y: i32, z: i32, t: i32) -> (i32, i32, i32, i32) {
    (x * 2, y * 3, z * 4, t * 5)
}

Current ARM64 output:

_multiply_tuple:
    ldr q0, [x0]
    adrp x9, lCPI8_0@PAGE
    ldr q1, [x9, lCPI8_0@PAGEOFF]  // What are the actual values?
    mul.4s v0, v0, v1
    str q0, [x8]
    ret

Would love to see something like:

_multiply_tuple:
    ldr q0, [x0]
    ldr q1, =constants     // or show actual values: [2, 3, 4, 5]
    mul.4s v0, v0, v1
    str q0, [x8]
    ret

constants: .word 2, 3, 4, 5

Question: Is there a flag or could we add one that:

  • Expands constant pool references to show actual values
  • Uses simpler, more readable symbols
  • Shows assembly closer to what you'd write by hand

This would be incredibly helpful for learning how Rust maps to assembly instructions.

Tried: --include-constants, --simplify, --reduce-labels but still get cryptic linker symbols.

Note: --dev mode does show readable code but adds extensive overflow checking that obscures the core algorithm, making it impractical for learning the actual instruction mapping.

alloc33 avatar Aug 10 '25 17:08 alloc33

It would be nice to have but, but off the top of my head I don't know how to go directly from [x9, lCPI8_0@PAGEOFF] to whatever constant values are there, that works for all the CPUs.

Need to think about it.

pacak avatar Aug 10 '25 17:08 pacak