Atmel CAVR-4 Manual De Usuario

Descargar
Página de 323
CAVR-4
98
Calling assembler routines from C++
AVR® IAR C/C++ Compiler
Reference Guide
Calling assembler routines from C++
The C calling convention does not apply to C++ functions. Most importantly, a function 
name is not sufficient to identify a C++ function. The scope and the type of the function 
are also required to guarantee type-safe linkage, and to resolve overloading. 
Another difference is that non-static member functions get an extra, hidden argument, 
the 
this
 pointer.
However, when using C linkage, the calling convention conforms to the C calling 
convention. An assembler routine may therefore be called from C++ when declared in 
the following manner:
extern "C" 
{
  int my_routine(int x);
}
Memory access layout of non-PODs ("plain old data structures") is not defined, and may 
change between compiler versions. Therefore, we do not recommend that you access 
non-PODs from assembler routines.
To achieve the equivalent to a non-static member function, the implicit 
this
 pointer has 
to be made explicit:
class X;
extern "C" 
{
  void doit(X *ptr, int arg);
}
It is possible to “wrap” the call to the assembler routine in a member function. Using an 
inline member function removes the overhead of the extra call—provided that function 
inlining is enabled:
class X 
{
public:
  inline void doit(int arg) { ::doit(this, arg); }
}; 
Note: Support for C++ names from assembler code is extremely limited. This means 
that:
Assembler list files resulting from compiling C++ files cannot, in general, be passed 
through the assembler.
It is not possible to refer to or define C++ functions that do not have C linkage in 
assembler.