When I call a C function containing an infinite loop from main() it pushes some registers on the stack before executing that function. And since the function contains an infinite loop, those registers never gets popped.
Here's an example,
void My_Func (void)
{
int flag_1 = 1;
while(1)
{
if(counter > 5 && flag_1)
{
flag_1 = 0;
}
else if(counter > 550 && flag_1)
{
flag_1 = 0;
}
}
}
int main(void)
{
My_Func();
return 0;
}
Here counter is a global variable.
When I call My_Func() it pushes R4, R5, R6 before executing the function. The disassembly looks like this,
0x080004BC B470 PUSH {r4-r6}
And then the function execution starts. But since there is an infinite loop inside the function the registers never gets popped.
Is there any way to stop KEIL IDE from pushing registers before executing function, without modifying the function definition?
counteris something like a C11atomic_uint, I hope? Otherwise the compiler is free to read it once outside the loop. - Peter Cordes