29.10.2014 Views

ARM Compiler toolchain v4.1 for µVision Using the Compiler

ARM Compiler toolchain v4.1 for µVision Using the Compiler

ARM Compiler toolchain v4.1 for µVision Using the Compiler

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Using</strong> <strong>the</strong> Inline and Embedded Assemblers of <strong>the</strong> <strong>ARM</strong> <strong>Compiler</strong><br />

7.49 Legacy inline assembler that accesses sp, lr, or pc<br />

The compilers in <strong>ARM</strong> Developer Suite (ADS) v1.2 and earlier enabled accesses to sp (r13), lr<br />

(r14), and pc (r15) from inline assembly code. Example 7-8 shows how legacy inline assembly<br />

code might use lr.<br />

Example 7-8 Legacy inline assembly code using lr<br />

void func()<br />

{<br />

int var;<br />

__asm<br />

{<br />

mov var, lr /* get <strong>the</strong> return address of func() */<br />

}<br />

}<br />

There is no guarantee that lr contains <strong>the</strong> return address of a function if your legacy code uses<br />

it in inline assembly. For example, <strong>the</strong>re are certain build options or optimizations that might<br />

use lr <strong>for</strong> ano<strong>the</strong>r purpose. The compiler in RVCT v2.0 and later reports an error similar to <strong>the</strong><br />

following if lr, sp or pc is used in this way:<br />

If you have to access <strong>the</strong>se registers from within a C or C++ source file, you can:<br />

• use embedded assembly<br />

• use <strong>the</strong> following intrinsics in inline assembly:<br />

__current_pc() To access <strong>the</strong> pc register.<br />

__current_sp()<br />

To access <strong>the</strong> sp register.<br />

__return_address() To access <strong>the</strong> lr register.<br />

7.49.1 See also<br />

Tasks<br />

• Accessing sp (r13), lr (r14), and pc (r15) in legacy code on page 7-57.<br />

Concepts<br />

• <strong>Compiler</strong> support <strong>for</strong> inline assembly language on page 7-4<br />

• <strong>Compiler</strong> support <strong>for</strong> embedded assembler on page 7-36.<br />

Reference<br />

• Instruction intrinsics on page 5-61.<br />

<strong>ARM</strong> DUI 0375C Copyright © 2007-2008, 2011 <strong>ARM</strong>. All rights reserved. 7-56<br />

ID061811<br />

Non-Confidential

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!