ARM GCC assembly output

A forum for ARM assembly programmers (32 & 64 bit)
Post Reply
rhyde
Site Admin
Posts: 47
Joined: Sun Dec 04, 2022 5:36 pm

ARM GCC assembly output

Post by rhyde »

I am currently working on Volume 2 of "The Art of ARM Assembly" (if you're wondering, Volume 1 is already written and is in the middle of the editing process). Volume 2 covers 32-bit ARM/Thumb assembly language programming on 32-bit PiOS (Raspberry Pi) systems and various embedded SBCs including the Raspberry Pi Pico, Arduino Zero (and MKR Zero), Teensy 3.x, and Teensy 4.x.

Quite often I need to view the assembly language source code emitted by GCC in order to provide some examples in the book. For Pi and Pico code, it's easy enough to modify the GCC command line and add an "-S" command-line option to tell GCC to stop processing after producing a Gas assembly language output file (from the compilation). With Arduino-based development (Arduino and Teensy SBCs) this is a lot more difficult because the Arduino IDE automates the compilation process and doesn't readily give you access to the command line. There is, however, a way to brute force your way through this.

To produce the assembly language output of a C compilation, hold down the Alt key when clicking on the "syntax check" option in the IDE. This displays all the commands the Arduino emits in the output window in the Arduino IDE. At one point in the (massive amount of) output, you'll see a line that says "Compiling sketch..." The next line is the command the IDE uses to run GCC to compile the code. For example, when compiling a "due.ino" sketch (for the Arduino Cortex-M3-based Due, I get the following:

Code: Select all

/Users/rhyde/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=10607 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino Due\"" -I/Users/rhyde/Library/Arduino15/packages/arduino/hardware/sam/1.6.12/system/libsam -I/Users/rhyde/Library/Arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/CMSIS/Include/ -I/Users/rhyde/Library/Arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/Device/ATMEL/ -I/Users/rhyde/Library/Arduino15/packages/arduino/hardware/sam/1.6.12/cores/arduino -I/Users/rhyde/Library/Arduino15/packages/arduino/hardware/sam/1.6.12/variants/arduino_due_x /private/var/folders/13/fqsfj5688xl6n0006s6cl2vh0000gr/T/arduino/sketches/CB081C3733319369A9E70242F8A10B79/sketch/due.ino.cpp -o /private/var/folders/13/fqsfj5688xl6n0006s6cl2vh0000gr/T/arduino/sketches/CB081C3733319369A9E70242F8A10B79/sketch/due.ino.cpp.o
Most of this is superfluous if you simply want to generate an assembly language output source file. I trimmed this down to the following:

Code: Select all

/Users/rhyde/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++ -S -g -w -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions
 -MMD -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=10607 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino Due\"" -I/Users/rhyde/Library/Arduino15/packages/arduino/hardware/sam/1.6.12/system/libsam -I/Users/rhyde/Library/Arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/CMSIS/Include/ -I/Users/rhyde/Library/Arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/Device/ATMEL/ -I/Users/rhyde/Library/Arduino15/packages/arduino/hardware/sam/1.6.12/cores/arduino -I/Users/rhyde/Library/Arduino15/packages/arduino/hardware/sam/1.6.12/variants/arduino_due_x /private/var/folders/13/fqsfj5688xl6n0006s6cl2vh0000gr/T/arduino/sketches/CB081C3733319369A9E70242F8A10B79/sketch/due.ino.cpp
I executed this in a terminal window (on my Mac, command-line prompt for other OSes). This left the due.ino.s file sitting in my current working directory. I was able to inspect this file and check out the assembly code it produced.


Cheers,
Randy Hyde
Post Reply