In many cases it is very useful to see the generated assembly code produced by the compiler. One obvious way to see the assembly code is to use the Disassembly view in Eclipse:
But this requires a debug session. An easier way is to use command line options to generate the listing file(s).
-a: Generating an assembly listing file for each file compiled/assembled
One way is to add the following to the gcc compiler command line, for which I usually use the following:
-Wa,-adhlns="$@.lst"
The -Wa is an option for the assembler (which is staged after the compiler). The options passed to the assembler follow right after with the comma (,). For a description of the assembler -a option see https://sourceware.org/binutils/docs/as/a.html#a
In MCUXpresso IDE 10.2 I add it to the ‘Miscellaneous’ compiler options:
With this, for every source file compiled it will place the listing file into the same output folder as the object file:
Then I can open it with a text editor:
which opens a text view in Eclipse:
Objdump: Generating an assembly listing from the object file
Another way is to generate the listing file from the compiler output object file. For this I can use the GNU objdump utility
arm-none-eabi-objdump -d test.o >test.o.lst
Which writes the disassembly listing to a file:
MCUXpresso IDE: Binary Utilities
With the MCUXpresso IDE 10.2 (Eclipse Oxygen based) NXP has added an extension with the ‘Binary Utilities’ menu which I can use on an object (or ELF/Dwarf) file:
This again calls the objdump utility and creates the listing file:
In summary, there are many ways to create the assembly listing file :-).
Happy Disassembling 🙂
Links
- GNU assembler (as) options: https://sourceware.org/binutils/docs/as/Invoking.html#Invoking
- GNU objdump options: https://sourceware.org/binutils/docs/binutils/objdump.html
- MCUXpresso IDE download: http://www.nxp.com/mcuxpresso/ide
Pingback: Execute-Only-Code with GNU and gcc | MCU on Eclipse
Pingback: Disassembling in MPLABX & MCUXpresso | James Andrew Smith