There are already a few sites out there with this info, but I thought I would try and create something that is a little more complete (I hope).

Inline ASM coding allows assembly language coding to be inserted directly into C++ files. This will be shown in a general form using with the GNU compiler.

General form:
  asm("statements;" [ : output_list [ : input_list : [ clobber_list ]]]); 

"statements;" - the statements should be a list of assembly language mnemonics each terminated with a semi-colon ';'. You can put multi-mnemonics on one line inside of one set of double-quotes, or place each in its own set of double-quotes.
output_list - this is a list of variables that are outputed by the set of statements.

Output general form :
  "=x" (variablename), ...

Where 'x' could be:
  m = memory variable (stack argument, local variable)
  g = general purpose register (eax, ebx, ecx, edx or variable in memory)
  a = eax
  b = ebx
  c = ecx
  d = edx
  S = esi
  D = edi
  I = constant value (0 to 31)
  q,r = dynamically allocated register
  A = eax and edx combined into a 64-bit integer (use long longs)
input_list - this is a list of variables that are needed in the statements.

Input general form :
  "x" (variablename), ...
Where 'x' is the same as in the output list.

clobber_list - this is a list of registers that are used by the statements (so the compiler will not store variables in them across the statements).

Clobber general form :
  (registername), ...


To reference the input and output lists from the statements, you must use %0, %1, %2, etc. Numbered thru the output list first, and then continuing in the input list.
To use registers you must prefix them with '%%'.
To use immediate values you must prefix them with '$'.
The coding style is AT&T style which means in 2 operand forms, the source is first and the destination is second.
You do not have to list output registers in the clobber list, they are assumed to be clobbered (although it doesn't hurt).
The assembler may need help in determining operand sizes (and its guesses are often wrong) so you need a suffix on the mnemonic as follows:
  b = byte (8bit)
  w = word (16bit)
  l = long (32bit integer) (64bit double)
  q = qword (64bit integer)


void ex1() {
  asm("mov %%eax,%%ebx;" : : "ebx");  //moves eax into ebx (ebx is therefore clobbered)
int strlen(char *s) {
  int ret;
    "movl %1,%%edi;"  //'l' suffix overrides size to 32bits
    "xor %%al,%%al;"
    "xor %%ecx,%%ecx;"
    "dec %%ecx;
    "repnz scasb;"
    "neg %%ecx;"
    "dec %%ecx;"
    "dec %%ecx;"
    "mov %%ecx,%0;"
      :"=g" (ret)        //outputs (%0)
      :"m" (s)           //inputs (%1)
      :"edi","al","ecx"  //clobbers
  return ret;
Author : Peter Quiring
Reference : DJGPP Guide to inline ASM coding