To learn assembly I am viewing the assembly generated by GCC using the -S command for some simple C programs on Linux.
I write a C function foo.c
long shift_left4_rightn(long x, long n)
{
x <<= 4;
x >>= n;
return x;
}
When I run gcc -Og -S foo.c
I got foo.s . Below is the part about this function
shift_left4_rightn:
movq %rdi, %rax
salq $4, %rax
movl %esi, %ecx
sarq %cl, %rax
ret
The function parameter x uses the register %rdi, which is normal. What confuses me is why the other parameter n uses the register %esi instead of %rsi. What am I missing? What would happen if I replace movl %esi, %ecx with movq %rsi, %rcx.