want to see assembly output from C++ compiler

Hello everyone! I am new to Arduino development, and I am very excited. I want to say this is a wonderful introduction for me to the world of microcontrollers. Based on this web site, I was able successfully to build my own Arduino board, program bootloader using my home-made parallel cable, then start writing my own software. Now I have a board that receives Morse Code commands and replies with Morse Code. (I'm willing to share my code if anyone is interested, by the way.)

Now, however, I'm wondering if I can save some space by re-writing some of the stuff using assembly language directly instead of C++. I thought a good place to start would be to get the C++ compiler to emit assembly code so I could see which functions could be better coded in assembly by hand. I did a "g++ --help" and found out that there is a compiler option "-save-temps" which is described as "Do not delete intermediate files". I'm hoping one of those intermediate files is the assembly language output from the compiler (just a guess... maybe wishful thinking).

Can anyone tell me how to tweak the compiler options that is used by the Arduino IDE?

Thanks in advance,

  • Don

Actually, it looks like I was able to partially answer my own question. Instead of modifying the compiler options to produce an assembly listing, I discovered that I can use objdump.exe (included in the Arduino distribution) to disassemble the object file that the compiler generated. I'm using Windows, so I went into a command prompt, and added c:\arduino-0006 to my PATH:

PATH=c:\arduino-0006;%path%

Then I went into the Applet directory beneath my project and ran objdump:

c:\arduino-0006\tools\avr\avr\bin\objdump.exe -x -d -S morse_buddy.cpp.o >morse_buddy.asm

This created my assembly listing, interspersed with the original C++ code. This should give me a clue how to write my own embedded assembly code inside my C++ code.

I would still be interested in knowing how to tweak the compiler options, though, in case anybody knows... thanks!

  • Don

Right now, there's no way (short of editing its source code) to get the Arduino environment to pass arbitrary parameters to the C++ compiler. You can only set a few options (e.g. CPU speed and microcontroller). If there's enough demand for it, this is something that could be added to later versions of Arduino.

It might not need to be an option... maybe just always emit assembly code annotated with the original C++ that produced it, as yet another file in the applet subdirectory beneath the project. I doubt that would bother anybody... at worst, it would be ignored by some people.

At any rate, I am finding the use of objdump.exe very handy in figuring out how to make my code smaller. It's also very useful for me to start learning how the Atmega8 processor works.