11.07.2015 Views

MSP430 IAR C/C++ Compiler reference guide - Rice University

MSP430 IAR C/C++ Compiler reference guide - Rice University

MSP430 IAR C/C++ Compiler reference guide - Rice University

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Calling conventionPreserved registersPreserved registers, on the other hand, are preserved across function calls. The calledfunction may use the register for other purposes, but must save the value prior to use andrestore it at the exit of the function.The registers R4 to R11 are preserved registers.If the registers R11:R10:R9:R8 are used for passing a 64-bit scalar parameter, they donot have to be preserved.Note:● When compiling for the <strong>MSP430</strong>X architecture in the Small data model, only thelower 16 bits of the registers are preserved, unless the __save_reg20 attributeis specified. It is only necessary to save and restore the upper 4 bits of you havean assembler routine that uses these bits● When compiling using the options --lock_r4 or --lock_r5, the R4 and R5registers are not used.Special registersYou must consider that the stack pointer register must at all times point to the lastelement on the stack or below. In the eventuality of an interrupt, which can occur at anytime, everything below the point the stack pointer points to, will be destroyed.FUNCTION ENTRANCEParameters can be passed to a function using one of two basic methods: in registers oron the stack. It is much more efficient to use registers than to take a detour via memory,so the calling convention is designed to utilize registers as much as possible. There isonly a limited number of registers that can be used for passing parameters; when nomore registers are available, the remaining parameters are passed on the stack. Inaddition, the parameters are passed on the stack in the following cases:● Structure types: struct, union, and classes● Unnamed parameters to variable length functions; in other words, functionsdeclared as foo(param1, ...), for example printf.Note: Interrupt functions cannot take any parameters.Hidden parametersIn addition to the parameters visible in a function declaration and definition, there canbe hidden parameters:●If the function returns a structure, the memory location where to store the structureis passed in the register R12 as a hidden parameter.92<strong>MSP430</strong> <strong>IAR</strong> C/<strong>C++</strong> <strong>Compiler</strong>Reference Guide

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!