Legacy inline assembler that accesses sp, lr, or pc

The compilers in ARM Developer Suite (ADS) v1.2 and earlier enabled accesses to sp (r13), lr (r14), and pc (r15) from inline assembly code. Example 48 shows how legacy inline assembly code might use lr.

Example 48. 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 later 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:

Show/hideSee also

Copyright © 2010-2011 ARM. All rights reserved.ARM DUI 0472F
Non-ConfidentialID091611