To see the assembly code that Rust compiles down to, do the following:
First, install the cargo-show-asm crate (NOT the outdated cargo-asm crate)
cargo install cargo-show-asmThen, do:
cargo asm \
-p emu86rs \
--profile=release-with-debug \
--color \
--rust \
--att \
--lib \
--simplify \
--everything \
> everything.lst-p emu86rsselects the emulator package--profile=release-with-debuguses the release-with-debug profile, which will hopefully correlate with the build profile we will use for the debugger.--coloradds ANSI color codes, which makes the output look nice.--rustinterleaves Rust code in the assembly, so it's easy to see what corresponds to what.--attoutputs assembly in the AT&T syntax instead of Intel syntax.--libselects all code that falls under the lib module.--simplifyremoves various non-assembly directives that just clutter things.--everythingwill generate assembly for the entire program.
Other options:
--intel(the default) outputs assembly in the Intel syntax instead of AT&T syntax. However, this will make it not match up with the debugger disassembly output, so it may be easier to stick not specify this when trying to match it up with the debugger.
You can also change --lib for --bin to see the executable startup code. See
cargo asm --help for more options.
To view the listing file with colors in VSCode, be sure to install the
ANSI Colors extension and then do ANSI TEXT: Open Preview.
Alternatively, do less -R main.lst in a terminal to see the colorized listing
file.
There are basically two flavors of x86 assembly: AT&T/Linux, and Intel. For a quick refresher on the syntax, see x86 assembly language - Syntax.
Other x86-64 assembly tips:
- TODO
llvm-mca is a performance analysis tool that can be used to statically guess the performance of machine code for a specific CPU. It guesses Instructions Per Cycle (IPC) as well as hardware resource pressure.
To use it, first install the llvm Debian package:
sudo apt install llvmThis will install many llvm-based tools, including llvm-mca.
Next, run it like so:
cargo asm --mca-intel --lib decode 9 > decode.mca.txt