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.

Assembler language interfaceThis means that the function takes two parameters: an integer and a pointer to acharacter. The function returns a value, an integer.In the general case, this is the only knowledge that the compiler has about a function.Therefore, it must be able to deduce the calling convention from this information.USING C LINKAGE IN <strong>C++</strong> SOURCE CODEIn <strong>C++</strong>, a function can have either C or <strong>C++</strong> linkage. To call assembler routines from<strong>C++</strong>, it is easiest if you make the <strong>C++</strong> function have C linkage.The following is an example of a declaration of a function with C linkage:extern "C"{int f(int);}It is often practical to share header files between C and <strong>C++</strong>. The following is anexample of a declaration that declares a function with C linkage in both C and <strong>C++</strong>:#ifdef __cplusplusextern "C"{#endifint f(int);#ifdef __cplusplus}#endifPRESERVED VERSUS SCRATCH REGISTERSThe general <strong>MSP430</strong> CPU registers are divided into three separate sets, which aredescribed in this section.Scratch registersAny function may destroy the contents of a scratch register. If a function needs theregister value after a call to another function, it must store it during the call, for exampleon the stack.Any of the registers R12 to R15, as well as the return address registers, are consideredscratch registers and can be used by the function.When the registers R11:R10:R9:R8 are used for passing a 64-bit scalar parameter, theyare also considered to be scratch registers.Part 1. Using the compiler91

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

Saved successfully!

Ooh no, something went wrong!