For developers writing assembly code, the most noticeable part of an ABI is the calling convention. Full specification of the calling convention is very detailed (see MSP430 Embedded Application Binary Interface), but developers writing assembly do not typically use most of it. There are three basic differences between MSPGCC and the GCC compiler for MSP in the calling convention that are important to be aware of:
- In MSPGCC, registers are passed starting with R15 and descending to R12. For example, if two integers are passed, the first is passed in R15 and the second is passed in R14. In contrast, the MSP430 EABI specifies that arguments are passed beginning with R12 and moving up to R15. So, in the same situation, registers R12 and R13 would hold the two arguments. In both cases, after the registers R12 through R15 are used, continued arguments are passed on the stack. If you are using stack-based arguments, you should consult the EABI specification.
- MSPGCC and the GCC compiler for MSP use different registers for the return value. MSPGCC places the return value in R15 (or R15 and consecutive lower registers if the value is larger than a word), while the EABI specifies that the return value is placed in R12.
- In MSPGCC, register R11 is considered a save on entry register and needs to be saved and restored by the callee if it is used in the called function. Conversely, the MSP EABI specifies that R11 is a save on call register, so it needs to be saved and restored by the calling function if its value will be needed after a function call. For comparison purposes, R4 to R10 are save on entry registers for both compilers, and R12 to R15 are save on call.
These are the key differences to be aware of when moving between the compilers. If you are writing assembly code that passes parameters on the stack or that passes structures by value, you should consult the MSP EABI document for additional information.