Microchip Technology SW006022-2N Scheda Tecnica

Pagina di 338
Mixing C and Assembly Code
 2012 Microchip Technology Inc.
DS52071B-page 191
EXAMPLE 13-2: 
CALLING AN ASSEMBLY FUNCTION IN C
/*
** file: call1.c
*/
extern int asmFunction(int, int);
int x;
void
main(void)
{
  x = asmFunction(0x100, 0x200);
}
The assembly-language function sums its two parameters and returns the result.
;
; file: call2.s
;
  .global _asmFunction
_asmFunction:
  add w0,w1,w0
  return
 .end
Parameter passing in C is detailed in Section 10.8.2 “Return Value”. In the preceding 
example, the two integer arguments are passed in the W0 and W1 registers. The 
integer return result is transferred via register W0. More complicated parameter lists 
may require different registers and care should be taken in the hand-written assembly 
to follow the guidelines.