I am learning x86-64 assembly and one thing that's confusing me is argument passing. from what i have understood till now that in case of normal function calls the arguments are pushed on stack by the callie function and accessed by the called function through an offset from the base pointer And In case of a system call the argument is passed by using registers such as rdi , rsi etc. but when i try to look at the assemble code of following code snippet
#include <stdio.h>
#include <stdlib.h>
int by12(int);
int main(void)
{
int x = 2;
int y = by12(x);
printf("%d\n",y);
return 0;
}
int by12(int a)
{
return a*12;
}
then the assembly result is
by12:
.LFB39:
.cfi_startproc
leal (%rdi,%rdi,2), %edx
leal 0(,%rdx,4), %eax
ret
main:
.LFB38:
.cfi_startproc
subq $8, %rsp
.cfi_def_cfa_offset 16
movl $2, %edi
call by12
movl %eax, %edx
movl $.LC0, %esi
movl $1, %edi
movl $0, %eax
call __printf_chk
movl $0, %eax
addq $8, %rsp
i am not able to understand why the generated assembly code uses rdi register instead of using an stack base offset ? edit- i saw the stack based method in this answer