I'm curious about the parameter passing procedure in the x86-64 environment and therefore I wrote a snippet of code.
//a.c
extern int shared;
int main(){
int a=100;
swap(&a, &shared);
}
//b.c
int shared=1;
void swap(int* a, int* b){
*a ^= *b ^= *a ^= *b;
}
I compile two files using the following commands:
gcc -c -fno-stack-protector a.c b.c
Then I objdump -d a.o to check a.o's disassembly code.
Disassembly of section .text:
0000000000000000 <main>:
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: 48 83 ec 10 sub $0x10,%rsp
8: c7 45 fc 64 00 00 00 movl $0x64,-0x4(%rbp)
f: 48 8d 45 fc lea -0x4(%rbp),%rax
13: be 00 00 00 00 mov $0x0,%esi
18: 48 89 c7 mov %rax,%rdi
1b: b8 00 00 00 00 mov $0x0,%eax
20: e8 00 00 00 00 callq 25 <main+0x25>
25: b8 00 00 00 00 mov $0x0,%eax
2a: c9 leaveq
2b: c3 retq
Due to my working environment is Ubuntu 16.04 x86-64, I found it hard to understand the order of passing parameter.
In my point of view, the default call convention is fastcall here and therefore the parameters are passed from right to left.
I know from the x86-64 System V ABI manual that rdi and rsi are used for passing the first two parameters 
However, according to the disassembly code, rdi is responsible for var a, which is the param on the left, meaning it should be the second param.
Could someone help me point out my mistake?