User`s manual

3-24 Suite56 DSP Tools User’s Manual Motorola
Calling Assembly Code from C Code
3.4 Calling Assembly Code from C Code
C compilers—whether distributed by Motorola or by another supplier of software
tools—observe calling conventions (i.e., conventions about how information flows
between a routine that calls a piece of code and the piece of code that is called) usually
documented in the reference manual for that compiler. The documentation about the
calling conventions of a given compiler usually indicates how the compiler uses the
underlying hardware: where the compiler can expect to find incoming data, such as
parameters passed to a routine; where the compiler should place outgoing data, such as the
return values of routines; how symbols are handled; and so forth.
One convention of the Suite56 C compilers (.e.g.,
g563c or g566c) is that they prefix
every symbol with an upper-case
F. When you compile a C program that calls other C
routines, the compiler silently handles this convention, prefixing every called routine with
the requisite
F. When you compile a C program that calls routines written in assembly
code, however, you must observe this convention yourself: in the assembly code, prefix
F
to the names of assembly routines called by your C program and declare those routines
global so that your C program can access them; in the C program, declare the called
routine
extern.
Example 3 -7 on page 3-24 shows you a C program that calls an assembly program in this
way. The assembly routine is declared
extern in the C program. In Example 3 -8 on page
3-25, you can also see the assembly program with its
global declaration and its
required
F prefixing the name of the called routine.
Example 3 -7. A C program That Calls Assembly Code
extern int norm_l(int);
void func(long int Acc, long int Lcr[])
{
int i;
int Exp;
Exp=norm_l(Acc);
for(i=0;i<15;i++){
Lcr[i]=Lcr[i]<<Exp;
}
}