ARM VERSION 1.2 Guide de l'utilisateur Page 44

  • 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 43
2. Type armcc -c -g strtest.c to build the C source.
3. Type armlink strtest.o scopy.o -o strtest to link the object files
4. Type armsd -e strtest execute the example.
Calling C from assembly language
Example 4-11 and Example 4-12 show how to call C from assembly language.
Example 4-11 Defining the function in C
int g(int a, int b, int c, int d, int e)
{
return a + b + c + d + e;
}
Example 4-12 Assembly language call
; int f(int i) { return g(i, 2*i, 3*i, 4*i, 5*i); }
EXPORT f
AREA f, CODE, READONLY
IMPORT g ; i is in r0
STR lr, [sp, #-4]! ; preserve lr
ADD r1, r0, r0 ; compute 2*i (2nd param)
ADD r2, r1, r0 ; compute 3*i (3rd param)
ADD r3, r1, r2 ; compute 5*i
STR r3, [sp, #-4]! ; 5th param on stack
ADD r3, r1, r1 ; compute 4*i (4th param)
BL g ; branch to C function
ADD sp, sp, #4 ; remove 5th param
LDR pc, [sp], #4 ; return
END
Calling C from C++
Example 4-13 and Example 4-14 show how to call C from C++.
Example 4-13 Calling a C function from C++
struct S { // has no base classes
// or virtual functions
S(int s) : i(s) { }
int i;
};
extern "C" void cfunc(S *);
// declare the C function to be called from C++
int f(){
S s(2); // initialize 's'
cfunc(&s); // call 'cfunc' so it can change 's'
return s.i * 3;
}
Example 4-14 Defining the function in C
struct S {
int i;
};
void cfunc(struct S *p) {
/* the definition of the C function to be called from C++ */
p->i += 5;
}
Calling assembly language from C++
Example 4-15 and Example 4-16 show how to call assembly language from C++.
Example 4-15 Calling assembly language from C++
struct S { // has no base classes
// or virtual functions
S(int s) : i(s) { }
int i;
};
extern "C" void asmfunc(S *); // declare the Asm function
// to be called
Mixing C, C++, and Assembly Language
Copyright ?1999 2001 ARM Limited 4-13
Vue de la page 43
1 2 ... 39 40 41 42 43 44 45 46 47 48 49 ... 132 133

Commentaires sur ces manuels

Pas de commentaire