NASM移位运算符 [英] NASM shift operators
问题描述
您会如何去对一个寄存器做在NASM有点转变?我阅读手册,并似乎只提到这些运营商的>> &LT;&LT; 。当我尝试使用它们NASM抱怨移位运算符标量值工作。你能解释一个标值是什么,并给出了如何使用<强>>> 和℃的例子;&LT; 。另外,我认为有一个 SHR 或 SHL 运营商。如果他们不存在,您可以给如何使用它们的例子吗?感谢您的时间。
How would you go about doing a bit shift in NASM on a register? I read the manual and it only seems to mention these operators >>, <<. When I try to use them NASM complains about the shift operator working on scalar values. Can you explain what a scalar value is and give an example of how to use >> and <<. Also, I thought there were a shr or shl operators. If they do exist can you give an example of how to use them? Thank you for your time.
推荐答案
&LT;&LT;
和&GT;&GT;
为带有整型常量使用。这是什么意思的标值。您可以在寄存器中使用 SHL
或 SHR
指示值偏移。它们被用来的值在寄存器向左或向右移动,分别位的给定数目
<<
and >>
are for use with integer constants only. This is what it means by "scalar value". You can shift the value in a register using the shl
or shr
instructions. They are used to shift the value in a register left or right, respectively, a given number of bits.
在本实施例中的第一行中斧
向左4比特,这是相同的由16第二行乘以移动的值在<$将这个值C $ C> BX 右2位,这是一样的整数除以4。
The first line in this example shifts the value in ax
left 4 bits, which is the same as multiplying it by 16. The second line shifts the value in bx
right by 2 bits, which is the same as integer division by 4.
shl ax, 4
shr bx, 2
您也可以使用 CL
来表示的比特数转移,而不是一个常量。关于这些和相关指令的详细信息,请参阅此页面。
You can also use cl
to indicate the number of bits to shift, instead of a constant. For more information on these and related instructions, see this page.
这篇关于NASM移位运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!