Header Ads Widget

Ticker

6/recent/ticker-posts

Function calling convention

 4.4. Function calling convention:

1. Parameters might be passed from left to right.

2. Parameters might be passed from right to left.

In ‘C’ parameters passed from right to left.

A function call to finding maximum number between three numbers is shown in below example:

r = max (j, k, l);

The corresponding assembler code for the call would be something like:

PUSH l

PUSH k

PUSH j

CALL max

Here parameters are passed from right to left direction.

Most of time parameters are passed from left to right or from right to left is doesn’t matter, but in some cases order of passing parameter becomes an important thing shown in following example:

Example:

int x =10;

printf(“%d %d %d”, x, --x, x--);

Here, output is 8 8 10. Because here arguments are passed from right to left otherwise output will be sometime different.

Post a Comment

0 Comments