Msg/ClobberedSP: Difference between revisions
From CPUlator Wiki
< Msg
< Msg
Line 14: | Line 14: | ||
MyFunction: | MyFunction: | ||
push {r4} // | push {r4} // Change SP | ||
bx lr // | bx lr // SP is different at return | ||
</syntaxhighlight> | |||
==== Nios II ==== | |||
<syntaxhighlight lang="Asm" line highlight="9"> | |||
.global _start | |||
_start: | |||
movi sp, 0x1000 # Initialize SP | |||
call Function | |||
nop | |||
nop | |||
Function: | |||
subi sp, sp, 4 # Modify SP | |||
ret # SP is different at return | |||
</syntaxhighlight> | </syntaxhighlight> | ||
{{DisableMsg|Function clobbered ra or sp}} | {{DisableMsg|Function clobbered ra or sp}} |
Revision as of 23:25, 9 March 2019
A function should always ensure that the stack pointer is the same at the entry and exit of the function. This message tells you that this didn't happen: the stack pointer was different at the function return than when the function was first called.
Examples
ARMv7
.global _start
_start:
mov sp, #0x1000 // Initialize SP to something sane
bl MyFunction
nop
nop
# ...
MyFunction:
push {r4} // Change SP
bx lr // SP is different at return
Nios II
.global _start
_start:
movi sp, 0x1000 # Initialize SP
call Function
nop
nop
Function:
subi sp, sp, 4 # Modify SP
ret # SP is different at return
Disabling this message
This debugging check can be disabled in the Debugging Checks section of the Settings box: Function clobbered ra or sp.