如何在x86程序集中设置或清除溢出标志? [英] How can I set or clear overflow flag in x86 assembly?
问题描述
我想编写一个简单的代码(或算法)来设置/清除溢出标志.对于设置OF,我知道我可以使用带符号的值.但是我该如何清除呢?
I want to write a simple code (or algorithm) to set/clear overflow flag. For setting OF, I know that I can use signed values. But how can I clear that?
推荐答案
有许多可能的解决方案.
There are many possible solutions.
例如, test al, al
将清除OF
标志,而不会影响寄存器的内容.
For instance, test al, al
will clear the OF
flag without affecting register contents.
或者,如果您不想影响其他标志,则可以直接修改*FLAGS
寄存器.例如,在32位中,看起来像这样:
Or, if you don't want to affect the other flags, you can just directly modify the *FLAGS
register. For example, in 32-bit, this would look like:
pushfd ; Push EFLAGS onto the stack
and dword [esp], ~0x800 ; Clear bit 11 (OF)
popfd ; Pop the modified result back into EFLAGS
根据 Peter Cordes 的建议,将or al, al
更改为test al, al
. (效果是相同的,但出于性能方面的考虑,后者更好)
Changed or al, al
to test al, al
per Peter Cordes' recommendation. (The effects are the same but the latter is better for performance reasons)
这篇关于如何在x86程序集中设置或清除溢出标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!