I have noticed that sometimes when I compile C code the assembly code is sometimes generated in method 1:
STR R11, [SP, #-4]!
ADD R11, SP, #0
SUB SP, SP, #4
and sometimes in method 2:
STMFD SP!, {R11, LR}
ADD R11, SP, #4
SUB SP, SP, #4
the difference between the first and the second methods is that the second method saves LR into the stack.
Right now I am facing a problem where my function, that starts like the first method, calls another function using the link register (BL), and since my function does not save the LR in the first place it causes a serious problem. If I could tell the compiler to use the second method It could solve my problem.
It may be connected to the fact that the function calls the inner function using inline assembly, and thus "not recognizes" that there is a call to another function and sees no point in saving the LR. Calling the inline assembly is obligated because the called function gets the value of SP as a parameter.
This is quite a catch-22 situation, hopefully someone could help me solve that. Thanks!