Intel 移位指令的陷阱(转)
今天发现了一个Intel逻辑左移指令shl的一个bug。
#include <stdio.h>
int main()
{
#define MOVE_CONSTANT_BITS 32
unsigned int move_step=MOVE_CONSTANT_BITS;
unsigned int value1 = 1ul << MOVE_CONSTANT_BITS;
printf("value1 is 0x%X\n", value1);
unsigned int value2 = 1ul << move_step;
printf("value2 is 0x%X\n", value2);
return ;
}
test.c: In function ‘main’:
test.c:8: warning: left shift count >= width of type
value1 is 0x0
value2 is 0x1
- Dump of assembler code for function main:
- 0x080483c4 <main+0>: push %ebp
- 0x080483c5 <main+1>: mov %esp,%ebp
- 0x080483c7 <main+3>: and $0xfffffff0,%esp
- 0x080483ca <main+6>: push %ebx
- 0x080483cb <main+7>: sub $0x2c,%esp
- 0x080483ce <main+10>: movl $0x20,0x14(%esp)
- 0x080483d6 <main+18>: movl $0x0,0x18(%esp)
- 0x080483de <main+26>: mov $0x80484f4,%eax
- 0x080483e3 <main+31>: mov 0x18(%esp),%edx
- 0x080483e7 <main+35>: mov %edx,0x4(%esp)
- 0x080483eb <main+39>: mov %eax,(%esp)
- 0x080483ee <main+42>: call 0x80482f4<printf@plt>
- 0x080483f3 <main+47>: mov 0x14(%esp),%eax
- 0x080483f7 <main+51>: mov $0x1,%edx
- 0x080483fc <main+56>: mov %edx,%ebx
- 0x080483fe <main+58>: mov %eax,%ecx
- 0x08048400 <main+60>: shl %cl,%ebx
- 0x08048402 <main+62>: mov %ebx,%eax
- 0x08048404 <main+64>: mov %eax,0x1c(%esp)
- 0x08048408 <main+68>: mov $0x8048504,%eax
- 0x0804840d <main+73>: mov 0x1c(%esp),%edx
- 0x08048411 <main+77>: mov %edx,0x4(%esp)
- 0x08048415 <main+81>: mov %eax,(%esp)
- 0x08048418 <main+84>: call 0x80482f4<printf@plt>
- 0x0804841d <main+89>: mov $0x0,%eax
- 0x08048422 <main+94>: add $0x2c,%esp
- 0x08048425 <main+97>: pop %ebx
- 0x08048426 <main+98>: mov %ebp,%esp
- 0x08048428 <main+100>: pop %ebp
- 0x08048429 <main+101>: ret
- End of assembler dump.
Description
These instructions shift the bits in the first operand (destination operand) to the left or right by
the number of bits specified in the second operand (count operand). Bits shifted beyond the
destination operand boundary are first shifted into the CF flag, then discarded. At the end of the
shift operation, the CF flag contains the last bit shifted out of the destination operand.
The destination operand can be a register or a memory location. The count operand can be an
immediate value or register CL. The count is masked to five bits, which limits the count range
to 0 to 31. A special opcode encoding is provided for a count of 1.
转自:http://blog.chinaunix.net/uid-23629988-id-127318.html
Intel 移位指令的陷阱(转)的更多相关文章
- Linux版Matlab R2015b的bug——脚本运行的陷阱(未解决)
0 系统+软件版本 系统:CentOS 6.7 x64, 内核 2.6.32-573.el6.x86_64软件:Matlab R2015b(包括威锋网和东北大学ipv6下载的资源,都测试过) 1 脚本 ...
- Intel 80x86 Linux Kernel Interrupt(中断)、Interrupt Priority、Interrupt nesting、Prohibit Things Whthin CPU In The Interrupt Off State
目录 . 引言 . Linux 中断的概念 . 中断处理流程 . Linux 中断相关的源代码分析 . Linux 硬件中断 . Linux 软中断 . 中断优先级 . CPU在关中断状态下编程要注意 ...
- Intel微处理器学习笔记(五) 中断
▼ 中断是一个由硬件激发的过程,它中断当前正在执行的任何程序. ▼ 在Intel系列微处理器中,包括INTR和NMI(Non Maskable Interrupt)两个申请中断的引脚和一个响应INTR ...
- Intel大坑之中的一个:丢失的SSE2 128bit/64bit 位移指令,马航MH370??
缘由 近期在写一些字符串函数的优化,兴趣使然.但是写的过程中,想要实现 SSE2 128 bit / 64 bit 的按 bit 逻辑位移.遇到了一个大坑,且听我娓娓道来. 我并不想用什么马航370来 ...
- Intel大坑之一:丢失的SSE2 128bit/64bit 位移指令,马航MH370??
缘由 最近在写一些字符串函数的优化,兴趣使然,可是写的过程中,想要实现 128bit 的按 bit 逻辑位移,遇到了一个大坑,且听我娓娓道来. 如果要追究标题,更确切的是丢失的SSE2 128 bit ...
- gcc中的内嵌汇编语言(Intel i386平台)
[转]http://bbs.chinaunix.net/thread-2149855-1-1.html 一.声明 虽然Linux的核心代码大部分是用C语言编写的,但是不可避免的其中还是有一部分是用汇 ...
- 【av68676164(p55-p58)】 Intel CPU和Linux内存管理
7.4.1 Intel CPU物理结构 https://www.cnblogs.com/megachen/p/9768115.html x86实模式 实模式 20位:1M内存空间 地址表示方式:段地址 ...
- Intel汇编程序设计-整数算术指令(上)
第七章 整数算术指令 7.1 简介 每种汇编语言都有进行操作数移位的指令,移位和循环移位指令在控制硬件设备.加密数据,以及实现高速的图形操作时特别有用.本章讲述如何进行移位和循环移位操作以及如何使用移 ...
- Intel Media SDK H264 encoder GOP setting
1 I帧,P帧,B帧,IDR帧,NAL单元 I frame:帧内编码帧,又称intra picture,I 帧通常是每个 GOP(MPEG 所使用的一种视频压缩技术)的第一个帧,经过适度地压缩,做为随 ...
随机推荐
- uva10976
数学题. 1. 因为 1/k = 1/x +1/y 所以 1/k > 1/y 那么 y > k 2 . 因为 x >= y 所以 1/k - 1/y <= 1/y 那么 y & ...
- freemaker中的map遍历
前两天在freemaker中遇到一个问题,怎么遍历一个Map<List<Object>的map呢? 网上找个很多都是类似下面的: <#if map?exists> < ...
- 接口测试执行工具Postman:模拟请求、用例执行、断言、批量运行用例、简单持续集成
一.接口测试-postman-模拟HTTP Requests 二.接口测试-postman-权限Authorization 三.接口测试-postman-断言Writting Test 四.接口测试- ...
- yum源配置的三种方法
(一)yum源概述 yum需要一个yum库,也就是yum源.默认情况下,CentOS就有一个yum源.在/etc/yum.repos.d/目录下有一些默认的配置文件(可以将这些文件移到/opt下,或者 ...
- 在测试crontab执行脚本的时候,修改了linux的系统时间,crontab不执行了。
今天在写服务器的perl脚本的时候,在完成一版脚本打算通过crontab来测试一下呢,因为直接执行脚本文件是没有问题的,但是当配置到crontab定期执行时就会出现问题,到了指定的时间了,但是脚本文件 ...
- 阻止微信浏览器/QQ浏览器长按弹框“在浏览器打开”
这个弹框实际上等同于PC环境下的鼠标右键的弹框,因此只要禁止页面的弹框事件就能完美屏蔽该弹框对我们功能带来的影响.程序代码如下: document.oncontextmenu=function(e){ ...
- ubuntu下串口编程备忘
弄了一下串口,一个小问题多折腾了下,备忘.软件环境:zl@zhanglong:~$ cat /etc/lsb-release DISTRIB_ID=UbuntuDISTRIB_RELEASE=12.0 ...
- python︱字符操作杂记(split、zip...)
字符串特别是中文在python里面还是有很多需要注意的地方. . . . 一.字符串 . . 1.字符串连接 方式一:单个字符相连用 + 就可以: 方式二:list组内相连,可以用join: 方式三: ...
- C语言中的可变参数函数的浅析(以Arm 程序中的printf()函数实现为例) .
我们在C语言编程中会遇到一些参数个数可变的函数,一般人对它的实现不理解.例如Printf(): Printf()函数是C语言中非常常用的一个典型的变参数函数,它 的原型为: int printf( c ...
- Rwordseg使用
#用于下载安装rJava 和 Rwordseg,如果安装了就注释掉 install.packages("rJava") install.packages("Rwordse ...