The subroutine(C source code) is the same, but when compiled:
The DEMO's disassembly:
PUSH {r4-r7} ... ... ... POP {r4-r7} BX lr
My project's disassembly:
PUSH {r4, lr} ... ... ... POP {r4, pc}
The situation is I clean all the RAM during the subroutine to 0. So after "POP {r4, pc}", the program is crashed. I don't konw assembly language very well. So what could I do to make the ARMCC generate disassembly code using "BX lr" to make my code work? I'm using STM32F103/MDK5/ARMCC5.06.
It's possible to create a RAM-test that is non-destructive by saving the RAM contents before testing to write. And then restore the original content.
If the RAM is broken, then the above will fail. But that's irrelevant since with broken RAM you just have to settle for setting an error LED and then busy-loop or similar until power is cut.
But as Pier notes, it's when your function contains further function calls that the compiler needs that additional push since a fixed register can only store a single copy of the LR value.