为什么CMP 0x84,0x30触发溢出标志? [英] Why does cmp 0x84,0x30 trigger the overflow flag?

查看:215
本文介绍了为什么CMP 0x84,0x30触发溢出标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在玩装配了一会儿,看一些code。
其中AL首先被设置到的0x84然后CMP AL,的0x30被使用。
然后,此指令触发溢出标志。

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.

从我读CMP应该从第一减去第二个数字,然后设置标志,在这种情况下,它应该是0x84-0x30结果是0x54,没有溢出。

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.

推荐答案

还有,如果你是跨preT这些值作为无符号数只是没有溢出 - 如果你跨preT你的的0x84 作为签约,肯定有溢出:

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:


  1. PTED为有符号的8位值的0x84间$ P $是-124

  2. PTED为有符号的8位值的0x30间$ P $ 48

  3. -124 - 48 = -172

-172是一种符号的8位值(-128到+127)的范围之外,这就是为什么在标志置位。您应该检查 CF ,表示无符号溢出。

-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 check CF which indicates unsigned overflow.

从<一个href=\"http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html/\">Intel 64和IA-32架构软件开发人员手册,第2卷CMP:

的比较是通过从第一操作数中减去第二个操作数,然后以相同的方式作为SUB指令设定状态标志进行。

The comparison is performed by subtracting the second operand from the first operand and then setting the status flags in the same manner as the SUB instruction.

和SUB:

SUB指令执行整数加减。它计算两种符号和无符号整数运算的结果,并设置和CF标志来表示有符号或无符号结果溢出,分别。 SF标志表示有符号结果的符号。

The SUB instruction performs integer subtraction. It evaluates the result for both signed and unsigned integer operands and sets the OF and CF flags to indicate an overflow in the signed or unsigned result, respectively. The SF flag indicates the sign of the signed result.

这篇关于为什么CMP 0x84,0x30触发溢出标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