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.

call a function written in asm

Other Parts Discussed in Thread: MSP430FG437

HI,

I am trying the pulse oximeter (slaa274) with MSP430FG437. in the c code, a function "mul16" is called, but it is defined in asm in another file "mul.s43".

If I just include the mul.s43 file into the project, there will be lots of errors say "[E0003] Only labels and comments may begin in the first column. Make sure that the label name is not a reserved keyword. ", "[E0001] Undefined symbol ", and "[E0002] Illegal mnemonic specified".
By the way, I am using CCS v5


Could anyone help me on this problem?

Thanks!

  • Those error messages come from the assembler, so CCS has correctly identified the file mul.s43 as an assembly language file.  However, that file is an IAR-format file.  The IAR assembler and the TI assembler differ slightly in the required syntax.  You'll need to modify the file mul.s43 to conform to the requirements of the TI assembly code language.  In particular, the TI assembler doesn't support "PUBLIC", "RSEG", "END" or "#define".  Try this:

    [..]
            .def    mul16
            .text
    mul16
            .asg r9, x1
            .asg r13, z0
            .asg r15, z1
            .asg r12, x
            .asg r14, y
    [..]
            pop     r9
            ret
           .end
  • Hi,

    thanks for your help.

    seems CCS doesnt identify the file "mul.s43" as an asm file, since almost each line has an error, "[E0001] Undefined Symbol" except the line with command push pop and jump.

    and when i tried to change to .asg, there is another kind of error message "[E0300] Symbol .asg has already been defined".




  • I know CCS is recognizing mul.s43 as an assembly file, because that error message format is particular to the assembler.

    The error message "Symbol XYZ has already been defined", where XYZ is an assembler directive or mnemonic, means you have forgotten to include leading whitespace before the directive or mnemonic.  Without this leading whitespace, XYZ is interpreted as a label, which is not going to work. 

    Please show me the exact text of all of the error messages coming from this file.

  • Hi, thanks for your help.

    below is the error message. ( I change the file name from "mul.s43" to "mul.asm"

    Description    Resource    Path    Location    Type
    [E0001] Undefined symbol    mul.asm    /pulsoxi_v1.0    line 12    C/C++ Problem
    [E0001] Undefined symbol    mul.asm    /pulsoxi_v1.0    line 13    C/C++ Problem
    [E0001] Undefined symbol    mul.asm    /pulsoxi_v1.0    line 14    C/C++ Problem
    [E0001] Undefined symbol    mul.asm    /pulsoxi_v1.0    line 15    C/C++ Problem
    [E0001] Undefined symbol    mul.asm    /pulsoxi_v1.0    line 17    C/C++ Problem
    [E0001] Undefined symbol    mul.asm    /pulsoxi_v1.0    line 21    C/C++ Problem
    [E0001] Undefined symbol    mul.asm    /pulsoxi_v1.0    line 22    C/C++ Problem
    [E0001] Undefined symbol    mul.asm    /pulsoxi_v1.0    line 24    C/C++ Problem
    [E0001] Undefined symbol    mul.asm    /pulsoxi_v1.0    line 25    C/C++ Problem
    [E0001] Undefined symbol    mul.asm    /pulsoxi_v1.0    line 27    C/C++ Problem
    [E0001] Undefined symbol    mul.asm    /pulsoxi_v1.0    line 33    C/C++ Problem
    [E0001] Undefined symbol    mul.asm    /pulsoxi_v1.0    line 34    C/C++ Problem
    [E0001] Undefined symbol    mul.asm    /pulsoxi_v1.0    line 36    C/C++ Problem
    [E0001] Undefined symbol    mul.asm    /pulsoxi_v1.0    line 37    C/C++ Problem
    [E0001] Undefined symbol    mul.asm    /pulsoxi_v1.0    line 38    C/C++ Problem
    [E0001] Undefined symbol    mul.asm    /pulsoxi_v1.0    line 40    C/C++ Problem
    [E0001] Undefined symbol    mul.asm    /pulsoxi_v1.0    line 44    C/C++ Problem
    [E0002] Illegal mnemonic specified    mul.asm    /pulsoxi_v1.0    line 4    C/C++ Problem
    [E0002] Illegal mnemonic specified    mul.asm    /pulsoxi_v1.0    line 5    C/C++ Problem
    [E0002] Illegal mnemonic specified    mul.asm    /pulsoxi_v1.0    line 6    C/C++ Problem
    [E0002] Illegal mnemonic specified    mul.asm    /pulsoxi_v1.0    line 7    C/C++ Problem
    [E0002] Illegal mnemonic specified    mul.asm    /pulsoxi_v1.0    line 8    C/C++ Problem
    [E0300] Symbol .asg has already been defined    mul.asm    /pulsoxi_v1.0    line 5    C/C++ Problem
    [E0300] Symbol .asg has already been defined    mul.asm    /pulsoxi_v1.0    line 6    C/C++ Problem
    [E0300] Symbol .asg has already been defined    mul.asm    /pulsoxi_v1.0    line 7    C/C++ Problem
    [E0300] Symbol .asg has already been defined    mul.asm    /pulsoxi_v1.0    line 8    C/C++ Problem
    [E0300] The following symbols are undefined:    mul.asm    /pulsoxi_v1.0         C/C++ Problem

    and the file is:

            .def  mul16
            .text
    mul16
    .asg     r9,x1
    .asg     r13,z0
    .asg     r15,z1
    .asg     r12,x
    .asg     r14,y

                push    r9

            clr        z0
            mov        z0,z1
            mov        z0,x1
            tst        x
            jge        xbooth_2
            mov        #-1,x1
            jmp        xbooth_2

    xbooth_6
            add        x,z1
            addc    x1,z0
    xbooth_1
            rla        x
            rlc        x1
    xbooth_2
            rra        y
            jc        xbooth_5
            jne        xbooth_1
            jmp        xbooth_4

    xbooth_5
            sub        x,z1
            subc    x1,z0
    xbooth_3
            rla        x
            rlc        x1
            rra        y
            jnc        xbooth_6
            cmp        #0FFFFh,y
            jne        xbooth_3

    xbooth_4
                mov     z1,r12

                pop     r9

                ret
               .end



  • You have hit the same error I mentioned earlier:

    Archaeologist said:
    The error message "Symbol XYZ has already been defined", where XYZ is an assembler directive or mnemonic, means you have forgotten to include leading whitespace before the directive or mnemonic.  Without this leading whitespace, XYZ is interpreted as a label, which is not going to work.

    Those lines beginning with .asg must have leading whitespace.  Go to those lines and add a tab before the period, like so:

            .text
    mul16
            .asg     r9,x1
  • Thanks very much! There is no error in the asm file now.

    But there is still some error about the linker or something else.

    below is the error message.

    Description    Resource    Path    Location    Type
    #10010 errors encountered during linking; "pulsoxi_v1.0.out" not built    pulsoxi_v1.0             C/C++ Problem
    #10234-D  unresolved symbols remain    pulsoxi_v1.0             C/C++ Problem
    unresolved symbol __MSPABI_FUNC_EPILOG_3, first referenced in ./main.obj    pulsoxi_v1.0             C/C++ Problem
    unresolved symbol __MSPABI_SRAI_4, first referenced in ./main.obj    pulsoxi_v1.0             C/C++ Problem
    unresolved symbol __MSPABI_SRAI_6, first referenced in ./main.obj    pulsoxi_v1.0             C/C++ Problem
    unresolved symbol __MSPABI_SRAL_10, first referenced in ./main.obj    pulsoxi_v1.0             C/C++ Problem
    unresolved symbol __MSPABI_SRAL_15, first referenced in ./main.obj    pulsoxi_v1.0             C/C++ Problem
    unresolved symbol __MSPABI_SRAL_9, first referenced in ./main.obj    pulsoxi_v1.0             C/C++ Problem
    unresolved symbol main, first referenced in D:\TI\ccsv5\tools\compiler\msp430_4.1.1\lib\rts430_eabi.lib<boot.obj>    pulsoxi_v1.0             C/C++ Problem

    If I just declare a mul function in C without using the asm file, then the project will work.

    I can find these symbols start with __MSPABI in the error message in the main.asm in the Ddebug folder in the project which I guess is translated by the compiler. But I do not know how to solve these error messages.



  • Those symbol names are bogus.  Uppercase letters vs. lowercase letters matters; please make sure you are copying the exact text of the error message, and not altering the letter case.  The correct names for those symbols are:

    __mspabi_func_epilog_3
    __mspabi_srai_4
    __mspabi_srai_6
    __mspabi_sral_10
    __mspabi_sral_15
    __mspabi_sral_9
    

    If you have a hand-coded assembly function which calls these functions directly, you must use the lowercase version.

    However, I think it is more likely that you are compiling main.c in COFF ABI mode, and attempting to link it against the EABI C library.  You must make sure that all files are compiled with the same ABI, either COFF ABI or EABI, and the matching C library must be used.  Check your project options to make sure you are using the --abi=eabi option for all files.

  • Thanks for your help!

    Finally there is no error message troubling me!

    I do use all as --abi=eabi.

    The problem is the case-sensitive. When I cancel the option "Symbol names are not case-sensitive" in the Assembler options, then it works.

    Now I can carry on with my Final year project, LOL.

  • Hi,

    when i debug the whole project, I found although there is no error message, the mul16 function in asm still does not work properly.

    I try a small program:

    ......

    .........

    int x,y;

    long z;

    x=4;

    y=13;

    z = mul16(x,y);

    print (z); // a function i write to print the number z through uart

    ......

    .....

    i include the asm file in the project, the program will print rubbish on the screen, however if i use the function below instead, the correct answer 52 will be printed.

    int32_t mul16(register int16_t x, register int16_t y)
    {
        return (int32_t)x * y;
    }

    is there still anything needed to be modified in the mul.asm mentioned before?

  • Hi Hanjie,

    is there a declaration of that asm function somewhere in your code? You have to declare the asm function ("extern") to your compiler to reliable invoke it:

    extern int32_t mul16(int16_t, int16t);

    The compiler needs to know the return value to be type of int32_t, else it is assuming int. There must be a compiler warning #225 "function declared implicitly" if there is no declaration.

    I hope it helps.

    Best regards

  • Hi Christian,

    I Tried declare as extern, and I found that every time I re-lauch it (not rebuild the project, just terminate and click the debug again), the result will be different.

    Is this because the result in asm code is stored in a wrong place?

    Or do I need to do something to make the code in asm public?

    Thanks for your help.

  • Hi Hanjie,

    Archaeologist said:

    Those error messages come from the assembler, so CCS has correctly identified the file mul.s43 as an assembly language file.  However, that file is an IAR-format file.  The IAR assembler and the TI assembler differ slightly in the required syntax.  You'll need to modify the file mul.s43 to conform to the requirements of the TI assembly code language.

    As Archaeologist already noted mul.s43 is written for IAR assembly. TI's assembly language has a different register convention. I strongly recommend to read slau132g "MSP430 Optimizing C/C++ Compiler v4.1 User's Guide" chapter 6, but especially sections 6.3 Register Conventions, 6.4 Function Structure and Calling Conventions and 6.5 Interfacing C and C++ With Assembly Language.

    TI's compiler places the first arguments in registers R12-R15 in that order if a function (parent) calls another function (child). So you have argument x placed in register R12 and y placed in R13.

    Have a look at mul.s43:

    .asg     r9, x1
    .asg     r13,z0
    .asg     r15,z1
    .asg     r12,x
    .asg     r14,y

    You find argument x placed in register R12 but (!!) argument y in register R14. R13 is used for z0 and it is cleared at the beginning ("clr z0") of that function. You have to adapt the register conventions to TI's assembly format, otherwise it will not work.

    Best regards,
    Christian

  • Hi Christian,

    Thanks for your help!

    After i made the change

            .asg     r9,x1
            .asg     r14,z0
            .asg     r15,z1
            .asg     r12,x
            .asg     r13,y

    .......

    .......

            mov        z1,r12
            mov        z0,r13

    It works!

  • Hi Hanjie,

    I'm glad to here that it helped.

    Christian