SLAA140.
4 Mixing C and Assembler With the MSP430
If the C code is compiled with -ur45, but the application is not to run in the ROM monitor, then it
is possible to use R4 and R5 in the assembler routine without saving them, since the C code
never uses them.
2.2 Interrupt Functions
The calling convention cannot be used for interrupt functions, since the interrupt may occur
during the calling of a foreground function. Hence, the requirements for an interrupt function
routine are different from those of a normal function routine as follows:
• The routine must preserve all used registers, including scratch registers R12–R15.
• The routine must exit using RETI.
• The routine must treat all flags of the status register as undefined (Carry / Neg. / Zero /
Overflow).
2.3 Defining Interrupt Vectors
As an alternative to defining a C interrupt function in assembly language as described above, the
user is free to assemble an interrupt routine and install it directly in the interrupt vector.
The interrupt vectors are located in the INTVEC segment.
3 Combining C and Assembler Functions
3.1 General Basics
The mechanics to combine C and assembler functions are fairly straightforward. Basically C
code within .c files imports labels exported by the assembler files using the extern keyword.
Assembler codes within .s43 files export labels to the C code using the PUBLIC keyword.
Assembler code import labels exported by C code using the EXTERN keyword. No keyword is
required to export C labels to assembler code.
Once the .c and .s43 files are written, they are added to the workbench project and the project is
built. See the example .c, .s43, and project (.prj) files included with this application note. See the
IAR documentation for a more complete description of this process.
3.2 Calling Assembler Functions Without Parameters to Pass
If no parameters have to be passed between the C code and the assembler function, a simple
call instruction can be used. See example 1.
3.3 Calling Assembler Functions With Parameters to Pass
When it is required to pass parameters from C to the assembler function, the parameters must
be located as described in the Stack Frames and Parameter Passing section.
Example 2 shows how parameters are passed between the C main program and an assembler
function.
评论0
最新资源