Whole document tree
4.32 Assembler Instructions with C Expression Operands
In an assembler instruction using 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
Here Each operand is described by an operand-constraint string followed by the C expression in parentheses. 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 limited to ten or to the maximum number of operands in any instruction pattern in the machine description, whichever is greater. 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.
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 The ordinary output operands must be write-only; GNU CC 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 `+' to indicate such an operand and list it with the output operands.
When the constraints for the read-write operand (or the operand in which
only some of the bits are to be changed) allows 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
expression for both operands, or different expressions. For example,
here we write the (fictitious) `combine' instruction with
The constraint `"0"' for operand 1 says that it must occupy the same location as operand 0. A digit in constraint is allowed only in an input operand and it must refer to an output operand.
Only a digit in the constraint can guarantee that one operand will be in
the same place as another. The mere fact that
Various optimizations or reloading could cause operands 0 and 1 to be in
different registers; GNU CC knows no reason not to do so. For example, the
compiler might find a copy of the value of Some instructions clobber specific hard registers. To describe this, write a third colon after the input operands, followed by the names of the clobbered hard registers (given as strings). Here is a realistic example for the VAX:
It is an error for a clobber description to overlap an input or output
operand (for example, an operand describing a register class with one
member, mentioned in the clobber list). Most notably, it is invalid to
describe that an input operand is modified, but unused as output. It has
to be specified as an input and output operand anyway. Note that if there
are only unused output operands, you will then also need to specify
If you refer to a particular hardware register from the assembler code, you will probably have to list the register after the third colon to tell the compiler the register's value is modified. In some assemblers, the register names begin with `%'; to produce one `%' in the assembler code, you must write `%%' in the input. If your assembler instruction can alter the condition code register, add `cc' to the list of clobbered registers. GNU CC on some machines represents the condition codes as a specific hardware register; `cc' serves to name this register. On other machines, the condition code is handled differently, and specifying `cc' has no effect. But it is valid no matter what the machine. If your assembler instruction modifies memory in an unpredictable fashion, add `memory' to the list of clobbered registers. This will cause GNU CC to not keep memory values cached in registers across the assembler instruction.
You can put multiple assembler instructions together in a single
Unless an output operand has the `&' constraint modifier, GNU CC may allocate it in the same register as an unrelated input operand, on the assumption the inputs are consumed before the outputs are produced. This assumption may be false if the assembler code actually consists of more than one instruction. In such a case, use `&' for each output operand that may not overlap an input. See section 4.33.3 Constraint Modifier Characters.
If you want to test the condition code produced by an assembler
instruction, you must include a branch and a label in the
This assumes your assembler supports local labels, as the GNU assembler and most Unix assemblers do.
Speaking of labels, jumps from one
Usually the most convenient way to use these
Here the variable
Another way to make sure the instruction operates on the correct data
type is to use a cast in the
If an
You can prevent an
If you write an
An
Note that even a volatile It is a natural idea to look for a way to give access to the condition code left by the assembler instruction. However, when we attempted to implement this, we found no way to make it work reliably. The problem is that output operands might need reloading, which would result in additional following "store" instructions. On most machines, these instructions would alter the condition code before there was time to test it. This problem doesn't arise for ordinary "test" and "compare" instructions because they don't have any output operands.
If you are writing a header file that should be includable in ANSI C
programs, write
This document was generated by root on January, 30 2002 using texi2html |