views:

1155

answers:

3

I would like to be able to see an assembly language listing of my Arduino sketches. How can I achieve this?

Update: I am running the Arduino Software on a Windows machine.

+3  A: 

If you are using Linux, you can follow this tutorial on how to compile for the Arduino without the IDE.

Once you do that, you can get an assembly listing by running gcc with the -s flag.

Magnus Hoff
@Magnus I'm running on Windows, but the link may still be of use - I'll take a look. Thanks.
Matthew Murdoch
+2  A: 

The following (hacky) steps will provide assembly language listings of Arduino sketches and associated libraries on Windows:

  1. Download (and rename) the Arduino Windows command line batch files into the directory containing your sketch (the .pde file)
  2. Set up the required environment variables as specified in the above linked page
  3. Add -S to the abuild_gcc_opts variable in abuild.bat (line 158)
  4. Run abuild -r -c <pde_filename>
  5. Expect to get the following warnings and errors, which you can ignore:

    ... warning: #warning "This file has been moved to <util/delay.h>."

    .\obj\<pde_filename>.cpp.o: file format not recognized: treating as linker script

    .\obj\<pde_filename>.cpp.o:1: syntax error

The assembly language listings can be found in the .o files in the created obj directory. For example the listing for the sketch itself is in obj\<pde_filename>.cpp.o

Matthew Murdoch
+3  A: 

One way to do this is to use avr-objdump on the .elf file created by the build. For example, on OS X I can do this:

$ cd ~/arduino-0015/examples/Digital/Blink/applet
$ avr-objdump -d Blink.elf

(Your path on Windows may be different, obviously.) This produces a disassembly of the code, part of which will look something like this:

0000013a <main>:
 13a:   0e 94 3e 01     call    0x27c <init>
 13e:   0e 94 97 00     call    0x12e <setup>
 142:   0e 94 80 00     call    0x100 <loop>
 146:   fd cf           rjmp    .-6             ; 0x142 <main+0x8>
Greg Hewgill