Push instruction at the start of main

I am trying to write a C code with just inline functions so that there would be no access to stack. But I see the compiler is inserting a push instruction at the start of the main. Also, this behaviour is not seen every time. With a slight change in the code sometimes I don't see the push instruction. I would like to know the what is the reason behind this

Target CPU: Cortex M23

Compiler: GCC

Code structure:

#include "interface.h"

int main(void)

{

unsigned int operation;

operation = <SFR read>;
status = check_status(operation);
if(status)
{
return(status);
}

Disassembly:

int main(void)
{
c00069c: b510 push {r4, lr}

<rest of the inline functions>

}

Header file: interface.h

inline unsigned int check_status(unsigned int oper) __attribute__((always_inline));

inline unsigned int check_status(unsigned int oper)

{

 <function body>

}

Parents
  • If the rest of the disassembly you didn't show actually uses lr for calling another function, or uses r4, then it's no surprise that they're being pushed. If not, then it might be that optimization is turned off, and that it would be a little more efficient if it was on.

Reply
  • If the rest of the disassembly you didn't show actually uses lr for calling another function, or uses r4, then it's no surprise that they're being pushed. If not, then it might be that optimization is turned off, and that it would be a little more efficient if it was on.

Children
No data
More questions in this forum