
In-line Assembly Code
Motorola
Mixing C and Assembly Language
For More Information On This Product,
Go to: www.freescale.com
5-17
Example 5-23. Program DSP56001 SCI Timer
Program DSP56001 SCI Timer: The SCI timer can be programmed so that a SCI interrupt
service routine is accessed periodically. The following in-line assembly program is based
on the SCI timer described in section 11.2 of the DSP56000/DSP56001 User Manual.
_ _asm(“\nSCR
_ _asm(“\nSCCR
_ _asm(“\nIPR
main()
{
_ _asm( “move
EQU
EQU
EQU
$FFF0”);
$FFF2”);
$FFFF”);
#0,r7\n\
#$2000,x:SCR\n\
#$013f,x:SCCR\n\
#$C000,x:IPR\n\
#$fc,mr\n\
END”);
p:$001c\n\
(r7)+\n\
movep
movep
movep
andi
jmp
\nEND
_ _asm (“org
move
nop”);
}
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. 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,
"Compiler Naming Conventions," on page 4-13), and does not generate arbitrary labels
like most assembly programs. 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, Section 4-7 reads the data
at x memory location $100 and y memory location “y+2”. For test purposes, the y memory
space is filled with the integer sequence 0 through 9 and the x memory space is left
uninitialized. The
printf()
statement prints the data returned from the functions
ValOfX(100) and ValOfY(y+2). These two functions are constructed in assembly code
and reside in another file. The two assembly subroutines, ReadX and ReadY, are written
F
Freescale Semiconductor, Inc.
n
.