Pages: [1]   Go Down
Author Topic: Get Compiler to Output Assembly  (Read 2701 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
God Member
*****
Karma: 0
Posts: 594
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How can I tell the compiler to output a assembly file?
Logged

Freelance engineer, consultant, contractor. Graduated from UW in 2013.

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

What I do to look at assembler is use "objdump" on the elf file.  Just connect to the temporary directory that arduino uses for builds (/tmp/build* on my mac) and do something like:
Code:
MacOSX<1105> cd /tmp/build25808.tmp/
MacOSX<1106> /Downloads/arduino-0008/tools/avr/bin/avr-objdump -S hptime.elf

In theory, there's a -S switch for the compiler as well, but I worry about getting all the right switches and preprocessing done (automatically provided by audino environment), and using the .elf avoids this, and objdump produces a pretty nice mixed source/assembly listing:
Code:
       Serial.print("millis = ");
 12a:   60 e0           ldi     r22, 0x00       ; 0
 12c:   71 e0           ldi     r23, 0x01       ; 1
 12e:   86 e2           ldi     r24, 0x26       ; 38
 130:   91 e0           ldi     r25, 0x01       ; 1
 132:   0e 94 ec 00     call    0x1d8 <_ZN14HardwareSerial5printEPKc>
        Serial.print(mstime);
 136:   b8 01           movw    r22, r16
 138:   a7 01           movw    r20, r14
 13a:   86 e2           ldi     r24, 0x26       ; 38
 13c:   91 e0           ldi     r25, 0x01       ; 1
 13e:   0e 94 2a 01     call    0x254 <_ZN14HardwareSerial5printEm>
        Serial.print(",  high precision time = ");
 142:   6a e0           ldi     r22, 0x0A       ; 10
 144:   71 e0           ldi     r23, 0x01       ; 1
 146:   86 e2           ldi     r24, 0x26       ; 38
 148:   91 e0           ldi     r25, 0x01       ; 1
 14a:   0e 94 ec 00     call    0x1d8 <_ZN14HardwareSerial5printEPKc>
        Serial.print(hptime);
 14e:   dc 2c           mov     r13, r12
 150:   cb 2c           mov     r12, r11
 152:   ba 2c           mov     r11, r10
 154:   aa 24           eor     r10, r10
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

can someone please .. repost the steps to have the compiler or the sketch invoriment   output the writen C code in assembly .. which the atmel chips understand ..

in an  ( idiot proff way please for the arudino 0017 enviorment

am running windows vista
Logged

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

I am running the Arduino 18 software on Mac OS X, and I don't see any way to get the object code.  I even tried editing Library/Arduino/preferences.txt to change
preproc.save_build_files=false
to
preproc.save_build_files=true

That did not produce any new files that I could see when I compiled.  Even if it did, the Arduino 18 download does not contain any of the utilities described for looking at the output.  Do I have to get the Arduino source code and build the whole thing from scratch to get the utility files?

Normally C would be fine for me, but I was doing some timing of interrupt routines, and found that accessing a memory location was taking 15 cycles, while the hardware datasheet indicates that it should be taking 2 cycles.  I want to know what code the compiler is generating (I'll replace it with asm code if it is too ridiculous).
Logged

0
Offline Offline
Edison Member
*
Karma: 0
Posts: 1103
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Press the SHIFT key when Compiling your code. You then will see in the message window where the system hides it. In Windows, its something like:

documents..\user\local settings...\temp\another temp

Also handy for getting the hex files.

« Last Edit: August 17, 2010, 03:19:37 am by mpeuser » Logged

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

Thanks.  The tools were hidden in
/Applications/Arduino-18/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/
and the intermediate files in
/var/folders/8F/8FJE0ZtWEZCIWPVFJ8P-rU+++TI/-Tmp-/build5863418055745895668.tmp/

The tools I should have been able to find, despite being hidden from the Finder (I had not dived deep enough into the Arduino.app directory), but the temporary directory was a complete mystery.

Now I can finally find out why the code is taking almost twice as long as I think it should for memory accesses!
Logged

Pages: [1]   Go Up
Jump to: