汇编语言的NEG指令是否设置了溢出标志 [英] does NEG instruction in assembly language sets the Overflow flag

查看:204
本文介绍了汇编语言的NEG指令是否设置了溢出标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i want to know about NEG instruction, does it affects the overflow flag too!!!..i got to know that is just negate the value of a variable but couldn't know that is it affects the Overflow flag

推荐答案

如果您想知道什么说明,请查阅参考手册.

If you want to know what instructions do, consult the reference manuals.

The essential reference, namely the Intel instruction set manual says this about the NEG instruction:

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的原始问题.每次执行时都会这样做. (人们不应将未更改"与未设置"混为一谈.)

So it is clear that the NEG instruction sets the O flag; therefore it affects the O flag, which is the OP's original question. And it does so every time it is executed. (People should not confuse "didn't change" from "not set").

该特定参考手册未提供特定算法来指示O何时设置为零或一.但是,英特尔CPU是2的补码机.减法指令具有完全相同的语言. NEG X等于(0 SUBTRACT X).因此,NEG应根据溢出"将O位设置为(0 SUBTRACT X);当X为0x8000000时,它将设置为O.

That particular reference manual doesn't provide a specific algorithm to indicate when O is set to zero or one. However, Intel CPUs are 2's complement machines. The Subtract instruction has the exact same verbiage. NEG X is equivalent to (0 SUBTRACT X). So NEG should set the O bit according to "overflow" for (0 SUBTRACT X); this will set O when X is 0x8000000.

检查

Inspecting the Intel Basic Archiecture Manual, we find this description of the OF bit:

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

确认我们的理解.

这篇关于汇编语言的NEG指令是否设置了溢出标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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