DSPRelated.com
Forums

Calling C function From Assembly

Started by bharath March 29, 2006
Hi all,
I am calling C function from Assembly, I strore the return address in B3 and then i call the assembly function using call routine. I want to know wether i have to save the registers from (A0 to A9) (A16-A31) and (B0 to B9)(B16-B31) on stack before calling ,and pop those values after returning back rom C?. what others things i should takecare when calling C from Assembly. kindly reply ASAP.

thanking you
bharath

---------------------------------
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre.
Hi Bharath,

important are only register which have to keep their value after the
call :-)

I'm not sure if the calling function or the called function does save
the registers on the stack. You could have a look at the *.lst files to
find out.

Maybe this behavior depends on compiler switches (optimisation).

Gustl

bharath schrieb:
> Hi all,
> I am calling C function from Assembly, I strore the return
> address in B3 and then i call the assembly function using call routine.
> I want to know wether i have to save the registers from (A0 to A9)
> (A16-A31) and (B0 to B9)(B16-B31) on stack before calling ,and pop
> those values after returning back rom C?. what others things i should
> takecare when calling C from Assembly. kindly reply ASAP.
>
> thanking you
> bharath
>
>
> To help you stay safe and secure online, we've developed the all new
> *Yahoo! Security Centre*
> .
>
>
>
Bharath--

On 3/29/06, bharath wrote:
>
> Hi all,
> I am calling C function from Assembly, I strore the return
> address in B3 and then i call the assembly function using call routine. I
> want to know wether i have to save the registers from (A0 to A9)
> (A16-A31) and (B0 to B9)(B16-B31) on stack before calling ,and pop those
> values after returning back rom C?.
>

The C compiler is free to use ANY register it wants, when it enters a
compiled C function; it definitely does not know the registers that you have
utilized outside the scope of C and might not be able to understand that you
want them preserved. You must save all registers of interest(depends on your
asm code) and them pop them back on return from C function.

Alternatively, it might be a better idea (as a matter of policy) to code all
functions called from an assembly function in LinAsm because LinAsm allows
you to *reserve* registers(context of ASM function) that you donot want
Linear Assembler to utilize when it generates optimized asm code.

--Bhooshan

what others things i should takecare when calling C from Assembly. kindly
> reply ASAP.
>
> thanking you
> bharath
>
> ------------------------------
> To help you stay safe and secure online, we've developed the all new *Yahoo!
> Security Centre*
> .
>
> ------------------------------
>

--
-------------------------------
"I've missed more than 9000 shots in my career.
I've lost almost 300 games. 26 times I've been trusted to take the game
winning shot and missed.
I've failed over and over again in my life.
And that is why I succeed."
-- Michael Jordan
--------------------------------
Please use serial assembly, this reduces errors in assembly coding.
Additionally then you can simply use the .call directive,

And compiler takes care of the rest, for eg: you can just write as follows
to call rts6400.lib _divu as:

A_ret = .call _divu (A_num, A_den);

You will have to declare .global _divu at the top of your file.

Hope this helps!.

Regds

JS

_____

From: c... [mailto:c...] On Behalf Of Bhooshan
Iyer
Sent: Thursday, March 30, 2006 1:01 AM
To: bharath
Cc: c...
Subject: Re: [c6x] Calling C function From Assembly

Bharath--

On 3/29/06, bharath wrote:

Hi all,

I am calling C function from Assembly, I strore the return
address in B3 and then i call the assembly function using call routine. I
want to know wether i have to save the registers from (A0 to A9) (A16-A31)
and (B0 to B9)(B16-B31) on stack before calling ,and pop those values after
returning back rom C?.

The C compiler is free to use ANY register it wants, when it enters a
compiled C function; it definitely does not know the registers that you have
utilized outside the scope of C and might not be able to understand that you
want them preserved. You must save all registers of interest(depends on your
asm code) and them pop them back on return from C function.

Alternatively, it might be a better idea (as a matter of policy) to code all
functions called from an assembly function in LinAsm because LinAsm allows
you to *reserve* registers(context of ASM function) that you donot want
Linear Assembler to utilize when it generates optimized asm code.

--Bhooshan

what others things i should takecare when calling C from Assembly. kindly
reply ASAP.

thanking you

bharath
_____
To help you stay safe and secure online, we've developed the all new
ecurity.yahoo.com/> Yahoo! Security Centre.

_____

--
-------------------------------
"I've missed more than 9000 shots in my career.
I've lost almost 300 games. 26 times I've been trusted to take the game
winning shot and missed.
I've failed over and over again in my life.
And that is why I succeed."
-- Michael Jordan
--------------------------------

*

_____