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.

Code Composer studio inline assembly compile problem

Good morning.

I am trying to work on a small project for the Stellaris LM4F120 board, and as part of the project, I have a need to read the stack variable.  (I'm constructing a small context switcher for demonstration purposes.)  I obtained a segment of code from the web as follows:

static inline void * rd_stack_ptr(void){
void * result=NULL;
asm volatile ("MRS %0, msp\n\t"
"MOV r0, %0 \n\t"
: "=r" (result) );
return result;
}

Essentially, what the code is supposed to do is copy the stack pointer into the c variable "result" and return it.  However, I am getting errors as follows:

Description Resource Path Location Type
#126 expected a "(" os.c /OperatingSystem line 27 C/C++ Problem
#18 expected a ")" os.c /OperatingSystem line 29 C/C++ Problem

I have been unable to really find examples of this syntax in the CCS help files, though the code is supposedly written for CCS.  I am using TI compiler v4.9.5 if that provides any assistance.

Thanks for any info you have.  I've done this many times before on other processors, I just haven't been able to find the right manual page with the right details for this part from the materials I have access to.

Walt Schilling

  • Hello!

    You can try thus (for me compiling was successful at least):

    static inline void * rd_stack_ptr(void){
    void * result= NULL;
    __asm("MRS %0, msp\n\t"
    "MOV r0, %0 \n\t"
    ": =r (result)" );
    return result;
    }

    Regards,

    Igor

  • The TI compiler does not accept GCC-style inline assembly syntax.  The TI compiler provides no mechanism for referring to local variables from within the assembly.  See

    http://e2e.ti.com/support/development_tools/compiler/f/343/p/264539/925735.aspx#925735

  • Hello Dear Archaeologist!

    Archaeologist said:

    The TI compiler does not accept GCC-style inline assembly syntax.  The TI compiler provides no mechanism for referring to local variables from within the assembly.  

    That's funny. Ok. I have looked at link. I didn't know about this. It turns out I have befooled the compiler (and myself too), and compiler is a dream spirit. I have written incorrect code and why has compiler not given any error or warning messages? Oddly. (C2000 6.0.1).

    Thanks,

    Regards,

    Igor

  • A "static inline" function is always inlined.  If there are no calls to it, no code gets generated for it.  Remove the "static inline" and compile again.  You'll see that the TI compiler does not accept that asm syntax.

    Thanks and regards,

    -George

  • Hi George!

    Many thanks. You are right absolutly. It's all right with it:

    Invalid mnemonic specification
    MRS %0, msp

    "D:\DOCUME~1\MURZIK~1.HOM\LOCALS~1\Temp\0382810", ERROR! at line 55:
    [E0003]
    Syntax error - Operand 1
    MOV r0, %0

    "D:\DOCUME~1\MURZIK~1.HOM\LOCALS~1\Temp\0382810", ERROR! at line 55:
    [E0003]
    Syntax error - Operand 2
    MOV r0, %0

    "D:\DOCUME~1\MURZIK~1.HOM\LOCALS~1\Temp\0382810", ERROR! at line 56:
    [E0002]
    Invalid mnemonic specification
    : =r (result)

    4 Assembly Errors, No Assembly Warnings

    Errors in Source - Assembler Aborted

    >> Compilation failure
    gmake: *** [main.obj] Error 1
    gmake: Target `all' not remade because of errors.

    Regards,

    Igor