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.

Writing functions in CLA

Hi,

 

I know how to create macros(.macro) in CLA. Is there a document on how to write functions(.func) in CLA. 

 

Thanks.

 

with warm regards,

K.Sugantha

  • There isnt a document currently, but you're basically limited to using the MCCNDD and MRCNDD instructions. Since its all assembly code, there isnt any restrictions on which registers get arguments and such. I'm thinking that since the return address gets stored in the RPC register and not a stack you cant nest function calls. There are also some pipeline restrictions as to what instructions can/cannot affect the call and return functions. Those are listed in section 5.2 of the CLA reference guide

    Regards

    Vishal

  • Hi,

     

    Thanks for the input. One more clarification.

    Say i m implementing a simple code as below in C and asm.

    -------------------------------------

    // Implementation in C

    void main (void)
    {
    float i=10;

    eg_func(i);
    PwMReg = uint16(i);
    }

    void eg_func(float a)
    {
    a=15.0;
    }

    -----------------------------------------------------
    ; Implementation in asm

    CLATask1:
       
        MMOVF32    MR2, #10.0
        MMOV32    @_i, MR2

        eg_func i

       MSTOP

    ----------------------------------------------------

    eg_func .macro x

        MMOVF32    MR1,#15.0
        MMOV32    @_:x:, MR1
        MSTOP
        .endm
    ------------------------------------------------------

    I m not sure if this is a sensible question. But what i wanted was is there as similar way to write functions
    like how i ve written a .macro. The disadvantage of macro is in places we call, it substitutes that line
    with the entire macro. If i use functions, i can save the program memory. I saw some word .func in CCS. What is that
    used for?

    Thanks.

     

    with warm regards,

    K.Sugantha

  • Implementation in asm

    CLATask1:
       
        MMOVF32    MR2, #10.0
        MMOV32    @_i, MR2
        MCCNDD  eg_func, UNC
        MNOP
        MNOP
        MNOP

       MSTOP

    ----------------------------------------------------
    ;Assume a calling convention, arguments passed in this order
    ; MR0,MR1 ..etc and return values in MR0.
    eg_func:
        MMOVF32    MR1,#15.0
        MMOV32     MRO, MR1
        MRCNDD       UNC
        MNOP
        MNOP
        MNOP
        
    ------------------------------------------------------

    I was looking at the assembler user guide and found a .asmfunc assembler directive that generates debug information but i didnt come across a .func ?

  • Hi Vishal,

    Still the major use of functions is not solved with the code. Consider the case below:


    extern int x;

    void main void
    {
    int a,b;

    egfunc(a);
    egfunc(b);
    .
    .
    }



    egfunc(int y)
    {
    x=y;
    }

    ; Possible implementation in CLA asm
    ----------------------------------------

    egfunc:

        MMOV32    MR0, @_a
        MMOV32  @_y, MR0   ; y = a
            MMOV32    @_x, MR0   ; x = y
        MRCNDD       UNC

    The problem with this code is, i can't pass different variables. The line in main " egfunc(b)" will not work.



    How do i write the above in assembly? How does a compiler/ assembler write functions ?

    If the above simple C code can be written in asm, my problems will be solved.

     

    Thanks in advance.

     

    with warm regards,

    K.Sugantha

  • you cant pass arguments to the function in the normal sense.You could either load MR0 with your intended argument (a or b) before using the MCCNDD _egfunc and assume MR0 as the argument to your routine or setup a software stack in one of the data rams and use that , although that is the more complicated way.

     

    MMOV32 MR0,@_a

    MCCNDD _egfunc, UNC

    ...

    ...

    _egfunc:

    ;argument in MR0

       MMOV32  @_y, MR0   ; y = a
        MMOV32    @_x, MR0   ; x = y
        MRCNDD       UNC