avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Stack use - possible bug


From: Dale
Subject: Re: [avr-gcc-list] Stack use - possible bug
Date: Wed, 9 Jun 2010 15:16:36 +0200
User-agent: Mutt/1.5.20 (2009-06-14)

Hi                                  >@2010.06.09_14:42:49_+0200

Here's some code which shows this.

#include <stdio.h>
#include <stdlib.h>
#include <avr/io.h>


static void initialise(void)
{
        char    buf[50];
        uint8_t i;
        // nonsense code that's not optimised away
        for (i=0; i<50; i++) UDR0 = buf[i];
}

int main(void) 
{
        initialise();

        // run tasks
        while (1) {
                // nonsense code that's not optimised away
                do { __asm__ __volatile__ ("nop"); } while (0);
        }
}

Built using:

avr-gcc -Os -DF_CPU=14745600UL -mmcu=atmega2561 -c main.c  -o main.o
avr-gcc -mmcu=atmega2561 -DF_CPU-14745600UL main.o 
-Wl,-Map=out.map,--cref,--debug-stubs -o main.elf
avr-objdump -h -S main.elf > main.lss

Assembly output as follows:

00000112 <main>:
 112:   df 93           push    r29
 114:   cf 93           push    r28
 116:   cd b7           in      r28, 0x3d       ; 61
 118:   de b7           in      r29, 0x3e       ; 62
 11a:   e2 97           sbiw    r28, 0x32       ; 50
 11c:   0f b6           in      r0, 0x3f        ; 63
 11e:   f8 94           cli
 120:   de bf           out     0x3e, r29       ; 62
 122:   0f be           out     0x3f, r0        ; 63
 124:   cd bf           out     0x3d, r28       ; 61
 126:   fe 01           movw    r30, r28
 128:   31 96           adiw    r30, 0x01       ; 1
 12a:   9e 01           movw    r18, r28
 12c:   2d 5c           subi    r18, 0xCD       ; 205
 12e:   3f 4f           sbci    r19, 0xFF       ; 255
 130:   81 91           ld      r24, Z+
 132:   80 93 c6 00     sts     0x00C6, r24
 136:   e2 17           cp      r30, r18
 138:   f3 07           cpc     r31, r19
 13a:   d1 f7           brne    .-12            ; 0x130 <main+0x1e>
 13c:   00 00           nop
 13e:   fe cf           rjmp    .-4             ; 0x13c <main+0x2a>


Space taken on stack: stack pointer on mega2561 are 0x3d and 0x3e.

--

Cheers,

Dale.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]