NO

Author Topic: A doubt on calling convention of C  (Read 2247 times)

Manish Aggarwal

  • Guest
A doubt on calling convention of C
« on: September 12, 2015, 03:16:06 AM »
Basically the C language calling convention is from right to left. So I passed the values as shown. As per the convention , to what I think, b=l and j=a......but here what happens actually is b=a,j=i....Please explain this?

‪#‎include‬<stdio.h>
int pass();
int main(void)
{
int i = 135, a = 130, k,l=0 ;
k = pass ( i, a,l) ;
printf ( "\n%d\n", k ) ;
}
int pass ( int j,int b)
{
int c;
printf("b=%d",b);
printf("\nj=%d",j);
c = j + b ;
return ( c ) ;
}

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: A doubt on calling convention of C
« Reply #1 on: September 12, 2015, 08:26:14 AM »
Parameters are pushed into stack in that order. In function those are in same order.
Look https://en.wikipedia.org/wiki/X86_calling_conventions
In assembly
Code: [Select]
[40101B] push dword ptr [l]
[40101E] push dword ptr [a]
[401021] push dword ptr [i]
[401024] call pass
« Last Edit: September 12, 2015, 08:33:11 AM by TimoVJL »
May the source be with you

Manish Aggarwal

  • Guest
Re: A doubt on calling convention of C
« Reply #2 on: September 12, 2015, 08:43:51 AM »
hmmm.............Got that.........
Thanks Sir :)