Argument Passing Problem.

Started by Prakash Kamliya March 29, 2006
We are facing one problem with CCS 3.1 and also with CCS 2.1
Argument passing is incorrect.

We call 2 functions.
GenCallPrgTone(x, y, z)
-> UMTG_genSignal(x)

here the x, y and z arguments are passed in AR0, AR1 and T0 respectively,
but it passes incorrect value of x to UMTG_genSignal function, instead it
passes value of y !

UMTG_genSiganl(genObj2->fxn, tmpSamples, 50)

UMTG_genSignal(long x, char *buf, int len)

ALG_Activate(long x)
// uses x for further.

Assembly Listing :

MOV #50, T0
MOV dbl(*(#(_genObj2+26))), XAR0
AMOV #_tmpSamples, XAR1
CALL #_UMTG_genSignal

AADD #-10, SP

MOV T0, *SP(#4)
MOV XAR2, dbl(*SP(#2))
MOV XAR1, dbl(*SP(#0)) // here it should store XAR0 instead XAR1 !
MOV dbl(*SP(#0)), XAR0
CALL _ALG_activate

If you need whole listing of code we can mail you the same.

Please provide fix or workaround as early as possible.

- Prakash
Hello Sravanthi,

Thanks for your reply.

I had also the same question that : why other function should use XAR2 !,
because parent is passing arguments in XAR0, XAR1 and T0.

Well I found the problem with my code. Problem was like this.

In the first file where GenCallPrgTone (parent function) is calling the
child function (UMTG_genSignal) declared in some other file,
i did not declared the function prototype for UMTG_genSignal in the first
file. I found from that if we dont declare prototype, compiler treat as
return value to be void and so compiler generates code for first file which
passes argument starts from XAR0, XAR1 and T0.
(If we dont have return type compiler starts argument list assingment from
XAR0 and if we have return type it starts
argument list assignment from XAR1 - SPRU281f.pdf)

While in the child file (where the UMTG_genSignal defination is present)
actually it returns a integer value.
So compiler generates code which uses XAR0 for return type and XAR1, XAR2
and T0 for argument list. thats why the assembly listing
of UMTG_genSignal function contains referecne for XAR2.

the solution is if i declare my function prototype in the first file, both
agrees to same rules for argument passing and return types. And compiler
will generate code which uses same registers for arguments and return types.

Actually the default behaviour of CCS is do not generate warnings if we use
functions without any declaration of function before using it.
To turn on the warning (remark) for such cases, there is option -pdr (Issue
remarks) to enable remark generation.

It is always better to keep this option always ON so that in future we do
not cought in such problems.

Please let me know if you need more info.


----- Original Message -----
From: thungaturthi sravanthi
To: Prakash Kamliya
Sent: Wednesday, March 29, 2006 5:52 PM
Subject: Re: [c55x] Argument Passing Problem.

i've a Q:n for u. in the asm code, where from u are getting the XAR2
pointer. beco'z the input arg.s are coming in to XAR0 ,XAR1 and T0
but where is the Q.n of XAR2?

second thing is, since u have given XAR1, it is sending XAR1 in to
the specified stack location.

there(if i'm not wrong) u should specify XAR0 and XAR1.
or else, send me the entire code, so that i get a clear idea .