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.

Calling C function from ASM



In srpru514j section 7 it outlines how to call asm functions from C, and it makes 'mention' of

"When you call a C/C++ function from assembly language, load the designated registers with arguments and push the remaining arguments onto the stack as described in section 7.3.1"

So if I have

file1.cla

myFunction(params) {

.. whatever it does

}

file2.asm

.global  _myFunction

MOV params into appropriate registers

MBCNDD #_myFunction

MNOP

MNOP

MNOP

It complains unresolved symbol when it links that _myFunction doesn't exist.

Is there more that I'm required to do in this case?

  • in file2.asm, if you change .global to .ref does the behavior change?
  • No, It still is not able to find myFunction.

    I checked the listing file of file1.lst and it is compiling myFunction and I see it using the symbol _myFunction, so to the best of my knowledge it is present in file1.obj, not sure why linker can't find it.
  • Rob -

    I'll ask someone who writes assembly often to take a closer look at your question. Many members of the team are on Holiday this week for US Thanksgiving so the response may be delayed.

    Thank you
    Lori
  • I think I may have found some valuable information as to what it might be related to.

    I simplified the code to key parts to display to you... but in actuality (while it shouldn't make a difference) I do it a smidge differently... but I tried exactly what I showed you and it worked, so I put the following alteration in and it fails... so I think if you can explain it this might be why it's failing, and hopefully there is a solution.

    Essentially same question but make one modification.
    file1.h

    #pragma FUNC_ALWAYS_INLINE(myFunction)
    inline void myFunction( void ) {
    DoSomething
    }

    file1.cla
    void someFunction(void) {
    myFunction();
    }

    file2.asm
    same as I did before... with .global or .ref...

    So the key difference is ... by putting myFunction in the header, declaring it as inline, so when file1.cla compiles it includes the function, and you do see it in the file1.lst file... it doesn't actually inline it because I don't have optimizations on, so it creates a _myFunction in the file1.cla file... but there must be something different because of the inlining...

    when I ACTUALLY pull it out of the header file, drop the inlining... the assembler/linker works...

    SO the question is:
    Why would doing it in this way cause a conflict with the linker? I still 'see' the _myFunction in the file1.lst? so why can't the linker see it?

    Thanks.
  • looking at the listing file when I compile it both ways, when it works (when I don't do the inline method) the listing file includes a .global _myFunction in the file1.lst file... while when I do it the inline way, the same code results, but the listing file doesn't contain a .global _myFunction in it..

    As per the spruf513k section 2.5.1, it appears that in assembly I need to declare it (.def.ref.global) in both files... however since the C compiler is compiling ONE of the files in this case, the C compiler must put the .global or .def in for me..

    So based on what I see in the listing file it's clear that when I do it the inline way (even though it's not inlining because no optimizations on) it doesn't place the .global into the c compiled file, so when the linker tries to link it... it fails...

    Q: is this appropriate? ie: should the compiler be updated? Or do I need to find a way around it... In this case I should simply be able to build a dummy function in the file

    file1.h
    #pragma FUNC_ALWAYS_INLINE(myFunction)
    inline void myFunction( void ) {
    do something
    }


    file1.cla
    void dummyFunc(void) {
    myFunction();
    }

    file2.asm
    .global _dummyFunc

    ... etc.

    In this way it should put the .global in the c compiled file for me... so I can call it from assembly...

    Please let me know if this can be corrected, or if there is a reason it doesn't work.

    Thanks.
  • Where is the calling procedure outlined in the documentation for the CLA? Do I just load the registers to pass parameters and call it? do I need to do anything else? Restore anything after it returns?
  • Rob,

    Function calling convention for the CLA is documented in 10.2.4. I have attached a sample project that has a .cla file that calls a function in a .asm file. Hopefully it helps,

    F2837x_CLA_unsignedModulus_151113.zip