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.

Compiler/AM3358: Reading LR register to a C variable

Part Number: AM3358

Tool/software: TI C/C++ Compiler

Hi,

We are trying to read value of LR register into a C variable, for which we used below mentioned inline function, but are getting error #18: expected a ")".

__attribute__( ( always_inline ) ) __STATIC_INLINE VCI_UINT32 __get_LR(void)
{
    register VCI_UINT32 result;

__ASM volatile ("MOV %0, lr\n\t" : "=r" (result));
    return(result);
}

We referred similar query, linked below, but was unable to understand provided solution:

e2e.ti.com/.../280370

 It would be a great help if you could provide us an example code for the same.

  • The TI ARM compiler does not support GCC-style asm statements.  The best alternative is to implement this function in hand-coded assembly.

    suraj suraj said:
     It would be a great help if you could provide us an example code for the same.

    I'm not aware of an example.  While I did not test it by running it, something close to the following should work ...

    ; UNTESTED EXAMPLE
    
    	.text
    	.global	__get_LR
    __get_LR:
            MOV       A1, LR
            BX        LR

    Put this code in an assembly language source file that has the file extension .asm.  Add it to your project.

    Thanks and regards,

    -George

  • Thanks George.

    We tried your suggestion but it doesn't satisfy our requirement.

    Our use case is to read value of LR register into some global C variable.

    Could you please help us to achieve this?

    Regards,

    Suraj

  • Unfortunately, I cannot think of a good way to solve your problem with the TI ARM compiler.  If it is practical, consider changing to a GCC ARM compiler, such as the one that comes with Code Composer Studio.

    Thanks and regards,

    -George