Out-of-line Assembly Code
Motorola
Mixing C and Assembly Language
For More Information On This Product,
Go to: www.freescale.com
5-29
5.4.1.5 Epilogue
The out-of-line template epilogue is the reverse of the prologue. The epilogue restores the
return address and updates the frame pointer, R0. Notice that the stack pointer, R6, should
be decremented before each move operation. In addition, register A is tested to update the
SR register. This testing is a part of the C compiler code generation feature and should be
included (see Section 5.4.5 for optimization).
5.4.1.6 Out-of-line Assembly Code Example
The following example illustrates using the general template as well as the fact that the
DSP56000/DSP56001 performs fractional arithmetic. Assume that section mod1 contains
two C callable subroutines,
mac01()
and
mac02()
and section
mod2
contains a single C
callable subroutine,
mactwo()
. The two functions
mac01()
and
mac02()
take one
argument each and
mactwo()
takes two arguments. These functions perform
multiplication according to the following formulas and return their results:
Note that multiplication on the DSP56000/DSP56001 treats data as fractions; however,
the C programming environment does not support a fractional data type. Therefore data
will be passed as integers from the C programming environment and will be treated as
fractional data in the DSP56000/DSP56001. This can be an advantage if fractional
arithmetic is desired since this is normally difficult to accomplish in C. Note that the
calling routine must ensure arg is in range to prevent overflow.
The following function declarations (ANSI standard) can be used to declare functions
which are known to perform fractional arithmetic. Internally, the size of integers is the
same as the size of fractions.
int mac01(int);
int mac02(int);
int mactwo(int, int);
mac01(arg)
calculates
arg * 0.01
mac02(arg)
calculates
arg * 0.02
mactwo(arg1,
arg2)
calculates
arg1 * arg2
F
Freescale Semiconductor, Inc.
n
.