NEG指令如何影响x86上的标志? [英] How does the NEG instruction affect the flags on x86?

查看:188
本文介绍了NEG指令如何影响x86上的标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

《英特尔软件开发手册》关于neg指令的内容是这样的:

The Intel Software Development Manual says this about the neg instruction:

如果源操作数为0,则CF标志设置为0;否则,将CF标志设置为0.否则设置为1.OF,SF,ZF,AF和PF标志根据结果设置.

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.

我认为将AF和CF设置为好像由neg %eax替换为

I thought that AF and CF would be set as if neg %eax were replaced by,

not %eax   # bitwise negation
add $1, %eax

但是事实并非如此,在实际CPU上取反0x6ffffef5会设置AF和CF.

But that's not the case, negating 0x6ffffef5 on a real CPU sets AF and CF.

推荐答案

neg所有标志设置为与sub从0开始获得的标志相同.

neg sets all flags identically to what you'd get with a sub from 0.

此指令序列将所有标志(包括AF和CF)设置为与neg %eax相同:

This sequence of instructions sets all flags (including AF and CF) identically to neg %eax:

xor  %ecx, %ecx
sub  %eax, %ecx     # ecx = 0 - eax


英特尔文档确实确实指定了此内容,但没有在neg本身的指令集参考(第2卷)条目的伪代码操作"部分或受标志影响的部分中指定.


Intel's documentation does actually specify this, but not in the pseudo-code Operation section or in the flags-affected section of the instruction-set reference (Volume 2) entry for neg itself.

neg 的描述"部分的文本包括此块:

The text of the Description section for neg includes this nugget:

此操作等效于从0减去操作数.

This operation is equivalent to subtracting the operand from 0.

并且在

7.3.2.4比较和符号更改说明

[有关CMP的段落]

[a paragraph about CMP]

NEG(取反)指令从零中减去有符号整数操作数.

The existence of this documentation was pointed out by a comment on an earlier duplicate of this question which isn't as directly worded.

我不知道第1卷的整个章节都对说明进行了说明.事实证明,第2卷insn集合参考中并没有提到Intel关于单个指令的所有内容.

I didn't know that vol.1 had a whole section explaining the instructions. It turns out that not everything Intel has to say about individual instructions is in the Volume 2 insn set reference.

有证据表明,neg在内部解码为与Intel CPU上的sub指令相同的uop. (例如,neg [mem]可以与ALU op微融合负载,以及微融合存储地址和存储数据uops.inc [mem]只能微融合存储,因此总共有3个融合域哦.

There's some evidence that neg decodes internally to the same uop as a sub instruction on Intel CPUs. (e.g. neg [mem] can micro-fuse the load with the ALU op, as well as micro-fusing the store-address and store-data uops. inc [mem] can only micro-fuse the store, so it's 3 total fused-domain uops).

这篇关于NEG指令如何影响x86上的标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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