问题描述
假设我有一个二进制数.1010 是十进制的 10.
Let's say I have a number in binary. 1010 which is 10 in decimal.
我知道左移 1 位本质上是将数字乘以 2.
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
是一个数字,%salq
是一个左移.我感到困惑的是 %cl
.
%rdx
is a number and %salq
is a left shift. What I'm confused about is the %cl
.
我读过 CL 是 8 位,这是否意味着我要乘以 2^8?
I've read that CL is 8 bits, does that mean I'm multiplying by 2^8?
推荐答案
cl
部分寄存器(实际上是寄存器 rcx
的最低 8 位)包含rdx
将左移的值.它有 8 位长,但移位的量是实际存在的:
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.
这篇关于使用 %cl 左移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!