You copied the Doc URL to your clipboard.

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.

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 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:

  • use embedded assembly

  • use the following intrinsics in inline assembly:


    To access the pc register.


    To access the sp register.


    To access the lr register.