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.10 Inline assembler Thumb instruction set restrictions in C and C++ code<br />

The inline assembler is not available when compiling C or C++ <strong>for</strong> Thumb state, and <strong>the</strong> inline<br />

assembler does not assemble Thumb instructions. Instead, <strong>the</strong> compiler switches to <strong>ARM</strong> state<br />

automatically.<br />

Inline assembly language can be included in a source file that contains code to be compiled <strong>for</strong><br />

Thumb, by enclosing <strong>the</strong> functions containing inline assembler code between #pragma arm and<br />

#pragma thumb statements. For example:<br />

... // Thumb code<br />

#pragma arm // <strong>ARM</strong> code. Switch code generation to <strong>the</strong> <strong>ARM</strong> instruction set so<br />

// that <strong>the</strong> inline assembler is available.<br />

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

{<br />

int res;<br />

__asm<br />

{<br />

ADD res, i, j // add here<br />

}<br />

return res;<br />

}<br />

#pragma thumb<br />

// Thumb code. Switch back to <strong>the</strong> Thumb instruction set.<br />

// The inline assembler is no longer available.<br />

The code must also be compiled using <strong>the</strong> --apcs /interwork compiler command-line option.<br />

7.10.1 See also<br />

Concepts<br />

• Restrictions on inline assembly operations in C and C++ code on page 7-11.<br />

Reference<br />

<strong>Compiler</strong> Reference:<br />

• --apcs=qualifer...qualifier on page 3-7<br />

• Pragmas on page 5-47.<br />

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

ID061811<br />

Non-Confidential

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

Saved successfully!

Ooh no, something went wrong!