将某些程序集转换为 VB.NET - SHR 运算符的工作方式不同吗?
好吧,这里有一个简单的问题,
我正在研究一些汇编,并将一些汇编例程转换回 VB.NET
现在,有一行特定的代码我遇到了麻烦,在汇编中,假设以下内容:
EBX = F0D04080
然后执行以下行
SHR EBX, 4
这给了我以下内容:
EBX = 0F0D0408
现在,在 VB.NET 中,我执行以下操作
variable = variable >> 4
哪个应该给我相同的...但它略有不同,而不是值 0F0D0408 我得到 FF0D0408
那么这里发生了什么?
Well, a simple question here
I am studying some assembly, and converting some assembly routines back to VB.NET
Now, There is a specific line of code I am having trouble with, in assembly, assume the following:
EBX = F0D04080
Then the following line gets executed
SHR EBX, 4
Which gives me the following:
EBX = 0F0D0408
Now, in VB.NET, i do the following
variable = variable >> 4
Which SHOULD give me the same... But it differs a SLIGHT bit, instead of the value 0F0D0408 I get FF0D0408
So what is happening here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 >> 的文档中运算符:
如果您使用有符号数据类型,则
F0B04080
具有负号(开头的位1
),该负号将被复制到左侧空出的位置。顺便说一句,这不是 VB.NET 特有的东西:
variable >>> 4
被转换为 IL指令shr
,它是一个“算术移位”并保留符号,与 x86 汇编指令SHR
不同,它是一个无符号移位。要在 x86 汇编器中进行算术移位,可以使用 SAR。要在 VB.NET 中使用无符号移位,您需要使用无符号变量:
F0D04080
末尾的UI
类型字符 告诉 VB.NET 该文字是一个无符号整数(否则,它将被解释为负符号整数)并且赋值会导致编译时错误)。From the documentation of the >> operator:
If you are using a signed data type,
F0B04080
has a negative sign (bit1
at the start), which is copied to the vacated positions on the left.This is not something specific to VB.NET, by the way:
variable >> 4
is translated to the IL instructionshr
, which is an "arithmetic shift" and preserves the sign, in contrast to the x86 assembly instructionSHR
, which is an unsigned shift. To do an arithmetic shift in x86 assembler,SAR
can be used.To use an unsigned shift in VB.NET, you need to use an unsigned variable:
The
UI
type character at the end ofF0D04080
tells VB.NET that the literal is an unsigned integer (otherwise, it would be interpreted as a negative signed integer and the assignment would result in a compile-time error).VB 的
>>
运算符执行算术移位,即移位符号位而不是 0。应该给你一个等价的值,即使它有点长。或者,您可以使用无符号整数(UInteger 或 UInt32),因为没有符号位需要移动。
VB's
>>
operator does an arithmetic shift, which shifts in the sign bit rather than 0's.should give you an equivalent value, even if it is a bit long. Alternatively, you could use an unsigned integer (UInteger or UInt32), as there's no sign bit to shift.