简体   繁体   English

x86装配右移操作员SHR的副作用?

[英]Side-effects of x86 assembly right-shift operator SHR?

I'm tracing through a program with an ASM debugger ollydbg and I come across this code snippet, which is a loop segment: 我正在使用ASM调试器ollydbg跟踪程序,我遇到了这个代码片段,这是一个循环段:

CPU Disasm
Address   Hex dump          Command                                  Comments
007D05EC  |.  33C9          XOR ECX,ECX
007D05EE  |.  8BFF          MOV EDI,EDI
007D05F0  |>  8B54B4 10     /MOV EDX,DWORD PTR SS:[ESI*4+ESP+10]
007D05F4  |.  8BFA          |MOV EDI,EDX
007D05F6  |.  0FAFFE        |IMUL EDI,ESI
007D05F9  |.  8BDA          |MOV EBX,EDX
007D05FB  |.  D3EB          |SHR EBX,CL
007D05FD  |.  03F8          |ADD EDI,EAX
007D05FF  |.  83C1 10       |ADD ECX,10
007D0602  |.  83C6 01       |ADD ESI,1
007D0605  |.  03DF          |ADD EBX,EDI
007D0607  |.  33DA          |XOR EBX,EDX
007D0609  |.  81F9 B0000000 |CMP ECX,0B0
007D060F  |.  8BC3          |MOV EAX,EBX
007D0611  |.^ 7C DD         \JL SHORT 007D05F0

I can follow and get what the other operators do and it makes sense when I trace through it. 我可以跟随并获得其他操作员所做的事情,当我追踪它时它是有意义的。 But the SHR EBX, CL doesn't make sense to me. 但SHR EBX,CL对我来说没有意义。

//Shouldn't in asm
SHR EBX, CL
//be the same as doing this in c/c++?
//that's how it read when I checked the asm reference anyway
ebx >>= CL;

But what I am seeing instead when tracing is that if the loop iteration is odd, discard the LSB and shift the MSB into it's place. 但是我在跟踪时看到的是,如果循环迭代是奇数,则丢弃LSB并将MSB移动到它的位置。 If it's even then ebx is unchanged. 如果它甚至那么ebx没有变化。 Each loop iteration, the ecx register changes as follows: 每次循环迭代,ecx寄存器更改如下:

**ecx**
0x0000  -- loop 0
0x0010  -- loop 1
0x0020  -- loop 2
..
0x00A0  -- loop 10

What I was expecting to see was after the 2nd or 3rd loop, was that ebx would always be zero'ed out because 0x20 your already shifting 32 bits. 我期待看到的是在第二个或第三个循环之后,ebx总是会被清零,因为0x20你已经移位了32位。

I'm kind of confused, can someone shed some light on this? 我有点困惑,有人可以对此有所了解吗?

Thanks 谢谢

Here's what I read from the description of the instruction: 这是我从指令描述中读到的内容:

In either case, shifts counts of greater then 31 are performed modulo 32. 在任何一种情况下,大于31的移位计数以模32执行。

Answer your question? 回答你的问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM