| |||
| Home > Using the Inline and Embedded Assemblers > Legacy inline assembler that accesses sp, lr, or pc | |||
The compilers in RVCT v1.2 and earlier enabled accesses to sp (r13), lr (r14),
and pc (r15) from inline assembly
code (see Inline assembler). Example 6.8 shows how legacy
inline assembly code might use lr.
Example 6.8. Legacy inline assembly code using lr
void func()
{
int var;
__asm
{
mov var, lr /* get the return address of func() */
}
}
There is no guarantee that lr contains
the return address of a function if your legacy code uses it in
inline assembly. For example, there are certain build options or optimizations
that might use lr for another purpose. The compiler
in RVCT v2.0 and above reports an error similar to the following
if lr, sp or pc is
used in this way:
If you have to access these registers from within a C or C++ source file, you can:
use embedded assembly (see Embedded assembler).
use the following intrinsics in inline assembly:
__current_pc()To access the pc register.
__current_sp()To access the sp register.
__return_address()To access the lr register.
For more information see also:
Instruction intrinsics in the Compiler Reference Guide.