Sign in

username:

password:



Not a member?

Search c55x



Search tips

Subscribe to c55x



c55x by Keywords

AIC23 | C5509 | CCS | CSL | EMIF | EVM | GEL | GPIO | HPI | Interfacing | JTAG | McBSP | OMAP | Omap15 | OMAP59 | RTDX | SDRAM | TMS320VC5509 | USB | XDS5

Ads

Discussion Groups

Discussion Groups | TMS320C55x | calling C from Assm.

Technical discussions about the TI C55x DSPs (including the c5501, c5502, c5503, c5507, c5509, c5510 and OMAP5910).

  

Post a new Thread

calling C from Assm. - thungaturthi sravanthi - Jan 10 5:04:00 2006



 
Hi all,
i'm working on C55x Platform. i need to call a C function from Assembly.i know we can call Assm from C. but what is the way to call a C from Assm.
please, if any one of u know the solution to my problem, please respond to my mail, as it is very very urgent .
Thanks in advance
sravanthi.T.N.S

SRAVANTHI




(You need to be a member of c55x -- send a blank email to c55x-subscribe@yahoogroups.com )

Re: calling C from Assm. - mahesha - Jan 10 9:51:00 2006

Hi,

see the below example

cfile.c

func1(Int32 a,Int32 b)
{
Int32 sum;
sum = a+b;
}

asmfile.asm

.mmregs
.data
x .int 10
y .int 20
.text _asm1
.ref _func1 // c function name

_asm1:
stm #x, ar0
stm #y, ar1
// i need to pass 2 parameters of type int32 to
// asm function so put these 2 parameters in a,b accumulators
mov a, *ar0
mov b, *ar1 // these inscs are not proper, correct the syntax
push sp
push status registers required
call _func1
pop status registers required
pop sp
.end
----- Original Message -----
From: "thungaturthi sravanthi" <sravanthi_123@srav...>
To: <c55x@c55x...>
Sent: Tuesday, January 10, 2006 2:34 PM
Subject: [c55x] calling C from Assm.
Hi all,
i'm working on C55x Platform. i need to call a C function from
Assembly.i know we can call Assm from C. but what is the way to call a C
from Assm.
please, if any one of u know the solution to my problem, please respond to
my mail, as it is very very urgent .
Thanks in advance
sravanthi.T.N.S

SRAVANTHI





(You need to be a member of c55x -- send a blank email to c55x-subscribe@yahoogroups.com )

RE: calling C from Assm. - Lance Ralph - Jan 10 10:09:00 2006

Assuming you're trying to do this in an assembly source file, to make the
call, make sure to declare the function external in your source file, the
function must be properly decorated:

.global _MyCFunc

Call it with:

call _MyCFunc

Look at Help under Code Generation Tools -> Using the C/C++ compiler ->
Run-Time Environment -> Accessing Assembly Language -> Using Assembly
Language Modules with c/c++ code.

Hope this helps.

Lance

-----Original Message-----
From: c55x@c55x... [mailto:c55x@c55x...] On Behalf Of
thungaturthi sravanthi
Sent: Tuesday, January 10, 2006 4:05 AM
To: c55x@c55x...
Subject: [c55x] calling C from Assm.

 
Hi all,
i'm working on C55x Platform. i need to call a C function from
Assembly.i know we can call Assm from C. but what is the way to call a C
from Assm.
please, if any one of u know the solution to my problem, please respond to
my mail, as it is very very urgent .
Thanks in advance
sravanthi.T.N.S

SRAVANTHI




(You need to be a member of c55x -- send a blank email to c55x-subscribe@yahoogroups.com )

Re: calling C from Assm. - thungaturthi sravanthi - Jan 11 1:07:00 2006

hi,
Thankyou for ur valuble response. i implemented it and i found it is working.Thankyou again.

sravanthi. SRAVANTHI





(You need to be a member of c55x -- send a blank email to c55x-subscribe@yahoogroups.com )

Re: calling C from Assm. - Lakshman - Jan 11 10:55:00 2006

Hi Mahesh,

fallowing 3 classes must be keep in mind while calling
assembly function from C,

1. data pointer(16/23
bits):(X)AR0,(X)AR1,(X)AR2,(X)AR3,(X)AR4
2. short (16-bit) data: T0, T1,AR0, AR1, AR2,AR3,AR4
3. 32-bit data (long, float, double): AC0, AC1, AC2

case 1:
long func(int *, int , int , int )
long(return value:32 bit): AC0
AR0: Int pointer
T0: Int16 data
T1: Int16 data
AR1: Int16 data

case 2:
int func(long *, long, long , long , long , int , int*
)
int(return value:16-bit): T0
XAR0: Int32 pointer
AC0: Int32 data
AC1: Int32 data
AC2: Int32 data
stack: Int32 data
T0: Int16 data
AR1: Int16 pointer

when you call a ASM/C function the arguments are
passed in the above mentioned order...

Mahesh, I think you forgot all the assembly coding you
did here...BTW where you push the stack pointer???

BR,
-Lakshman --- mahesha <mahesha@mahe...> wrote:

