Calling Inline Assembly Language Functions

The following listing demonstrates how to create an inline assembly language function in a C source file. This example adds two 16-bit integers and returns the result.

Notice that you are passing two 16-bit addresses to the add_int function. You pick up those addresses in R2 and R3, passing the sum back in Y0.

Listing: Sample code - Creating an inline assembly language function
asm int add_int( int * i, int * j )
{
  move.w    x:(r2),y0
  move.w    x:(r3),x0
  add   x0,y0
  // int result returned in y0
  rts
}

The following listing shows the C calling statement for this inline-assembly-language function.

Listing: Sample Code - Calling an Inline Assembly Language Function
  int x = 4, y = 2; 

  y = add_int( &x, &y ); /* Returns 6 */