2

Let's say I have a number in binary. 1010 which is 10 in decimal.

I understand that shifting left by 1 bit is essentially multiplying the number by 2.

Theres a line in a textbook that's got me confused.

salq %cl, %rdx

%rdx is a number and %salq is a left shift. What I'm confused about is the %cl.

I've read that CL is 8 bits, does that mean I'm multiplying by 2^8?

UnseededAndroid
  • 407
  • 2
  • 6
  • 14

2 Answers2

3

The cl partial register (which is really the lowest 8 bits of the register rcx) contains the value by which rdx will be shifted left. It's eight bits long, but the amount shifted is whatever is actually in there:

movb $10, %cl
salq %cl, %rdx ; rdx is shifted 10 bits left.
Govind Parmar
  • 18,500
  • 6
  • 49
  • 78
  • 1
    It's not a "pseudo"-register. It's 100% a real register, but yes it aliases the low byte of RCX. Maybe the term you're looking for is "partial register", as in [Why doesn't GCC use partial registers?](https://stackoverflow.com/q/41573502). – Peter Cordes Oct 10 '18 at 20:19
  • Updated my answer. – Govind Parmar Oct 10 '18 at 20:24
1

CL is the shift count. In C, it's rdx <<= cl, or rdx = rdx << cl. http://felixcloutier.com/x86/SAL:SAR:SHL:SHR.html.

Or more precisely, rdx <<= (cl&63), because x86 masks shift counts.


You're multiplying RDX by 2^cl.

8 is the bit width of CL, meaning it can represent values from 0..255.

Peter Cordes
  • 245,674
  • 35
  • 423
  • 606