cancel
Showing results for 
Search instead for 
Did you mean: 

Operations during PUSH and POP

Kuikui
Associate III
Posted on December 19, 2010 at 23:33

Operations during PUSH and POP

5 REPLIES 5
Posted on May 17, 2011 at 14:18

PUSH and POP *instructions* can handle one or multiple registers, depending on what you define in the operand.

For stacking of interrupts, the processors pushes R0,R1,R2,R3,R12,LR, PC and PSR onto the stack. When tail chaining these are not popped back until the last interrupt completes.

As I recall the value you see in LR during the interrupt is a magic value that defines the processor state/stack from which to return.

Google ''cortex-m3 interrupt stack frame'', and review Joseph Yiu's book.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Kuikui
Associate III
Posted on May 17, 2011 at 14:18

Thanks clive1. This helped me a lot.

Nevertheless, I figured it out that what is pushed and pop in a ISR is kind of ''compiler-dependent''.

As far as I understood, there are 2 operations when entering in an interrupt function :

- hardware push ( the so-called ''interrupt stack frame'' )

- software push

Software push seems to be ''compiler-dependent'', and should be, I suppose, code-dependent.I mean, if your C code does a lot of stuff in the interrupt function, the compiler may need several registers, and then should have to push some additionnal register (compared to what is pushed by hardware ).

With my actual code, IAR generates a software push of R7 and LR when entering the interrupt function. If I change some optimization options, IAR won't push the same registers (as an example : R4, R7 and LR).

I want to totally control what is stacked or not, I don't want it to be compiler-dependent, or what so ever.

Then my question is : is there any (hopefully portable) way to force IAR (hopefully as most compilers as possible) to push the registers I want to push ?

Thanks for help ...

Best regards,

V.

Andrew Neil
Evangelist
Posted on May 17, 2011 at 14:18

''I want to totally control what is stacked or not, I don't want it to be compiler-dependent, or what so ever.''

In that case, you

must

use assembler!

The whole point of a High-Level Language (HLL) - any  HLL - is that you choose to delegate this stuff to the compiler. If you cannot accept that delegation, then you cannot use a HLL - or, at least, not for that part of the code.

''is there any (hopefully portable) way to force IAR (hopefully as most compilers as possible) to push the registers I want to push''

No.

stforum2
Associate II
Posted on May 17, 2011 at 14:18

''I want to totally control what is stacked or not''

Why do you want to do this?

Kuikui
Associate III
Posted on May 17, 2011 at 14:18

Thanks andrew, that is the answered I had in mind, but I wanted someone to confirm my thoughts.

Gonna try this, I might be back :p