Table of Contents Previous topic Next topic
C/C++ COMPILER->Compiler command line options->Stack Frame Pointer Elimination (/Ok)
The /Ok option tells the compiler to try to avoid using a frame pointer.
R11 is use as the frame pointer. It is used to access function parameters and local variables not stored in registers. In many cases the compiler is instead able to use the stack pointer R13 to access these function parameters and local variables.
If R11 is not used then is does not need to be saved on function entry, it does not need to be initialized and it does not have to be restored on function exit.
Consider the code generated for the C library abs() function.
With the default optimizations, the following code is generated:
STMFD R13!,{R11}
MOV R11,R13
LDR R0,[R11,#4]
CMP R0,#0
BGE .@1
RSB R0,R0,#0
.@1
MOV R13,R11
LDMFD R13!,{R11}
MOV R15,R14
With stack frame pointer elimination enabled, the following code is generated:
LDR R0,[R13,#0]
CMP R0,#0
BGE .@1
RSB R0,R0,#0
.@1
MOV R15,R14