> Hi,
>
> see the below example
>
> cfile.c
>
> func1(Int32 a,Int32 b)
> {
> Int32 sum;
> sum = a+b;
> }
>
> asmfile.asm
>
> .mmregs
> .data
> x .int 10
> y .int 20
> .text _asm1
> .ref _func1 // c function name
>
> _asm1:
> stm #x, ar0
> stm #y, ar1
> // i need to pass 2 parameters of type int32 to
> // asm function so put these 2 parameters in
> a,b accumulators
> mov a, *ar0
> mov b, *ar1 // these inscs are not proper,
> correct the syntax
> push sp
> push status registers required
> call _func1
> pop status registers required
> pop sp
> .end >
> ----- Original Message -----
> From: "thungaturthi sravanthi"
> <sravanthi_123@srav...>
> To: <c55x@c55x...>
> Sent: Tuesday, January 10, 2006 2:34 PM
> Subject: [c55x] calling C from Assm. >
> Hi all,
> i'm working on C55x Platform. i need to call
> a C function from
> Assembly.i know we can call Assm from C. but what is
> the way to call a C
> from Assm.
> please, if any one of u know the solution to my
> problem, please respond to
> my mail, as it is very very urgent .
> Thanks in advance
> sravanthi.T.N.S
>
> SRAVANTHI




(You need to be a member of c55x -- send a blank email to c55x-subscribe@yahoogroups.com )

Re: calling C from Assm. - mahesha - Jan 12 0:25:00 2006

Hi Lakshman,

Thank You for your detailed and clarity info regarding the same.
I wanted to remove instructions like push sp and pop sp ( its not needed)
and
wanted to save necessary context.

wil write to you more later.

Regards,
Mahesha M

----- Original Message -----
From: "Lakshman" <lakshman97@laks...>
To: "mahesha" <mahesha@mahe...>; "thungaturthi sravanthi"
<sravanthi_123@srav...>
Cc: <c55x@c55x...>
Sent: Wednesday, January 11, 2006 8:25 PM
Subject: Re: [c55x] calling C from Assm. > Hi Mahesh,
>
> fallowing 3 classes must be keep in mind while calling
> assembly function from C,
>
> 1. data pointer(16/23
> bits):(X)AR0,(X)AR1,(X)AR2,(X)AR3,(X)AR4
> 2. short (16-bit) data: T0, T1,AR0, AR1, AR2,AR3,AR4
> 3. 32-bit data (long, float, double): AC0, AC1, AC2
>
> case 1:
> long func(int *, int , int , int )
> long(return value:32 bit): AC0
> AR0: Int pointer
> T0: Int16 data
> T1: Int16 data
> AR1: Int16 data
>
> case 2:
> int func(long *, long, long , long , long , int , int*
> )
> int(return value:16-bit): T0
> XAR0: Int32 pointer
> AC0: Int32 data
> AC1: Int32 data
> AC2: Int32 data
> stack: Int32 data
> T0: Int16 data
> AR1: Int16 pointer
>
> when you call a ASM/C function the arguments are
> passed in the above mentioned order...
>
> Mahesh, I think you forgot all the assembly coding you
> did here...BTW where you push the stack pointer???
>
> BR,
> -Lakshman > --- mahesha <mahesha@mahe...> wrote:
>
>> Hi,
>>
>> see the below example
>>
>> cfile.c
>>
>> func1(Int32 a,Int32 b)
>> {
>> Int32 sum;
>> sum = a+b;
>> }
>>
>> asmfile.asm
>>
>> .mmregs
>> .data
>> x .int 10
>> y .int 20
>> .text _asm1
>> .ref _func1 // c function name
>>
>> _asm1:
>> stm #x, ar0
>> stm #y, ar1
>> // i need to pass 2 parameters of type int32 to
>> // asm function so put these 2 parameters in
>> a,b accumulators
>> mov a, *ar0
>> mov b, *ar1 // these inscs are not proper,
>> correct the syntax
>> push sp
>> push status registers required
>> call _func1
>> pop status registers required
>> pop sp
>> .end
>>
>>
>>
>> ----- Original Message -----
>> From: "thungaturthi sravanthi"
>> <sravanthi_123@srav...>
>> To: <c55x@c55x...>
>> Sent: Tuesday, January 10, 2006 2:34 PM
>> Subject: [c55x] calling C from Assm.
>>
>>
>>
>> Hi all,
>> i'm working on C55x Platform. i need to call
>> a C function from
>> Assembly.i know we can call Assm from C. but what is
>> the way to call a C
>> from Assm.
>> please, if any one of u know the solution to my
>> problem, please respond to
>> my mail, as it is very very urgent .
>> Thanks in advance
>> sravanthi.T.N.S
>>
>> SRAVANTHI
>




(You need to be a member of c55x -- send a blank email to c55x-subscribe@yahoogroups.com )

Re: calling C from Assm. - Mannava - Jan 12 3:34:00 2006

Hi,

General rules to remember for linking C and ASM files.
1. any C file variable if it is global can be used as external variable using .extern directive. All C variables in asm have underscore '_' as a prefix.

for ex:

int x; //C code

is reffered as

.extern _x

2. All function names are reffered in same way using prefixes as shown...

fun ()
{
----

}

is reffered as

.extern _fun

3. If .global directive is used in asm it can be directly called in a C file using extern.

.global _x,_y,_z;

is reffered as

externx,y,z;

4. The function arguments in C go into auxillary registers and to stack if they are more

Regards,
Prem





(You need to be a member of c55x -- send a blank email to c55x-subscribe@yahoogroups.com )