Examples of inline assembly statements

In the following example:

int a ;  
int b = 100 ;  
int c = 200 ;  
	asm("add %0, %1, %2"
	      : "=r"(a)  
	      : "r"(b) , "r"(c) 

is the op code of the instruction, understood by the assembler. %0, %1 and %2 are the operands, which are to be substituted by the C expressions in the output/input operand fields. The output operand uses the = constraint to indicate that a modifiable operand is required; and the r constraint to indicate that a general purpose register is required. Likewise, the r in the input operands indicates that general purpose registers are required. Within these restrictions, the compiler is free to choose any registers to substitute for %0, %1, and %2.

The following example illustrates the use of the symbolic names for input and output operands:

int a ;  
int b = 1, c = 2, d = 3 ;  
__asm("addc %[result],%[first],%[second]"  
             :[first]"r"(b), [second]"r"(d) );