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.

Return value from Assembler to C

Genius 5820 points


Hi,

as far as I understood TI compiler does not support inline assember code like this:

static inline unsigned int get_cyclecount (void)
{
   unsigned int value;
   // Read CCNT Register
   asm volatile ("MRC p15, 0, %0, c9, c13, 0\t\n": "=r"(value));  
   return value;
}

So I have to put it into a separate file that is processed separately. But: how do I implement the above? How do I write the value read from CCNT register into some variable and return it to the calling C-function?

Thanks :-)

  • In .asm file:

         .global get_cyclecount
    get_cyclecount:  .asmfunc
          MRC p15, 0, R0, c9, c13, 0
          BX LR
          .endasmfunc

    Then in a C or H file delcare it as:

    unsigned int get_cyclecount (void);

    Then call it like any other C function.  By ARM EABI convention it looks for the return value in R0.