ARM VERSION 1.2 Guide de l'utilisateur Page 45

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 133
  • Table des matières
  • DEPANNAGE
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 44
int f() {
S s(2); // initialize 's'
asmfunc(&s); // call 'asmfunc' so it
// can change 's'
return s.i * 3;
}
Example 4-16 Defining the assembly language function
AREA Asm, CODE
EXPORT asmfunc
asmfunc ; the definition of the Asm
LDR r1, [r0] ; function to be called from C++
ADD r1, r1, #5
STR r1, [r0]
MOV pc, lr
END
Calling C++ from C
Example 4-17 and Example 4-18 show how to call C++ from C.
Example 4-17 Defining the function to be called in C++
struct S { // has no base classes or virtual functions
S(int s) : i(s) { }
int i;
};
extern "C" void cppfunc(S *p) {
// Definition of the C++ function to be called from C.
// The function is written in C++, only the linkage is C
p->i += 5; //
}
Example 4-18 Declaring and calling the function in C
struct S {
int i;
};
extern void cppfunc(struct S *p);
/* Declaration of the C++ function to be called from C */
int f(void) {
struct S s;
s.i = 2; /* initialize 's' */
cppfunc(&s); /* call 'cppfunc' so it */
/* can change 's' */
return s.i * 3;
}
Calling C++ from assembly language
Example 4-19 and Example 4-20 show how to call C++ from assembly language.
Example 4-19 Defining the function to be called in C++
struct S { // has no base classes or virtual functions
S(int s) : i(s) { }
int i;
};
extern "C" void cppfunc(S * p) {
// Definition of the C++ function to be called from ASM.
// The body is C++, only the linkage is C
p->i += 5;
}
In ARM assembly language, import the name of the C++ function and use a Branch with link instruction to call it:
Example 4-20 Defining assembly language function
AREA Asm, CODE
IMPORT cppfunc ; import the name of the C++
; function to be called from Asm
EXPORT f
Mixing C, C++, and Assembly Language
Copyright ?1999 2001 ARM Limited 4-14
Vue de la page 44
1 2 ... 40 41 42 43 44 45 46 47 48 49 50 ... 132 133

Commentaires sur ces manuels

Pas de commentaire