Intel 移位指令的陷阱(转)
2018-06-18 03:53:04来源:未知 阅读 ()
今天发现了一个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 0; }
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
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:哈希表开散列法(拉链法)
下一篇:如何使用C语言的面向对象
- C++ 在名称空间中使用using声明和using编译指令 2020-05-29
- usb口打印机的指令打印和驱动打印 2019-08-16
- 实验1 查看CPU和内存,用机器指令和汇编指令编程 2018-10-06
- [日常] 算法-旋转字符串-暴力移位法 2018-06-18
- [.NET逆向] .net IL 指令速查(net破解必备) 2018-06-18
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash