Download DSP563CCC DSP56300 Family Optimizing C Compiler User`s Manual

Transcript
read the program.
int read_n_add ( int data, int* ptr_a, int* ptr_b )
{
int tmp_a, tmp_b;
_ _asm ( “\
move x:(%3),%1
\n\
move x:(%4),%2
\n\
add %1,%0
\n\
add %2,%0“ : “=D” (data), “=S”, “=S” : “A” (ptr_a), “A” (ptr_b));
return data;
}
Example 5-19.
Instruction Template Label: The following in-line assembly
code which generates the label “foo” uses a return character “\n” to
insure that there is no white space in front of the label.
_ _asm(“\nfoo”);
5.2.5 Controlling Labels Generated by the Compiler
Using the _ _asm() keyword, it is possible for the programmer to override the compilers
label generation conventions for subroutines and global variables. In general, this practice is discouraged. This may be useful for:
1. calling assembly language subroutines,
2. calling C subroutines from assembly code,
3. referencing assembly language global variables from C,
4. referencing global C variables from assembly code.
5.2.5.1 Calling Assembly Subroutines
Calling a subroutine or function requires using a label that points to the subroutine or
function. The C compiler uses a predetermined labeling convention (see Section 4.7). In
order to call assembly subroutines labeled in an arbitrary fashion, _ _asm() can be used
to overwrite the C convention label with an arbitrary label.
To illustrate how to use the _ _asm directive for this purpose, Example 5-20. reads the
data at x memory location $100 and y memory location “X+2”. For test purposes, the y
memory space is filled with the integer sequence 0 through 9. The printf() statement
prints the data returned from the function calls ValOfX(100) and ValOfX(X+2). This function was written in assembly code and resides in another file.
MOTOROLA
DSP563CCC User’s Manual
5-13