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.

CCS/LAUNCHXL-F28377S: Parameter of Assembler Function in C

Part Number: LAUNCHXL-F28377S

Tool/software: Code Composer Studio

Hi,

I am trying to run a Assembler function C.

...
extern unsigned int asmfunc( int Vref, int Vadc, int b0);

void main(void)
{
	test = asmfunc( 4, 5, 8);
}
...
SPRU514L on page 145/203 Chapter 7.3.1 5:
You can see that int Vref is placed in AL Register and Vadc placed in the AH register. This part works fine.
But b0 ist placed in the stack.

How can i geht access to value of b0?

SPRU430F on page 85/551 i tried the different stack addressing modes
	.global  _asmfunc

_asmfunc:
        ; AL = 4
        ; AH = 5 
	ADDL ACC, *-SP[1]

  • Hi Jonas,
    b0 will be at *-SP[3]. The calling function will place stack argument first, and then the return program counter (RPC) at *-SP[2] before calling asmfunc(). To verify that b0 is at *-SP[3] you can first step into the assembly function in the disassembly window, find out what SP is from the register view, and then examine the words before that address in the memory browser.

    for example, if you find SP = 0x8003 as you get into the assembly function then open up the mem browser window and see if the value 8 is at 0x8000.
  • Hi Vishal,
    Thanks for your answer. I solved the Problem for this example (b0 was placed in XAR4 register, but i have the same Problem with another.
    I hope you can help me.


    C-Code:

    extern unsigned int asmfunc( int Vref, int Vadc, int b0, int a1, int c1, int d);

    void main(void)
    {
    test = asmfunc( 4, 5, 8, 200, 2, 40);
    }


    Assmbly-Code:

    .global _asmfunc

    _asmfunc:
    ; AL = 4
    ; AH = 5
    ; XAR4 = 8
    ; XAR5 = 200





    Where is Variable c1, d placed?

    How can i add for example Vref+b0? ; Vref is placed in AL
    ADD AL, ???

    Like this:
    ADD AL, *-SP[3] ; which number is correct and why?

    Thank you so much,
    Jonas
  • Hi,

    still have this Problem. Can anybody help me?
  • Hi Jonas,

    Sorry for the delay, i didn't see your response to my post earlier.

    From the compiler guide (SPR514, section 7.3.1), 

    (e) Remaining 16-bit arguments are placed in the order AL, AH, XAR4, XAR5 if they are available.
    4. Any remaining arguments not placed in registers are pushed on the stack in reverse order. That is, the
    leftmost argument that is placed on the stack is pushed on the stack last. All 32-bit arguments are
    aligned to even addresses on the stack.

     

    So, d1 and c1 should have been placed on the stack as shown

     

    ;; |_______|<- Stack Pointer (SP)
    ;; |_______|<- c1 (SP-1)
    ;; |_______|<- d1 (SP-2)
    ;; |_______|<- return pc of calling function (SP-4)

     

    Jonas Hemmer said:
    How can i add for example Vref+b0? ; Vref is placed in AL

    ADD AL, @AR4 ; adding Vref (AL) and b0 (lower half of XAR4)

  • ADD AL, @AR4 overwrites the original Vref value so if you need Vref for other calculations you should save AL to the stack or another ARn register before the addition
  • Thanks for your quick respone.
    The original Problem is how to adress the stack

    How can i add for example Vref+c1?
    like this:
    ADD AL, *–SP[1] ???

    This does not work in my example

    Thank you very much,

    Jonas
  • If you go to the archived workshops, F28335-> Student Guide -> appendix E you will find an example of instructions that use SP, AL. That plus the assembler users guide should help. Sorry, it has been several years since I worked with C2000 assembly...

    processors.wiki.ti.com/.../C2000_Archived_Workshops

    Hopefully, that helps.
  • I think i got the stack placement wrong - the calling function's return PC should be the last thing on the stack prior to moving execution to the assembly function

    ;; |_______|<- Stack Pointer (SP)
    ;; |_______|<- return pc of calling function (SP-2)
    ;; |_______|<- c1 (SP-3)
    ;; |_______|<- d1 (SP-4)

    "ADD AX, loc16 —Add Value to AX"

    and loc16 can be through stack addressing, i.e. *-SP[n]. Check that the value, c1 or 2 in the example from your post, is at SP-3 in the memory browser?
  • I have to thank both of you very much.
    Vishal your description above this comment is right. This works.
    And the workshop sheet is very helpful too.

    Regard,

    Jonas