How to get the assembly language equivalent code

Hi,

I have been programming the ATMEGA 328 on using the arduino duemilanove over the past couple of months. I know the basics of it and have been even able to make a stand alone arduino 328 circuitry.
When we program using arduino board, we load the code into the chip using the USB port. The code is in C language like instructions which is a high level language. Now, I was wondering if there is any way for me to get the assembly level code of the program that is loaded into my chip.
For example, the LED blinking program that is commonly used, if I load that into my arduino and it runs .. now how do I get the assembly level code?
Typically assembly language will have instructions like MOV A,B or ADD A, #35 etc.. A and B are say some registers in my processor.
Does any one need how to do this?
I will need the assembly language code to put it in my project report hence I am looking for ways to get it.. please guide..

Thank You..

• Locate the ELF file in your TEMP directory

• Use avr-objdump to convert it to an assembly listing...
avr-objdump.exe -S *.elf > Junk1.cpp

• Finally, open the converted file (Junk1.cpp) in your favourite text editor

For what it's worth, this is the Python script (ds.py) I use to do all the steps...

import fnmatch
import os
import subprocess
import string

pathok = False
pathlist = string.split( os.environ['PATH'], sep=os.pathsep )
for path in pathlist:
  testme = os.path.join(path,'avr-objdump.exe')
  if os.path.exists(testme):
    pathok = True
    break

if not( pathok ):
  pathlist.append( 'C:\\Arduino\\arduino-1.0\\hardware\\tools\\avr\\utils\\bin' )
  pathlist.append( 'C:\\Arduino\\arduino-1.0\\hardware\\tools\\avr\\bin' )
  pathlist.append( 'C:\\arduino\\arduino-1.0\\hardware\\tools\\avr\\etc' )
  pathnew = string.join( pathlist, sep=os.pathsep )
  os.environ['PATH'] = pathnew

tempdir = os.environ.get('TEMP')
tempfile = os.path.join(tempdir,'Junk.cpp')

matches = []
for root, dirnames, filenames in os.walk(tempdir):
  for filename in fnmatch.filter(filenames, '*.elf'):
    matches.append(os.path.join(root, filename))

if len(matches) > 0:
  f = open(tempfile, 'w')
  subprocess.call(['avr-objdump.exe','-S',matches[0]],stdout=f)
  f.close()

os.system( 'start ' + tempfile )

It's slow to start when executing "ds.py" directly so I run it from a command script (ds.cmd)...

@Echo Off
python C:\PathTo\ds.py

Just to clarify, you don't get a .cpp file (except in the name).

You will get something like (inside):

void loop ()
{
   fubar = foo + bar;
  be:	20 91 00 01 	lds	r18, 0x0100
  c2:	30 91 01 01 	lds	r19, 0x0101
  c6:	40 91 02 01 	lds	r20, 0x0102
  ca:	50 91 03 01 	lds	r21, 0x0103
  ce:	80 91 04 01 	lds	r24, 0x0104
  d2:	90 91 05 01 	lds	r25, 0x0105
  d6:	a0 91 06 01 	lds	r26, 0x0106
  da:	b0 91 07 01 	lds	r27, 0x0107
  de:	82 0f       	add	r24, r18
  e0:	93 1f       	adc	r25, r19
  e2:	a4 1f       	adc	r26, r20
  e4:	b5 1f       	adc	r27, r21
  e6:	80 93 1a 01 	sts	0x011A, r24
  ea:	90 93 1b 01 	sts	0x011B, r25
  ee:	a0 93 1c 01 	sts	0x011C, r26
  f2:	b0 93 1d 01 	sts	0x011D, r27
}
  f6:	08 95       	ret

Just to clarify, you don't get a .cpp file (except in the name).

Sorry about that. I give it a .cpp extension so it will load in Visual Studio.

I usually give a .txt extension, and then double-click that to open in the current text editor.