In the book Low-Level Programming: C, Assembly, and Program Execution on Intel® 64 Architecture it says,
On system call arguments The arguments for system calls are stored in a different set of registers than those for functions. The fourth argument is stored in
r10
, while a function accepts the fourth argument inrcx
!The reason is that
syscall
instruction implicitly usesrcx
. System calls cannot accept more than six arguments.
You can see this also mentioned in this Stack Overflow post,
A system-call is done via the syscall instruction. This clobbers %rcx and %r11, as well as %rax, but other registers are preserved.
I understand clobbering rax
to store the return code, but why is rcx
, and r11
clobbered in syscall
? Is there a list of the specific syscalls that clobber rcx
/r11
? Is there a convention for the clobbering? Are they assumed safe in any syscalls?