I have started to learn assembly language and immediately stumbled upon arguments passing. Every tutorial I've seen on the web (example: http://www.delorie.com/djgpp/doc/ug/asm/calling.html) explains arguments passing to functions as pushing them to the stack. However, when I started experimenting, it is quite clear this is not the case. For the simple function
int foo(int a, int b) {
return a + b;
}
Following asm is generated (compiled on AMD64 with gcc):
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
movl -8(%rbp), %eax
movl -4(%rbp), %edx
leal (%rdx,%rax), %eax
It is quite clear arguments are passed in EDI and ESI registers. As I add more argument to the function, I see more registers are used, and only after I reach 6 arguments I start to see values actually read from the stack. Yet googling EDI/ESI registers gives me no explanation of their special role in arguments passing. What am I missing here?