Re: [arm-gnu] Why is R3 pushed/popped on function entry/exit (Cortex-M3)?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [arm-gnu] Why is R3 pushed/popped on function entry/exit (Cortex-M3)?
- To: Andrew Sterian <steriana@xxxxxxxxx>
- Subject: Re: [arm-gnu] Why is R3 pushed/popped on function entry/exit (Cortex-M3)?
- From: Travis Geiselbrecht <Travis.Geiselbrecht@xxxxxxxx>
- Date: Wed, 19 May 2010 12:47:39 -0700
That's probably to maintain 8 byte alignment on the stack, another requirement of EABI. Sometimes the compiler will push extra registers to keep an even amount on the stack.
On May 19, 2010, at 12:43 PM, Andrew Sterian wrote:
> Can someone help me understand why R3 takes part in the PUSH/POP
> instructions for this:
>
> --------------<test.c>-----------------
> extern int func(int i);
>
> int test(int i)
> {
> return func(i)+5;
> }
> --------------<test.c>-----------------
>
> Compiled with (2010q1 release G++ Lite):
>
> arm-none-eabi-gcc -Wall -march=armv7-m -mcpu=cortex-m3 -mthumb
> -mfix-cortex-m3-ldrd -Os -S test.c
>
> Result:
> --------------<test.s>-----------------
> push {r3, lr}
> bl func
> adds r0, r0, #5
> pop {r3, pc}
> --------------<test.s>-----------------
>
> My understanding from the ARM Procedure Call Standard is that only R4
> upwards need to be saved in a function call. Why wouldn't it be enough
> to just PUSH/POP the LR?
>
> Thanks,
>
> --
> Andrew Sterian