Go Down

Topic: How can one view the assembly code output from the Arduino IDE? (Read 15068 times) previous topic - next topic


Well, the subject line tells it all, but I will add that I have searched the forum and cannot find a way to view the assembly code output from the Arduino IDE.  In fact, I cannot find any output files from running Arduino.  It looks as though there are no "tracks" left behind from uploading a sketch to a board.


Why do you want it? It is completely unreadable and in HEX.

for this blinking file:
Code: [Select]
    Copyright Spark Fun Electronics© 2007
    Nathan Seidle
    nathan at sparkfun.com

Example Blink
Toggles all IO pins at 1Hz

#include <avr/io.h>

//Define functions
void ioinit(void);      //Initializes IO
void delay_ms(uint16_t x); //General purpose delay

int main (void)
    ioinit(); //Setup IO pins and defaults


PORTC = 0x00;
PORTB = 0x00;
PORTD = 0x00;

void ioinit (void)
    //1 = output, 0 = input
    DDRB = 0b11111111; //All outputs
    DDRC = 0b11111111; //All outputs
    DDRD = 0b11111110; //PORTD (RX on PD0)

//General short delays
void delay_ms(uint16_t x)
  uint8_t y, z;
  for ( ; x > 0 ; x--){
    for ( y = 0 ; y < 90 ; y++){
      for ( z = 0 ; z < 6 ; z++){
        asm volatile ("nop");

You get
Code: [Select]

Check this out though:

It looks like it can compile C/C++ into HEX.


I don't consider the hex output to be assembly code --- however, I have seen reference to a utility that can produce assembly code from hex, although I expect that a great deal of readability would be lost.

As to why? --- I just like to peek under the skirts to see how things are done.  And sometimes for performance reasons I might feel a need to depart momentarily from the Arduino library calls and it can be useful to see how the C code (that works) does things; this can be used as a guide to in-line assembly coding.

Thanks for the response.


The art of getting good answers lies in asking good questions.


Bob Anderson

I agree with the points you make.  When writing for a controller, I am always pleased to have an easy and quick to program system create the user and communication interfaces and then revert to assembly for the interrupt routines that actually do time sensitive controlling.  If you had access to the assembly code that Arduino system emits, you could see when and what resources it is using and stay clear of interference, or change the Arduino program to avoid problems.

John Carroll

Interesting how the spell checker hates Arduino


Hold SHIFT down whilst pressing the verify or upload button to see what the IDE is doing behind the scenes. You will see that it uses a temporary directory, where you will find source and binary files.

You can either use objdump -d or -D to disassemble the object files, or copy the gcc command and add -S to get it to output assembler files.
Due VGA library - http://arduino.cc/forum/index.php/topic,150517.0.html



Is there a way to tell Arduino IDE to use the -S option?

It looks rather burdensome (and error prone) to copy and modify the rather long list of commands that are executed to compile a program.

Thanks for your help in this matter.  It was useful to see what Arduino is doing.



Code: [Select]
avr-objdump -S sketch.elf
will give you a mixed source/assembly listing; the elf file still has symbol info so it is pretty readable.


Avoid throwing electronics out as you or someone else might need them for parts or use.
Solid state rectifiers are the only REAL rectifiers.
Resistors for LEDS!



Where would one place the  "avr-objdump  -S" line?

I am used to imbedding things like 

      #pragma  stuffForCompiler

in the code.  Can this be done with Arduino to induce an assembly listing?  I'd really like to see an assembly listing interspersed with the C code.  I guess since the avr toolset is being used that I should investigate on the avr site as well.


You run it at a command prompt or terminal shell depending on your OS. Which OS are you using?

You can copy and paste the command from the window, if you are using the avr-gcc -S method you only need the one line which compiles your sketch (the other ones are compiling the Arduino library)

Unfortunately it is rather a chore, that's just the way it is... the IDE is designed to make the simplest things that most people do (ie edit a simple sketch and upload it) as trouble free as possible. Doing anything more complicated than that and very often you are on your own.

Two things to watch out for in the disassembly once you get it. Instructions are in the form  Instruction Destination Source, not Instruction Source Destination (think Intel style rather than AT&T). And watch out for an instruction called MOVW which the compiler emits quite often but the disassembler seems to disassemble incorrectly. So instead of saying movw r17:r16,r1:r0 it just says movw r16,r0. That had me confused for hours.
Due VGA library - http://arduino.cc/forum/index.php/topic,150517.0.html


You run it at a command prompt or terminal shell

Right.  There's no way I know of to get the IDE to produce the listing for you; you have to let the IDE produce the binaries, and then generate the listing manually from the binaries.

As Stimmer points out, you wind up with "gnu assembler" syntax, which will not match Atmel assembler syntax in a number of annoying ways.  (on the bright side, gnu assembler syntax remains more consistent across multiple architectures than the individual manufacturer's syntaxes...)


stimmer and westfw:

Thanks again for your useful comments.

I am using Snow Leopard on a MacBook Air. 

For some reason, I can find no vestiges of compiling a sketch anywhere on my harddrive.  Arduino seems to sweep up all crumbs, that makes it impossible to apply any of the disassembly tools.

I will try invoking avr-gcc -S in a Terminal window to see what I get.

Actually, this is not very important as I can find most of what I want by examining the core code.

I appreciate the Arduino IDE philosophy as outlined by stimmer, but I still wish that were a possibility to get a little deeper into things without having to change to a different environment completely.  There isn't much of a path for the developing programmer to spread his wings as he gains confidence.  On the other hand, any such options could easily become a source of confusion for the beginner.  On the whole, I feel that Arduino has it right.


I am using Snow Leopard on a MacBook Air.

For some reason, I can find no vestiges of compiling a sketch anywhere on my harddrive.  Arduino seems to sweep up all crumbs, that makes it impossible to apply any of the disassembly tools.

yes, apparently the IDE asks Java for a temporary directory, and gets something deeply buried as a result.  (I think this is something copied from "Processing", where the compiled code is less interesting the IDE originates with processing, and this behavior changed after a relatively recent upgrade that involved syncing with the Processing code.))  Holding SHIFT while clicking the verify command will show the verbose output during compile, and you can find the directory there.  Or you can modify your preferences.txt file (~/Library/Arduino/preferences.txt; a simple text file) to include a "build.path=/tmp/arduino" or similar.

Go Up