Inline assembler


Example exchanging the values of two variables:

  byte value1 = 123;
  byte value2 = 234;
  asm   ("mov __tmp_reg__, %[var1] \n\t"
         "mov %[var1], %[var2]     \n\t"
         "mov %[var2], __tmp_reg__ \n\t"
         : [var1] "+r" (value1), [var2] "+r" (value2)  // (*)
         : 
         );
  // now you will find value1 = 234 and value2 = 123 

(*) this is where you find the values If you really want to know more about it enjoy reading the Inline Assembler Cookbook.

Note:
This example is a bad example for optimization; if you exchange two variables with an auxiliary variable the compiler will not produce any code to do it. Instead, after you do the exchange statement you find the variables addresses will be exchanged.


contact: nji(at)gmx.de