MSP430 Optimizing C++ Compiler 6.5

MSP430 Optimizing C++ Compiler 6.5 - Interfacing...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
6.4.3 Accessing Arguments and Local Variables 6.5 Interfacing C and C++ With Assembly Language 6.5.1 Using Assembly Language Modules With C/C++ Code Interfacing C and C++ With Assembly Language A function accesses its local nonregister variables indirectly through the stack pointer (SP or R1) and its stack arguments. The SP always points to the top of the stack (points to the most recently pushed value). Since the stack grows toward smaller addresses, the local data on the stack for the C/C++ function is accessed with a positive offset from the SP register. The following are ways to use assembly language with C/C++ code: Use separate modules of assembled code and link them with compiled C/C++ modules (see Section 6.5.1 ). Use assembly language variables and constants in C/C++ source (see Section 6.5.2 ). Use inline assembly language embedded directly in the C/C++ source (see Section 6.5.4 ). Interfacing C/C++ with assembly language functions is straightforward if you follow the calling conventions defined in Section 6.4 , and the register conventions defined in Section 6.3 . C/C++ code can access variables and call functions defined in assembly language, and assembly code can access C/C++ variables and call C/C++ functions. Follow these guidelines to interface assembly language and C: You must preserve any dedicated registers modified by a function. Dedicated registers include: – Save-on-entry registers (R4-R10) – Stack pointer (SP or R1) If the SP is used normally, it does not need to be explicitly preserved. In other words, the assembly function is free to use the stack as long as anything that is pushed onto the stack is popped back off before the function returns (thus preserving SP). Any register that is not dedicated can be used freely without first being saved. Interrupt routines must save all the registers they use. For more information, see Section 6.6 . When you call a C/C++ function from assembly language, load the designated registers with arguments and push the remaining arguments onto the stack as described in Section 6.4.1 . Remember that a function can alter any register not designated as being preserved without having to
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

MSP430 Optimizing C++ Compiler 6.5 - Interfacing...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online