Von:
address@hidden
[mailto:address@hidden Im Auftrag
von Advait Jain Gesendet: Montag, 17. Juli 2006
09:37 An: address@hidden Betreff: [avr-gcc-list]
(no subject)
Hello,
I wrote a function which copies the contents of a
global array into a local array to see how avr-gcc allocates local arrays on the
stack.
void try1(void) { char
a[20]; unsigned char i;
for(i=0;i<20;i++)
a[i] = com1_msgbuf[i]; }
the assembly for
this function is this: (from the .lss file)
void
try1(void) { 5a40: cf
93 push
r28 5a42: df
93 push
r29 5a44: cd
b7 in
r28, 0x3d ; 61 5a46:
de b7
in r29, 0x3e ; 62
5a48: 64 97
sbiw r28, 0x14 ;
20 5a4a: 0f
b6 in r0, 0x3f ;
63 5a4c: f8
94 cli 5a4e: de
bf out 0x3e, r29 ;
62 5a50: 0f
be out 0x3f, r0 ;
63 5a52: cd
bf out 0x3d, r28 ;
61 5a54: de
01 movw
r26, r28 5a56: 11
96 adiw
r26, 0x01 ; 1 5a58: ef
e7 ldi
r30, 0x7F ; 127 5a5a:
f6 e0
ldi r31, 0x06 ; 6
5a5c: 93 e1
ldi r25, 0x13 ;
19 char a[20]; unsigned char
i;
for(i=0;i<20;i++) a[i] =
com1_msgbuf[i]; 5a5e: 81
91 ld
r24, Z+ 5a60: 8d
93 st
X+, r24 5a62: 91
50 subi
r25, 0x01 ; 1 5a64: 97
ff sbrs
r25, 7 5a66: fb
cf rjmp
.-10 ; 0x5a5e
5a68: 64 96
adiw r28, 0x14 ;
20 5a6a: 0f
b6 in
r0, 0x3f ; 63 5a6c: f8
94
cli 5a6e: de
bf out
0x3e, r29 ; 62 5a70:
0f be
out 0x3f, r0 ; 63
5a72: cd bf
out 0x3d, r28 ;
61 5a74: df
91 pop
r29 5a76: cf
91 pop
r28 5a78: 08
95 ret
What I
want to know is why did the compiler save SREG in r0, disable all the
interrupts, restored only the upper byte of the stack pointer, restore SREG and
then copy the lower byte of the stack pointer. (5a4a to
5a52).
-- Advait Jain
4th Year undergraduate Computer
Science and Engg. Indian Institute of Technology,
Delhi