WinAVR vs. IAR generated code difference

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

Hi,

I compiled the simple test program:

unsigned long main( void )
{
  unsigned long i;
  unsigned char j;

  i = (unsigned long) 32767;

  for (j=0; j<10 ; j++) {
    i += (unsigned long) i;
  }

  return i;
}

using both the IAR "kickstart" embedded workbench and also the WinAVR (avr-gcc) tools. When I load the resultant code into AVR studio for the IAR code I get a disassembly showing:

@00000002: main
---- c:\documents and settings\clawson\my documents\iar embedded workbench\main.c -----------------
7:          i = (unsigned long) 32767;
+00000002:   EF0F        SER     R16              Set Register
+00000003:   E71F        LDI     R17,0x7F         Load immediate
+00000004:   E020        LDI     R18,0x00         Load immediate
+00000005:   E030        LDI     R19,0x00         Load immediate
9:          for (j=0; j<10 ; j++) {
+00000006:   E040        LDI     R20,0x00         Load immediate
9:          for (j=0; j<10 ; j++) {
+00000007:   304A        CPI     R20,0x0A         Compare with immediate
+00000008:   F430        BRCC    PC+0x07          Branch if carry cleared
10:           i += (unsigned long) i;
+00000009:   0F00        LSL     R16              Logical Shift Left
+0000000A:   1F11        ROL     R17              Rotate Left Through Carry
+0000000B:   1F22        ROL     R18              Rotate Left Through Carry
+0000000C:   1F33        ROL     R19              Rotate Left Through Carry
9:          for (j=0; j<10 ; j++) {
+0000000D:   9543        INC     R20              Increment
+0000000E:   CFF8        RJMP    PC-0x0007        Relative jump
13:         return i;
+0000000F:   9508        RET                      Subroutine return

whereas when I load the .elf output of WinAVR the disassembly shows:

@00000051: main
---- c:\winavr\pn\source\test.c -------------------------------------------------------------------
2:        {
+00000051:   EFCF        SER     R28              Set Register
---- No Source ------------------------------------------------------------------------------------
+00000052:   E0D4        LDI     R29,0x04         Load immediate
+00000053:   BFDE        OUT     0x3E,R29         Out to I/O location
+00000054:   BFCD        OUT     0x3D,R28         Out to I/O location
---- c:\winavr\pn\source\test.c -------------------------------------------------------------------
6:          i = (unsigned long) 32767;
+00000055:   EF8F        SER     R24              Set Register
---- No Source ------------------------------------------------------------------------------------
+00000056:   E79F        LDI     R25,0x7F         Load immediate
+00000057:   E0A0        LDI     R26,0x00         Load immediate
+00000058:   E0B0        LDI     R27,0x00         Load immediate
+00000059:   E029        LDI     R18,0x09         Load immediate
---- c:\winavr\pn\source\test.c -------------------------------------------------------------------
9:            i += (unsigned long) i;
+0000005A:   0F88        LSL     R24              Logical Shift Left
---- No Source ------------------------------------------------------------------------------------
+0000005B:   1F99        ROL     R25              Rotate Left Through Carry
+0000005C:   1FAA        ROL     R26              Rotate Left Through Carry
+0000005D:   1FBB        ROL     R27              Rotate Left Through Carry
---- c:\winavr\pn\source\test.c -------------------------------------------------------------------
8:          for (j=0; j<10 ; j++) {
+0000005E:   5021        SUBI    R18,0x01         Subtract immediate
---- No Source ------------------------------------------------------------------------------------
+0000005F:   FF27        SBRS    R18,7            Skip if bit in register set
+00000060:   CFF9        RJMP    PC-0x0006        Relative jump
+00000061:   940C0063    JMP     0x00000063       Jump
+00000063:   CFFF        RJMP    PC-0x0000        Relative jump

In both I can see source and assembler interleaved but the WinAVR generated one has loads of "---- No Source ---..." lines intermingled even though the source clearly IS there.

Does anyone know what I've done wrong to cause this?

It's not a big problem and I can live with it (I like FREE software!) but it makes the mixed source/diassembly more difficult to read than it needs to be.

Cliff

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

You might have to contact Atmel about this. But you might also be comparing apples and oranges here: IIRC, AVR Studio will load in the UBROF file format from IAR, whereas you are loading the ELF file (with DWARF2 debug information) from GCC. These are completely different formats. The ELF/DWARF2 parser in AVR Studio is still very new and I know that it is not completely bug-free yet.

HTH
Eric

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
2:        {
+00000051:   EFCF        SER     R28              Set Register
---- No Source ------------------------------------------------------------------------------------
+00000052:   E0D4        LDI     R29,0x04         Load immediate
+00000053:   BFDE        OUT     0x3E,R29         Out to I/O location
+00000054:   BFCD        OUT     0x3D,R28         Out to I/O location

This is stack initializaion

---- No Source ------------------------------------------------------------------------------------
+0000005F:   FF27        SBRS    R18,7            Skip if bit in register set
+00000060:   CFF9        RJMP    PC-0x0006        Relative jump
+00000061:   940C0063    JMP     0x00000063       Jump
+00000063:   CFFF        RJMP    PC-0x0000        Relative jump

This is exiting from main

Last Edited: Mon. Jul 18, 2005 - 04:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Eric,

Is there some way to make avr-gcc (/WinAVR) generate UBPROF then? I noticed (in old documenation for WinAVR) mentions of using "make extcoff" to generate a different, AVR-studio compatible, output from WinAVR. I tried this but while I could load the test.cof this generated it only showed the binary (just disasm) - no sign of source level debugging.

Anyway, thanks again for the help. As my project is very small I can probably use the IAR its only limit is that it won't generate more than 4K of code. Or I may continue with the GNU stuff anyway.

Cliff

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

brberie wrote:

This is stack initializaion


This is exiting from main

Yup I know. I wasn't confused by that - merely by the existence of multiple lines saying "no source" when clearly it WAS managing to find/display the source.

Cliff

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

clawson wrote:

Is there some way to make avr-gcc (/WinAVR) generate UBROF then?

No. UBROF is proprietary to IAR.

clawson wrote:

I noticed (in old documenation for WinAVR) mentions of using "make extcoff" to generate a different, AVR-studio compatible, output from WinAVR. I tried this but while I could load the test.cof this generated it only showed the binary (just disasm) - no sign of source level debugging.

Using the Extended COFF file format is deprecated and should no longer be used.

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

I think that the "No source" lines in the beginning of the dissasembler (except stack initialization etc.) are branches in the address 0x0000 just in case a bad interrupt (interrupt that is enabled without an ISR for it) occurs in run time. In that case you have a kind of soft reset instead of unpredictable behaviour.