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 conventionExample 2This example shows how structures are passed on the stack. Assume that we have thefollowing declarations:struct a_struct { int a; };int a_function(struct a_struct x, int y);The calling function must reserve 4 bytes on the top of the stack and copy the contentsof the struct to that location. The integer parameter y is passed in the register R12. Thereturn value is passed back to its caller in the register R12.Example 3The function below will return a struct.struct a_struct { int a; };struct a_struct a_function(int x);It is the responsibility of the calling function to allocate a memory location—typicallyon the stack—for the return value and pass a pointer to it as a hidden first parameter. Thepointer to the location where the return value should be stored is passed in R12. Thecaller assumes that this register remains untouched. The parameter x is passed in R14.Assume that the function instead would have been declared to return a pointer to thestructure:struct a_struct * a_function(int x);In this case, the return value is a pointer, so there is no hidden parameter. The parameterx is passed in R12 and the return value is also returned in R12.FUNCTION DIRECTIVESNote: This type of directive is primarily intended to support static overlay, a featurewhich is useful in some smaller microcontrollers. The <strong>MSP430</strong> <strong>IAR</strong> C/<strong>C++</strong> <strong>Compiler</strong>does not use static overlay, because it has no use for it.The function directives FUNCTION, ARGFRAME, LOCFRAME, and FUNCALL are generatedby the <strong>MSP430</strong> <strong>IAR</strong> C/<strong>C++</strong> <strong>Compiler</strong> to pass information about functions and functioncalls to the <strong>IAR</strong> XLINK Linker. These directives can be seen if you use the compileroption Assembler file (-lA) to create an assembler list file.For <strong>reference</strong> information about the function directives, see the <strong>MSP430</strong> <strong>IAR</strong> AssemblerReference Guide.96<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!