Argument Passing

The same calling convention is used for a fixed as well as a variable number of arguments:

The actual passing order is from right to left (that is, the first argument pushed is the rightmost one).

The following example demonstrates argument passing for a simple function with a fixed number of arguments:

Listing: Argument Passing for Simple Function with Fixed Number of Arguments
void func(char a, char b, int c, long d, long e)
{

g1 = a;

g2 = b;

g3 = c;

g4 = d;

g5 = e;

}

...

void main(void)

{

...

func(0x12, 0x34, 0x5678, 0x1234ABCD, 0x5678ABCD);

...

}

Assuming inlining has been turned off, the compiler generates code as listed below:

Listing: Compiler Output when Inlining is Turned Off
29:   func(0x12, 0x34, 0x5678, 0x1234ABCD, 0x5678ABCD);
LD        D6,#1450748877

PSH       D6

LD        D0,#52

PSH       D0

LD        D6,#305441741

LD        D2,#22136

LD        D0,#18

JSR       func