汇编语言中的NEG指令是否设置了溢出标志

时间:2014-10-18 13:51:45

标签: assembly masm32

我想知道NEG指令,它是否也会影响溢出标志!!! ..我知道这只是否定变量的值但是不知道它是否会影响溢出标志

2 个答案:

答案 0 :(得分:4)

如果您想知道说明书的作用,请参阅参考手册。

essential reference, namely the Intel instruction set manual对NEG指令说了这个:

Flags Affected
The CF flag set to 0 if the source operand is 0; otherwise it is set to 1.
The OF, SF, ZF, AF, and PF flags are set according to the result. 

很明显,NEG指令设置 O标志;因此它影响 O标志,这是OP的原始问题。它每次执行时都会这样做。 (人们不应该混淆"没有改变"来自"没有设置")。

该特定参考手册没有提供特定算法来指示何时将O设置为零或一。但是,英特尔CPU是2的补充机器。 Subtract指令具有完全相同的措辞。 NEG X相当于(0 SUBTRACT X)。因此NEG应根据"溢出"设置O位。 for(0 SUBTRACT X);当X为0x8000000时,这将设置O。

检查Intel Basic Archiecture Manual,我们找到OF位的描述:

OF (bit 11) Overflow flag
— Set if the integer result is too large a positive number or too small a
  negative number (excluding the sign-bit) to fit in the destination operand;
  cleared otherwise. This flag indicates an overflow condition for signed-integer
 (two’s complement) arithmetic

确认我们的理解。

答案 1 :(得分:0)

如果neg80h,操作数不会改变,但溢出标志确实设置为1