This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Ti codegen - variables in the inline assemby

Hi,

 i am using TI code gen compiler. I want to use c variable in inline assembly code. for example,

 

unsigned int IntStat(void)
{
    unsigned int stat;

       asm("    mrs     r0, CPSR\n\t"
                 "    and     stat], r0, #0xC0");
    return stat;
}

 

here i want to use 'stat' in assembly. How can i do that?. Can you give me the exact syntax to do this

  • Hi,

    We don't recommend modifying C variables in inline assembly code at all, since this will cause unpredictable results if optimization is used (check section 6.5.4 of SPNU151).

    Instead, you should write your function entirely in assembly and call it from C (check section 6.5 of the same book for details) - although a bit more complex, it guarantees the integrity of your code under any circumstance.

    Regards,

    Rafael

     

  • Hi

    I tried to do the same, but I failed on TI C compiler.
    It cannot refer to any local variable from assembler (like GCC does).
    With TI compiler you can refer only to global variables.

    In your example you can relay on convention used by the compiler - register that is always used for returning the result.
    For details, please refer to The C Compiler Reference.

    What architecture do you use?

    Regards,
    Piotr Romaniuk, Ph.D.
    ELESOFTROM

  • Also check the section titled CPSR Register and Interrupt Intrinsics in the ARM compiler book.  One of those intrinsics probably does what you need.

    Thanks and regards,

    -George