Chapter 6. Extensions to the C Language Family
6.35. Assembler Instructions with C Expression Operands
In an assembler instruction using
sions. This means you need not guess which registers or memory locations will contain the data you
want to use.
You must specify an assembler instruction template much like what appears in a machine description,
plus an operand constraint string for each operand.
For example, here is how to use the 68881's
asm ("fsinx %1,%0" : "=f" (result) : "f" (angle));
Here
is the C expression for the input operand while
angle
Each has
as its operand constraint, saying that a floating point register is required. The
"f"
indicates that the operand is an output; all output operands' constraints must use
use the same language used in the machine description (Section 6.36 Constraints for
Each operand is described by an operand-constraint string followed by the C expression in parenthe-
ses. A colon separates the assembler template from the first output operand and another separates the
last output operand from the first input, if any. Commas separate the operands within each group. The
total number of operands is currently limited to 30; this limitation may be lifted in some future version
of GCC.
If there are no output operands but there are input operands, you must place two consecutive colons
surrounding the place where the output operands would go.
As of GCC version 3.1, it is also possible to specify input and output operands using symbolic names
which can be referenced within the assembler code. These names are specified inside square brackets
preceding the constraint string, and can be referenced inside the assembler code using
of a percentage sign followed by the operand number. Using named operands the above example could
look like:
asm ("fsinx %[angle],%[output]"
: [output] "=f" (result)
: [angle] "f" (angle));
Note that the symbolic operand names have no relation whatsoever to other C identifiers. You may
use any name you like, even those of existing C symbols, but you must ensure that no two operands
within the same assembler construct use the same symbolic name.
Output operand expressions must be lvalues; the compiler can check this. The input operands need not
be lvalues. The compiler cannot check whether the operands have data types that are reasonable for
the instruction being executed. It does not parse the assembler instruction template and does not know
what it means or even whether it is valid assembler input. The extended
used for machine instructions the compiler itself does not know exist. If the output expression cannot
be directly addressed (for example, it is a bit-field), your constraint must allow a register. In that case,
GCC will use the register as the output of the
The ordinary output operands must be write-only; GCC will assume that the values in these operands
before the instruction are dead and need not be generated. Extended asm supports input-output or
read-write operands. Use the constraint character
output operands. You should only use read-write operands when the constraints for the operand (or
the operand in which only some of the bits are to be changed) allow a register.
You may, as an alternative, logically split its function into two separate operands, one input operand
and one write-only output operand. The connection between them is expressed by constraints which
say they need to be in the same location when the instruction executes. You can use the same C
, you can specify the operands of the instruction using C expres-
asm
instruction:
fsinx
, and then store that register into the output.
asm
to indicate such an operand and list it with the
+
is that of the output operand.
result
=
feature is most often
asm
173
in
=
=f
. The constraints
Operands).
asm
instead
%[
]
name
Need help?
Do you have a question about the ENTERPRISE LINUX 4 and is the answer not in the manual?