A doubt on calling convention of C

Started by Manish Aggarwal, September 12, 2015, 03:16:06 AM

Previous topic - Next topic

Manish Aggarwal

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 ) ;
}

TimoVJL

#1
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[40101B] push dword ptr [l]
[40101E] push dword ptr [a]
[401021] push dword ptr [i]
[401024] call pass
May the source be with you

Manish Aggarwal

hmmm.............Got that.........
Thanks Sir :)