ARM VERSION 1.2 Guide de l'utilisateur Page 32

  • 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 31
4 Mixing C, C++, and Assembly Language
This chapter describes how to write mixed C, C++, and ARM assembly language code. It also describes how to use
the ARM inline assemblers from C and C++. It contains the following sections:
Using the inline assemblers
Accessing C global variables from assembly code
Using C header files from C++
Calling between C, C++, and ARM assembly language.
4.1 Using the inline assemblers
The inline assembler built into the C and C++ compilers enables you to features of the target processor that cannot
be accessed directly from C. For example:
saturating arithmetic (see Assembler Guide)
custom coprocessors
the PSR.
The inline assembler supports very flexible interworking with C and C++. Any register operand can be an arbitrary C
or C++ expression. The inline assembler also expands complex instructions and optimizes the assembly language
code.
Note
Inline assembly language is subject to optimization by the compiler if optimization is enabled either by default or with
the -O1 or -O2 compiler options.
The armcc and armcpp inline assemblers implement most of the ARM instruction set including generic coprocessor
instructions, halfword instructions and long multiply. The tcc and tcpp inline assemblers implement, again with two
exceptions, the full Thumb instruction set.
Note
The tcc and tcpp inline assemblers are deprecated and will not be supported in future releases of the tools.
See Differences between the inline assemblers and armasm for information on restrictions.
The inline assembler is a high-level assembler. The code it generates is not always exactly what you write. Do not
use it to generate more efficient code than the compiler generates. Use the ARM assembler armasm for this
purpose.
Some low-level features that are available to the ARM assembler armasm, such as branching by writing to pc, are
not supported.
4.1.1 Invoking the inline assembler
The ARM C compilers support inline assembly language with the __asm specifier.
The ARM C++ compilers support the asm syntax proposed in the ANSI C++ Standard, with the restriction that the
string literal must be a single string. For example:
asm("instruction[;instruction]");
The asm syntax is supported by the C++ compilers when compiling both C and C++. The asm statement must be
inside a C or C++ function. Do not include comments in the string literal. An asm statement can be used anywhere a
C or C++ statement is expected.
In addition to the asm syntax, ARM C++ supports the C compiler __asm syntax.
The inline assembler is invoked with the assembler specifier. The specifier is followed by a list of assembler
instructions inside braces. For example:
__asm
{
instruction [; instruction]
...
[instruction]
}
If two instructions are on the same line, you must separate them with a semicolon. If an instruction is on multiple
lines, line continuation must be specified with the backslash character (\). C or C++ comments can be used
anywhere within an inline assembly language block.
Mixing C, C++, and Assembly Language
Copyright ?1999 2001 ARM Limited 4-1
Vue de la page 31
1 2 ... 27 28 29 30 31 32 33 34 35 36 37 ... 132 133

Commentaires sur ces manuels

Pas de commentaire