mixed C and assembler output

Go To Last Post
21 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am in the midst of writing some code and would like to convince AVR GCC to output files with mixed C and assembler so I can see how the compiler is handling my C code. I tried a -S but that did not produce anything useful. Anyone know the correct incantation? I am using AVR studio and WINAVR.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Short answer: you can't

Long answer: Add a -save-temps to your CFLAGS and for every file.c you will get a file.i and file.s, the .i is the file after pre-processing and the file.s is the generated assembler. However this does not interleave source lines so can be very "dry" to read. It can be helped a little with "-fverbose-asm" which adds more variable name annotation but it still doesn't have the source.

What you can do though is to let the compiler generate the final .o files (or even the composite .elf) and then run ar-objdump -S on those. If you do it on the .o's then external references will not be fixed up and will show 00 00, if you do it on the .elf you'll get a complete diassembly of the entire program. Most Makefiles already do the latter and call the output
.lss

As you use Studio just start with -save-temps and -fverbose-asm for [All Files] under "custom options". Also make sure all the "generate" tick boxes on the opening config dialog are ticked (so you get .lss and .map)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Great! Thanks!

I am acutally glad it was not simple. :) I would have been unhappy if I missed it. Though I SHOULD have thought of the .lss file.

Thanks again, the .lss works for what I wanted.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jaydhall wrote:
Anyone know the correct incantation?

Your question is 3 years old but a simple method may still be interesting for someone else.

It is possible to obtain a disassembly output with C++ (or C) correspondances by invoking Debug->Windows->Disassembly ( ALT+8 ) in Atmel Studio. This only works during a debugging session.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But that's just about the worst disassembly there is. save-temps is far better.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Make sure you compile with debug -g option. When you create the list file eg. avr-objdump -h -S proj.elf  1>proj.lst

 

it should have the C source with asm mixed in. eg

 

void GPIO::SetOutput( LogicLevel level)
{
 75e:    fc 01           movw    r30, r24
    if( level == currentlevel )
 760:    82 81           ldd    r24, Z+2    ; 0x02
 762:    93 81           ldd    r25, Z+3    ; 0x03
 764:    68 17           cp    r22, r24
 766:    79 07           cpc    r23, r25
 768:    69 f0           breq    .+26         ; 0x784 <_ZN3AVR4GPIO9SetOutputEN7Devices4GPIO10LogicLevelE+0x26>
    {
        return;
    }

    //In newer AVRs a set to PIN register will perform a toggle.
    PIN = (1<<pinNumber);
 76a:    a2 85           ldd    r26, Z+10    ; 0x0a
 76c:    b3 85           ldd    r27, Z+11    ; 0x0b
 76e:    81 e0           ldi    r24, 0x01    ; 1
 770:    90 e0           ldi    r25, 0x00    ; 0
 772:    04 84           ldd    r0, Z+12    ; 0x0c
 774:    02 c0           rjmp    .+4          ; 0x77a <_ZN3AVR4GPIO9SetOutputEN7Devices4GPIO10LogicLevelE+0x1c>
 776:    88 0f           add    r24, r24
 778:    99 1f           adc    r25, r25
 77a:    0a 94           dec    r0
 77c:    e2 f7           brpl    .-8          ; 0x776 <_ZN3AVR4GPIO9SetOutputEN7Devices4GPIO10LogicLevelE+0x18>
 77e:    8c 93           st    X, r24
    currentlevel = level;
 780:    73 83           std    Z+3, r23    ; 0x03
 782:    62 83           std    Z+2, r22    ; 0x02
 784:    08 95           ret

00000786 <_ZN3AVR4GPIO9ReadInputEv>:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

John 2 years too late. wink

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

not really the -g is kind of new :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And the imagecraft compiler gives a beautiful readable assembler out interspersed in between the c statements.

 

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobgardner wrote:
And the imagecraft compiler gives a beautiful readable assembler out interspersed in between the c statements.

Does it still have the ASM operands in reverse order from all other AVR8 assemblers?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

Does it still have the ASM operands in reverse order from all other AVR8 assemblers?

 

Where did you get that statement from? Most/all instructions use the orders as specified in the original AVR manual. You may be thinking of GCC, which uses (used to anyway, may be they change by now) GCC order, independent of the target assembler.

Richard Man http://imagecraft.com

Beyond Arduino - When you're ready to get serious...
JumpStart C Tools, The Better Alternative.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry but why does that matter? I get a bit sick of your petty posts taking a pop at GCC. I thought the most important thing about a C compiler was the quality of the code it produces. Do you want to discuss that?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Sorry but why does that matter? I get a bit sick of your petty posts taking a pop at GCC. I thought the most important thing about a C compiler was the quality of the code it produces. Do you want to discuss that?

 

? WHat are you talking about? Someone made a claim that our compiler has certain misfeatures, at which I replied, we don't work that way, but GCC does. That's not a dig at GCC. That's answering a post with facts.

Richard Man http://imagecraft.com

Beyond Arduino - When you're ready to get serious...
JumpStart C Tools, The Better Alternative.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is from the x86 GAS wiki:

 

I do not know about the GAS AVR, but my comment is based on my experience, "back in the days". In no way it's an "attack" on GCC, which you seem to think I am doing.

Richard Man http://imagecraft.com

Beyond Arduino - When you're ready to get serious...
JumpStart C Tools, The Better Alternative.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tough crowd. A guys asks for an assembly listing, a suggestion is made to use the imagecraft compiler because it gives a nice assembler listing, and all of a sudden the gcc crowd wants imagecraft to change the way it outputs the assembly listing that gcc doesn't produce? OK Cliff... lets have the report on operand order in listing files for gcc, imagecraft, codevision and IAR. Maybe microc because lots of Indian profs use that compiler. Rowley is just gcc in a different wrapper right? Does it produce an avr8 listing file?

 

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Cliff you remind me about the war about using 8080 or z80 mnemonics for CP/M.

 

But in general it's up to the writer of the back-end to decide the order, because he "invent" the assembler.

So for both gcc and LCC (imagecraft), the back-end writer use the "normal" AVR order.  

 

add

And I have never understood why the AVR has ST and LD instructions, (the order decide) , but I guess that's just to say it has  130+ instructions 

Last Edited: Tue. Jun 14, 2016 - 08:39 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

not really the -g is kind of new :)

Huh?  Are you thinking of -Og?  -g has been around >>at least<< since 2.95.3 (2001/03/16), the earliest version for which there are docs here.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I use OMG.......

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

the -g is kind of new

 The (apparent) NEED for -g for mixed source/assembly disassembly is apparently relatively new.  I'm pretty sure older avr-gcc could produce such a listing without needing -g in the compile step.  Now, apparently not...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Err no. -g is as old as the hills and has always been a requirement for having DWARF-2, COFF, STABS embedded in the ELF so it can later be used to annotate the Asm code.

 

When sparrow said "-g is kind of new" in #8 commenting on the necromancy in #6 I think he meant that it was new to this thread and had not been mentioned so far. The following tangent has been discussed on a misinterpretation of that.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Note to Cliff... its been 13 days since you derailed the thread asking about asm listing by warping it into operand ordering in listing outputs, so I challenged you in msg 15 to report on operand listing order in avr c compilers and see if there is a clear concensus on how it should be done. It seems msg 10 was the 'attack' that made you sick and all snippy in msg 12. After that crickets. Is listing order more important than the listing itself?

Imagecraft compiler user