[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] something I don't understand with stack manipulation
From: |
Bernard Fouché |
Subject: |
[avr-gcc-list] something I don't understand with stack manipulation |
Date: |
Wed, 24 Nov 2004 13:35:57 +0100 |
Hi there.
I'm (still!) looking at the asm code produced by avr-gcc 3.4.2 with -Os.
When the compiler needs to give stack space to a local variable (for
instance a 10 bytes space), it produces:
1d6e: cd b7 in r28, 0x3d ; 61
1d70: de b7 in r29, 0x3e ; 62
1d72: 2a 97 sbiw r28, 0x0a ; 10
1d74: 0f b6 in r0, 0x3f ; 63
1d76: f8 94 cli
1d78: de bf out 0x3e, r29 ; 62
1d7a: 0f be out 0x3f, r0 ; 63
1d7c: cd bf out 0x3d, r28 ; 61
What I don't get is that 0x3d/0x3e is the stack pointer, obviously the
routine protects itself against interrupts while writing the new stack
pointer value but 0x3d is updated after that SREG has been written back and
so potentialy an interrupt can come between the last two lines.
I would better understand with:
1d78: cd bf out 0x3d, r28 ; 61
1d7a: de bf out 0x3e, r29 ; 62
1d7c: 0f be out 0x3f, r0 ; 63
What did I miss?
(BTW for people chasing the last possible free bytes for code this means
that if you have some RAM to spare, using global space instead of local
space, for say a 10 bytes string, will save you 16 bytes of code for stack
reservation + 10 bytes of code for stack freeing + space for push/popping
the registers needed in the stack calculation: 34 bytes!)
Bernard
- [avr-gcc-list] something I don't understand with stack manipulation,
Bernard Fouché <=