Automatic disassembling

Optimizing c++ code requires that we can view the generated machine code (hex) in assembly language. With the program avr-objdump.exe in \hardware\tools\avr\bin we can disassemble the machine code. The input is the .elf file in the applet folder.
The avr-objdump.exe program has some limitations:

One has to create a separate batchfile for each project
The batchfile must be run manually
File / folder names with spaces are not supported because of DOS limitations

Here is an example batchfile that I use:

@echo off 
cls
echo Disassembler for the .elf file in \applet by avr-objdump.exe
rem Place avr-objdump.exe and this batch file in the same folder
rem Don't use filenames with spaces

avr-objdump -S ..\code\Streaming\Streaming\applet\Blablabla1234567890.elf > Blablabla1234567890_assembler.txt
pause

It would be very handy that the disassembler would run automatically after compiling.

Who has the experience to help me with this?

See this: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1207951658/2#2

I usually keep a shell window around when I'm optimizing, connected to the appropriate directory:

BillW-MacOSX-2<1415> cd ~/Documents/Arduino/loop_example/applet/
BillW-MacOSX-2<1416> /Applications/arduino/arduino-0014/hardware/tools/avr/bin/avr-objdump  -S *.elf > foo.S
BillW-MacOSX-2<1417>

You seem to already have avr-objdump in your path, so it's even easier. I just use the reverse-search-through-history feature of "bash" to find the last time I used it. You CAN install bash on windows (cygwin or similar), but the basic idea should work even with the normal windows command line shell.

I'm using windows XP and I have found the best way for me.

  1. Bring up command prompt. Mine is

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\carl>

  1. Copy avr-objdump from \hardware\tools\avr\avr\bin into
    C:\Documents and Settings\carl.

It will now be accessable from your command line.

  1. When you want to disassemble copy the required .elf file into the
    same folder as above .
    From the command line type:

C:\Documents and Settings\carl>avr-objdump -S BlinkASM.cpp.elf > disasm.txt

  1. the lising is now in the same folder.

Here is the loop function from blink after disassembly:

00000100 :
// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
100: 80 91 00 01 lds r24, 0x0100
104: 61 e0 ldi r22, 0x01 ; 1
106: 0e 94 70 01 call 0x2e0 ; 0x2e0
delay(1000); // wait for a second
10a: 68 ee ldi r22, 0xE8 ; 232
10c: 73 e0 ldi r23, 0x03 ; 3
10e: 80 e0 ldi r24, 0x00 ; 0
110: 90 e0 ldi r25, 0x00 ; 0
112: 0e 94 ec 00 call 0x1d8 ; 0x1d8
digitalWrite(ledPin, LOW); // set the LED off
116: 80 91 00 01 lds r24, 0x0100
11a: 60 e0 ldi r22, 0x00 ; 0
11c: 0e 94 70 01 call 0x2e0 ; 0x2e0
delay(1000); // wait for a second
120: 68 ee ldi r22, 0xE8 ; 232
122: 73 e0 ldi r23, 0x03 ; 3
124: 80 e0 ldi r24, 0x00 ; 0
126: 90 e0 ldi r25, 0x00 ; 0
128: 0e 94 ec 00 call 0x1d8 ; 0x1d8
}
12c: 08 95 ret

Other options available:

Usage: avr-objdump <option(s)> <file(s)>
Display information from object <file(s)>.
At least one of the following switches must be given:
-a, --archive-headers Display archive header information
-f, --file-headers Display the contents of the overall file header
-p, --private-headers Display object format specific file header contents
-h, --[section-]headers Display the contents of the section headers
-x, --all-headers Display the contents of all headers
-d, --disassemble Display assembler contents of executable sections
-D, --disassemble-all Display assembler contents of all sections
-S, --source Intermix source code with disassembly
-s, --full-contents Display the full contents of all sections requested
-g, --debugging Display debug information in object file
-e, --debugging-tags Display debug information using ctags style
-G, --stabs Display (in raw form) any STABS info in the file
-W, --dwarf Display DWARF info in the file
-t, --syms Display the contents of the symbol table(s)
-T, --dynamic-syms Display the contents of the dynamic symbol table
-r, --reloc Display the relocation entries in the file
-R, --dynamic-reloc Display the dynamic relocation entries in the file
@ Read options from
-v, --version Display this program's version number
-i, --info List object formats and architectures supported
-H, --help Display this information

@carl47
Do me a favor, please. Never use green text. On a white background, that hurts my eyes and is hard to read.

How about a nice soft pink?

That works.

Can I please resurrect this thread.
Can somebody please translate what looks like superb information, to work with Windows 7, which does not permit access to what appears to be legacy Documents and Settings/username
Thank you

Try: C:\users\username

or copy/move the files to some other directory outside of C:\users path. For example C:\temp

Two things...

  1. Microsoft moved the user documents folder to \Users. Typically the path for you will be "C:\Users{Your Login}\Documents".

  2. The Arduino folks changed the IDE so it no longer outputs the Applet subdirectory. You can find the ELF file in a subdirectory in the %TEMP% folder.

I have just moved to window 7. I am the administrator.

The command prompt is still under accessories.
It is now run from:

C:\users\carl>

So just copy as before:

  1. Copy objdump from \hardware\tools\avr\avr\bin into
    C:\users\carl.

It will now be accessible from your command line.

Coding Badly.

I've just started using 21 and I did not realise until your reply that the applet had disappeared.

You can find the tempory folder by doing a search with %TEMP%

Mine is at:

C:\Users\carl\AppData\Local\Temp

There are many folders in this windows tempory file location.

I compiled a arduino sketch but I can find no sign of a arduino tempory folder.

There were a whole bunch of folders like:

untitled329976128171923035.tmp

which contained blank .pde files.

Help!

Thank you all for your excellent redirection, hopefully I will have success.

I found out how to find the applet(which has the .elf file) with help from:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1287332515

Compile or upload the sketch and do not close the sketch. Then look in:

C:\Users\carl\AppData\Local\Temp

you will find a folder like:

build6586865351983244490.tmp or

build4306609694168305606.tmp

The "build" is always common to the applet file.

The folder is deleted when you close the sketch.

So now you just:

  1. When you want to disassemble copy the required .elf file into the
    same folder as above .
    From the command line type:

C:\Users\carl>objdump -S BlinkASM.cpp.elf > disasm.txt

  1. the lising is now in the same folder.

Thank you carl47, this will take me a while to sort out but I am sure that all this info will help me achieve my goal.