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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

7.30 Inline assembler and virtual registers<br />

Inline assembly code <strong>for</strong> <strong>the</strong> compiler always specifies virtual registers. The compiler chooses<br />

<strong>the</strong> physical registers to be used <strong>for</strong> each instruction during code generation, and enables <strong>the</strong><br />

compiler to fully optimize <strong>the</strong> assembly code and surrounding C or C++ code.<br />

The pc (r15), lr (r14), and sp (r13) registers cannot be accessed at all. An error message is<br />

generated when <strong>the</strong>se registers are accessed.<br />

The initial values of virtual registers are undefined. There<strong>for</strong>e, you must write to virtual registers<br />

be<strong>for</strong>e reading <strong>the</strong>m. The compiler warns you if code reads a virtual register be<strong>for</strong>e writing to<br />

it. The compiler also generates <strong>the</strong>se warnings <strong>for</strong> legacy code that relies on particular values in<br />

physical registers at <strong>the</strong> beginning of inline assembly code, <strong>for</strong> example:<br />

int add(int i, int j)<br />

{<br />

int res;<br />

__asm<br />

{<br />

ADD res, r0, r1<br />

}<br />

return res;<br />

}<br />

// relies on i passed in r0 and j passed in r1<br />

This code generates warning and error messages.<br />

The errors are generated because virtual registers r0 and r1 are read be<strong>for</strong>e writing to <strong>the</strong>m. The<br />

warnings are generated because r0 and r1 must be defined as C or C++ variables. The corrected<br />

code is:<br />

int add(int i, int j)<br />

{<br />

int res;<br />

__asm<br />

{<br />

ADD res, i, j<br />

}<br />

return res;<br />

}<br />

7.30.1 See also<br />

Concepts<br />

• Inline assembler and register access in C and C++ code on page 7-18.<br />

O<strong>the</strong>r in<strong>for</strong>mation<br />

Migration and Compatibility:<br />

• Chapter 2 Migrating from RVCT v4.0 <strong>for</strong> µVision to <strong>ARM</strong> <strong>Compiler</strong> <strong>v4.1</strong> <strong>for</strong> µVision.<br />

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

ID061811<br />

Non-Confidential

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

Saved successfully!

Ooh no, something went wrong!