Pages: [1]   Go Down
Author Topic: Automatic disassembling  (Read 4083 times)
0 Members and 1 Guest are viewing this topic.
Maastricht Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
@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?
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6373
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I usually keep a shell window around when I'm optimizing, connected to the appropriate directory:
Code:
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.
Logged

Australia
Offline Offline
Full Member
***
Karma: 7
Posts: 209
AVR Microcontrollers
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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>


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

     It will now be accessable from your command line.

3. 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

4. the lising is now in the same folder.

Here is the loop function from blink after disassembly:

00000100 <loop>:
// 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 <digitalWrite>
  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 <delay>
  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 <digitalWrite>
  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 <delay>
}
 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
  @<file>                  Read options from <file>
  -v, --version            Display this program's version number
  -i, --info               List object formats and architectures supported
  -H, --help               Display this information

« Last Edit: May 21, 2010, 02:44:31 pm by carl47 » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46090
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Australia
Offline Offline
Full Member
***
Karma: 7
Posts: 209
AVR Microcontrollers
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How about a nice soft pink?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46090
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That works.
Logged

UK
Offline Offline
Full Member
***
Karma: 0
Posts: 100
Please cut all loops in plastic tin can retainers.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try: C:\users\username

or copy/move the files to some other directory outside of C:\users path. For example C:\temp
« Last Edit: October 18, 2010, 02:49:58 pm by mirzas » Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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.
Logged

Australia
Offline Offline
Full Member
***
Karma: 7
Posts: 209
AVR Microcontrollers
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

2. 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!

« Last Edit: October 19, 2010, 12:25:32 am by carl47 » Logged

UK
Offline Offline
Full Member
***
Karma: 0
Posts: 100
Please cut all loops in plastic tin can retainers.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Australia
Offline Offline
Full Member
***
Karma: 7
Posts: 209
AVR Microcontrollers
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

3. 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

4. the lising is now in the same folder.
« Last Edit: October 19, 2010, 01:22:29 am by carl47 » Logged

UK
Offline Offline
Full Member
***
Karma: 0
Posts: 100
Please cut all loops in plastic tin can retainers.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: