Assembler code

Assembler code can be included in C code using the __asm__ directive. The syntax of this extension mimics gcc's __asm__ extension.
void f()
{
  __asm__("mylabel") ;
  __asm__("\tmovlw 0\n"
          "\tmovwf INDF0,0"
         ) ;
}

__asm__ directive does not insert leading blank, so you can use it to insert labels. On the other hand, a trailing newline is automatically appended to asm code.

Prior version 0.7.3, the inserted code had to leave the stack pointer (FSR0) unchanged. The violation of this rule made the compiler unable to access the local variables properly.

However, this limitation is now removed: it is possible to specify that the inserted code changes the stack pointer, so the compiler is not fooled anymore. The following code shows how to use __asm__() with an extra parameter that gives the number of byte pushed on to the stack.

int g()
{
  int a,b,c ;
  // ...
  __asm__("\tmovff PRODL,PREINC0", 1) ; // one byte pushed on to the stack
  __asm__("\tmovff PRODH,PREINC0", 1) ; // one more  byte pushed on to the stack
  a = b+c ;  // a, b and c are properly accessed
  __asm__("\tmovff POSTDEC0,PRODH" ) ; 
  __asm__("\tmovff POSTDEC0,PRODL", -2)) ; // two bytes popped 
  return a ;
}

This feature allows the user to insert a more sophisticated assembler code in C code.



Alain Gibaud 2015-07-09