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

Create successful ePaper yourself

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

<strong>TASKING</strong> <strong>VX</strong>-<strong>toolset</strong> <strong>for</strong> <strong>ARM</strong> <strong>User</strong> <strong>Guide</strong>});return retvalue;int result,parm;void func(void){result = foo(1000,1000,&parm);}In this example the "1" constraint <strong>for</strong> the input parameter par1 refers to the output parameter par1, andsimilar <strong>for</strong> the "2" constraint and par2. In the inline assembly %1 (par1) and %2 (par2) are written. Thisis allowed because the compiler is aware of this.This results in the following generated assembly code:mov r0,#1000mov r1,r0ldr r2,.L2add r1,r0,r0,lsl #2mov r2,r1mov r3,r1ldr r0,.L2+4str r3,[r0,#0]bx lr.L2:.dw parm.dw resultHowever, when the inline assembly would have been as given below, the compiler would have assumedthat %1 (par1) and %2 (par2) were read-only. Because of the inline keyword the compiler knows thatpar1 and par2 both contain 1000. There<strong>for</strong>e the compiler can optimize and assign the same register to%1 and %2. This would have given an unexpected result.__asm("add %2,%1,%1,lsl #2\n\t""mov %3,%2\n\t""mov %0,%2": "=&r" (retvalue): "r" (par1), "r" (par2), "r" (par3));Generated assembly code:ldr r0,.L2mov r1,#100010

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

Saved successfully!

Ooh no, something went wrong!