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...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Calling assembler routines from CInline assembler is therefore often best avoided. If there is no suitable intrinsic functionavailable, we recommend the use of modules written in assembler language instead ofinline assembler, because the function call to an assembler routine normally causes lessperformance reduction.Calling assembler routines from CAn assembler routine that is to be called from C must:●●●Conform to the calling conventionHave a PUBLIC entry-point labelBe declared as external before any call, to allow type checking and optionalpromotion of parameters, as in the following examples:extern int foo(void);orextern int foo(int i, int j);One way of fulfilling these requirements is to create skeleton code in C, compile it, andstudy the assembler list file.CREATING SKELETON CODEThe recommended way to create an assembler language routine with the correctinterface is to start with an assembler language source file created by the C compiler.Note that you must create skeleton code for each function prototype.The following example shows how to create skeleton code to which you can easily addthe functional body of the routine. The skeleton source code only needs to declare thevariables required and perform simple accesses to them. In this example, the assemblerroutine takes an int and a double, and then returns an int:extern int gInt;extern double gDouble;int func(int arg1, double arg2){int locInt = arg1;gInt = arg1;gDouble = arg2;return locInt;}86<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!