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

k11*_*mer 1 x86 assembly masm32 eflags signed-overflow

我想知道 NEG 指令是否也会影响溢出标志。我知道它否定变量的值,但无法确定它是否影响溢出标志。

Ira*_*ter 5

如果您想知道指令的作用,请查阅参考手册。

重要参考,即英特尔指令集手册说,这对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. 
Run Code Online (Sandbox Code Playgroud)

所以很明显NEG指令设置了O标志;因此它会影响O 标志,这是 OP 的原始问题。每次执行时它都会这样做。(人们不应将“未更改”与“未设置”混淆)。

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

检查英特尔基本架构手册,我们发现 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
Run Code Online (Sandbox Code Playgroud)

确认我们的理解。