6.3. 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;
        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:

For more information see also:

Copyright © 2002-2007 ARM Limited. All rights reserved.ARM DUI 0205H