为什么cmp 0x84,0x30会触发溢出标志?
我已经玩了一段时间的汇编并查看了一些代码。 其中 AL 首先设置为 0x84,然后使用 cmp AL, 0x30。 该指令然后触发溢出标志。
根据我的阅读,CMP 应该从第一个数字中减去第二个数字,然后设置标志,在这种情况下,它应该是 0x84-0x30,结果是 0x54 并且没有溢出。
I've been playing with assembly for a while and looking at some code.
in which AL is first set to 0x84 then cmp AL, 0x30 is used.
This instruction then triggers the Overflow flag.
From what I read CMP is supposed to subtract the second number from the first then set the flags, in that case it should be 0x84-0x30 the result is 0x54 and there is no overflow.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只有当您将这些值解释为无符号数字时,才不会发生溢出 - 如果您将
0x84
解释为有符号数字,则肯定会发生溢出:-172 超出了有符号 8 位值的范围(-128 到+127) 这就是设置
OF
标志的原因。您应该检查CF
,它指示无符号溢出。来自 Intel 64 和 IA-32 CMP 架构软件开发人员手册,第 2 卷:
对于SUB:
There's only no overflow if you're interpret those values as unsigned numbers - if you interpret your
0x84
as signed, there's definitely overflow:-172 is outside of the range of a signed 8-bit value (-128 to +127) and that's why the
OF
flag gets set. You should checkCF
which indicates unsigned overflow.From the Intel 64 and IA-32 Architectures Software Developer’s Manual, Volume 2 for CMP:
and for SUB: