加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 创业 > C语言 > 正文

IA-32算术移位与逻辑移位

发布时间:2020-12-15 00:45:28 所属栏目:C语言 来源:网络整理
导读:IA-32 算术左移 (SAL) 与逻辑左移 (SHL) 指令执行相同的操作;它们将目标操作数中的位向左(朝向更高有效位的位置)移位。对于每个移位计数,目标操作数的最高有效位将移入 CF 标志,最低有效位将被清除(请参阅“IA-32 英特尔(R) 体系结构软件开发人员手册

IA-32

算术左移 (SAL) 与逻辑左移 (SHL) 指令执行相同的操作;它们将目标操作数中的位向左(朝向更高有效位的位置)移位。对于每个移位计数,目标操作数的最高有效位将移入 CF 标志,最低有效位将被清除(请参阅“IA-32 英特尔(R) 体系结构软件开发人员手册”第 1 卷的“图 6-6”)。

算术右移 (SAR) 与逻辑右移 (SHR) 指令将目标操作数的位向右(朝向更低有效位的位置)移位。对于每个移位计数,目标操作数的最低有效位将移入 CF 标志,根据指令类型,最高有效位将设置为 1 或清除为 0。SHR 指令清除最高有效位(请参阅“IA-32 英特尔(R) 体系结构软件开发人员手册”第 1 卷的“图 6-7”);根据目标操作数中原始值的符号(最高有效位),SAR 指令将设置或清除最高有效位。实际上,SAR 指令使用移位之前的值的符号来填充移位之后的值的空位(请参阅“IA-32 英特尔(R) 体系结构软件开发人员手册”第 1 卷的“图 6-8”)。

c中的右移

摘抄自c语言标准草案N15706.5.7 Bitwise shift operators小节。

The integer promotions are performed on each of the operands. The type of the result is that of the promoted left operand. If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand,the behavior is undefined

对所有的操作数会进行整数提升,结果的类型取决于左操作数,如果右操作数为负或者大于等于左操作数的宽度,行为未定义。

The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are filled with zeros. If E1 has an unsigned type,the value of the result is E1 × 2E2,reduced modulo one more than the maximum value representable in the result type. If E1 has a signed type and nonnegative value,and E1 × 2E2 is representable in the result type,then that is the resulting value; otherwise,the behavior is undefined.

E1 << E2的结果是 E1左移 E2个位,空出的位填充 0,如果 E1是无符号类型,结果即是 E1 x 2E2,超过最大值的结果将会被截断,如果 E1是有符号非负类型,结果将是
E1 x 2E2,否则,行为未定义。

The result of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has an unsigned type or if E1 has a signed type and a nonnegative value,the value of the result is the integral part of the quotient of E1 / 2E2. If E1 has a signed type and a negative value,the resulting value is implementation-defined.

E1 >> E2的结果是 E1右移 E2个位,如果 E1是无符号类型或者 E1是有符号非负类型,结果是 E1 / 2E2的结果的整数部分,如果 E1是有符号负数,结果是实现定义的。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读