13.07.2015 Views

TASKING VX-toolset for ARM User Guide

TASKING VX-toolset for ARM User Guide

TASKING VX-toolset for ARM User Guide

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>TASKING</strong> <strong>VX</strong>-<strong>toolset</strong> <strong>for</strong> <strong>ARM</strong> <strong>User</strong> <strong>Guide</strong>Remove the exclusive lock created by __LDREXB, __LDREXH, or __LDREXW.1.10.4.1. Writing Your Own Intrinsic FunctionBecause you can use any assembly instruction with the __asm() keyword, you can use the __asm()keyword to create your own intrinsic functions. The essence of an intrinsic function is that it is inlined.1. First write a function with assembly in the body using the keyword __asm(). See Section 1.5, UsingAssembly in the C Source: __asm()2. Next make sure that the function is inlined rather than being called.You can do this with the functionqualifier inline.This qualifier is discussed in more detail in Section 1.10.2, Inlining Functions: inline.inline int __my_pow( int base, int power ){int result;__asm( "mov %0,%1\n""1:\n\t""subs %2,%2,#1\n\t""mulne %0,%0,%1\n\t""bne 1p\n\t", %2": "=&r"(result): "r"(base), "r"(power) );}return result;void main(void){int result;}// call to function __my_powresult = __my_pow(3,2);Generated assembly code:main: .type func; __my_pow code is inlined heremov r0,#2mov r1,#31:movr2,r1subs r0,r0,#1mulne r2,r2,r1bne 1pAs you can see, the generated assembly code <strong>for</strong> the function __my_pow is inlined rather than called.Numeric labels are used <strong>for</strong> the loop.34

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

Saved successfully!

Ooh no, something went wrong!