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.

In-Line Assembly Language in C Files

I am attempting to insert all of the TMS570 start-up code into C files. But I have a problem with writing sys_intvecs.asm. The assemler does not like the following:

#include "sys_intvecs.h"

void sys_intvecs(void)
{
/*-------------------------------------------------------------------------------*/
/*; sys_intvecs.asm*/
/*;*/
/*;-------------------------------------------------------------------------------*/
/*; import reference for interrupt routines*/

    asm(".ref _c_int00");
    asm(".ref _undefined");
    asm(".ref _svc");
    asm(".ref _prefetchAbort");
    asm(".ref _dataAbort");
/*;-------------------------------------------------------------------------------*/
/*; interrupt vectors*/

    asm(".sect '.intvecs'");

    asm("            b   _c_int00");
    asm("            b   _undefined");
    asm("            b   _svc");
    asm("            b   _prefetchAbort");
    asm("            b   _dataAbort");
    asm("            b   #-8");
    asm("            ldr pc,[pc,#-0x1b0]");
    asm("            ldr pc,[pc,#-0x1b0]");

/*;-------------------------------------------------------------------------------*/

}

I get errors of the following type:

         Illegal mnemonic specified
    .ref _c_int00
         Symbol .ref has already been defined
    .ref _undefined
         Illegal mnemonic specified
    .ref _undefined
         Symbol .ref has already been defined
    .ref _svc

Is there a way to get around this problem?

Regards,
Dave

  • The first column in assembly statements is reserved for labels (this is documented in the TMS470 Assembly Language Tools Users Guide, section 3.5).
    So the asm statements should be written as asm("  .ref _c_int00"); (with one or more blanks).

     

  • Thank you for your response. The ".ref....." lines now appear to build ok.

    I am getting an error from line 29 as follows:
    "../sys_intvecs.c", line 29: error: this assembly directive not allowed inside a function
    1 error detected in the compilation of "../sys_intvecs.c".

    This is:

        asm("    .sect \".intvecs\"");

    The original assembly language was:
        .sect ".intvecs"

    I have indented the assembly language directive as you suggested (as for the lines starting with .ref, it is not a label as you pointed out)
    I have also "escaped" the quotes (") because it took this to be the end of the code line.

    Is there a way I can get this last assembly language line to be compilable as in-line asm?

    Regards,
    Dave

    P.S. new code is as follows:

    void sys_intvecs(void)
    {
    /*-------------------------------------------------------------------------------*/
    /*; sys_intvecs.asm*/
    /*;*/

    /*;-------------------------------------------------------------------------------*/
    /*; import reference for interrupt routines*/

        asm("    .ref _c_int00");
        asm("    .ref _undefined");
        asm("    .ref _svc");
        asm("    .ref _prefetchAbort");
        asm("    .ref _dataAbort");

    /*;-------------------------------------------------------------------------------*/
    /*; interrupt vectors*/

        asm("    .sect \".intvecs\"");

        asm("            b   _c_int00");
        asm("            b   _undefined");
        asm("            b   _svc");
        asm("            b   _prefetchAbort");
        asm("            b   _dataAbort");
        asm("            b   #-8");
        asm("            ldr pc,[pc,#-0x1b0]");
        asm("            ldr pc,[pc,#-0x1b0]");

    /*;-------------------------------------------------------------------------------*/
    }

  • Dave,

    It seems that the .sect assembly directive is not allowed inside a C function, probably because the C function is already being compiled into a intialized section by the compiler (default of .text). You may need to use the #pragma CODE_SECTION to place the C routine into a named section. The pragma is documented in the Compiler Users Guide.

    I also wanted to add the caution that it is generally not advisable to use inline assembly as it could disrupt the C environment and produce unexpected results, especially when using optimization. Please check section 6.5.4 of the Users Guide. A better method is to implement the entire function in assembly code, and call the assembly function from the C code. Details on interfacing C and assembly can be found in the same Users Guide.