I'm writing a compiler and I'm trying to implement a C interface. So, I wrote a simple C program and saw the assembly code generated by GCC:
...
mov rdi, rax
call puts@PL
....
I was expecting C to pass arguments to puts
through the stack, but it uses the di
register to do so. I tested other libc
's functions such as sleep
and calloc
and they all use registers as well.
So, is there a pattern for this? i.e. Do all libc
's functions receive arguments like syscalls?
And, where does C use the stack for function arguments? Is it only for user defined functions?