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.

C Language__asm( "nop\n""\tnop" );Example 2: using output parametersAssign the result of inline assembly to a variable. With the constraint r a general purpose register ischosen <strong>for</strong> the parameter; the compiler decides which register it uses. The %0 in the instruction templateis replaced with the name of this register. The compiler generates code to assign the result to the outputvariable.int out;void main( void ){__asm( "mov %0,#0xff": "=r" (out) );}Generated assembly code:.L2:mov r0,#0xffldr r1,.L2str r0,[r1,#0]bx lr.size main,$-main.align 4.dwoutExample 3: using input parametersAssign a variable to a register. A register is chosen <strong>for</strong> the parameter because of the constraint r; thecompiler decides which register is best to use. The %0 in the instruction template is replaced with thename of this register.The compiler generates code to move the input variable to the input register. Becausethere are no output parameters, the output parameter list is empty. Only the colon has to be present.int in;void initreg( void ){__asm( "MOV R0,%0":: "r" (in) );}Generated assembly code:ldr r0,.L2ldr r0,[r0,#0]MOV R0,r0bx lr.size initreg,$-initreg.align 47

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

Saved successfully!

Ooh no, something went wrong!