What code does the compiler produce?


Before you can optimize parts of your code you have to know what instructions the C-compiler produced. To do this you have to find the *.elf file that will produced temporarily (ELF: Executable and Linkable Format). When you successfully have done a "Sketch-Verify/Compile" or "File-Upload" you have to find this file which is stored in a directory with a random filename somewhere hidden in a subdirectory user\AppData\Local\Temp\. As it is a binary file you have to make it readable with a program shipped with the Arduino IDE:

avr-objdump -S myprogram.cpp.elf > listfile.txt

(The programm avr-objdump.exe can be found in the directory Arduino\hardware\tools\avr\bin\.)
With some versions of the Arduino IDE the temporary *.elf file will be deleted after you have saved the source program.

You also can read back the compiled file from the flash memory of the microcontroller (provided the fuses have not been set to disable this option). The command

avrdude -F -V -c arduino -p ATMEGA328P -P COM5 -b 9600 -U flash:r:flash_backup.hex:i

gives you a backup of what is in the flash memory. Of course, you have to provide the correct parameters instead of "-P com5" (port number) and "-b 9600" (baud rate).

The file flash_backup.hex can be made readable with the program ReAvr . But it's no fun to read what it produces.


contact: nji(at)gmx.de