So I'm reading Computer Systems: A Programmer's Perspective 3rd ed. and for one of the practice problem solutions it says that the following function:
long shift(long x, long n)
{
x <<= 4;
x >>= n;
return x;
}
outputs assembly code, a portion of which will be (with their comments):
# x in %rdi, n in %rsi
movq %rdi, %rax # Get x
salq $4, %rax # x <<= 4
movl %esi, %ecx # Get n (4 bytes) **QUESTION**
sarq %cl, %rax # x >>= n
Assuming x86-64 linux based, with 'long' being quad-word size.
My question is about the line where I added 'QUESTION'. Why isn't that line 'movq %rsi, %rcx', since n is type 'long'? I don't think it's a typo since they specifically added 'Get n (4 bytes)'.