Vault 7: Projects

This publication series is about specific projects related to the Vault 7 main publication.

Mixing C and Assembly Code
2012-2013 Microchip Technology Inc. DS50002071C-page 209
TABLE 16-2: CONSTRAINT MODIFIERS SUPPORTED BY THE COMPILER
Examples in this Section:
Passing C Variables
Clobbering Registers
Using Multiple Assembler Instructions
Using & to Prevent Input Register Clobbering
Matching Operands
Naming Operands
Volatile asm Statements
Handling Values Larger Than int
EXAMPLE 16-3: PASSING C VARIABLES
This example demonstrates how to use the swap instruction (which the compiler does
not generally use):
asm ("swap %0" : "+r"(var));
Here var is the C expression for the operand, which is both an input and an output
operand. The operand is constrained to be of type r, which denotes a register operand.
The + in +r indicates that the operand is both an input and output operand.
Each operand is described by an operand-constraint string that is 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 output operands and separate inputs.
If there are no output operands, but there are input operands; then, there must be two
consecutive colons surrounding the place where the output operands would go. The
compiler requires that the output operand expressions must be L-values. The input
operands need not be L-values. 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 whether
it is valid assembler input. The extended asm feature is most often used for machine
instructions that the compiler itself does not know exist. If the output expression cannot
be directly addressed (for example, it is a bit-field), the constraint must allow a register.
In that case, the compiler will use the register as the output of the asm, and then store
that register into the output. If output operands are write-only, the compiler will assume
that the values in these operands before the instruction are dead and need not be
generated.
Modifier Constraint
= Means that this operand is write-only for this instruction: the previous value is dis-
carded and replaced by output data.
+ Means that this operand is both read and written by the instruction.
& Means that this operand is an earlyclobber operand, which is modified before
the instruction is finished using the input operands. Therefore, this operand may
not lie in a register that is used as an input operand or as part of any memory
address.
d Second register for operand number n, i.e., %dn..
q Fourth register for operand number n, i.e., %qn..
t Third register for operand number n, i.e., %tn..

e-Highlighter

Click to send permalink to address bar, or right-click to copy permalink.

Un-highlight all Un-highlight selectionu Highlight selectionh