英特尔程序集TEST PF标志操作 [英] intel assembly TEST PF flag operation
问题描述
我正在使用TEST
(Parity flag operation)
进行手动操作,问题是我无法获得正确的结果,请考虑以下问题:
I'm was doing a manual operation with TEST
(Parity flag operation)
, the problem it's that i can't get the right result, consider this:
ax = 256 = 0000 0001 0000 0000
所以,如果我这样做:
test ah, 0x44
PF
标志操作应为:
0000 0000 =
0000 0001
&
0100 0100
PF = 0000 0000 XNOR 0000 0000
PF = 1111 1111
?
据此,我遵循了英特尔参考文献:
I've followed the intel reference, according to this:
问题是我做错了什么?
推荐答案
BitwiseXNOR
是位的水平 XNOR,产生一个位.请记住,PF只有1位宽(EFLAGS中的标志),因此写PF=1111 1111
没有任何意义.
BitwiseXNOR
is a horizontal XNOR of the bits, producing a single bit. Remember that PF is only 1 bit wide (a flag in EFLAGS), so it makes no sense to write PF=1111 1111
.
对于根据结果设置标志"的指令,它始终与奇偶校验计算相同,只是对test
的内部临时结果执行此操作. (并且一如既往,不管操作数的大小如何,都在其低8位上.)
It's the same parity calculation as always for instructions that "set flags according to the result", except that it's done on test
's internal temporary result. (And as always, on the low 8 bits of it, regardless of operand size).
如果置位的位数为奇数,则PF = 0,如果置位的位数为偶数,则PF = 1.是的,您在评论中发布的表达式~(0^0^0^0^0^0^0^0)
是正确的.
PF = 0 if the number of set bits is odd, PF = 1 if the number of set bits is even. So yes, the expression you posted in comments, ~(0^0^0^0^0^0^0^0)
is correct.
另请参阅:
- https://en.wikipedia.org/wiki/Parity_flag
- https://en.wikipedia.org/wiki/Parity_bit 指出了这种奇偶性也是所有位的取反(求和模2). (因为
XOR
是不带进位的加法).可以使用popcnt eax, eax
/not eax
/and eax, 1
计算大于8位的整数的奇偶校验. (或者在循环外部使用BMIandn eax, eax, ecx
和ecx=1
进行设置,以在一条指令中做非和部分运算.)或者仅使用反转的奇偶校验值,其中1 =奇数奇偶校验.
- https://en.wikipedia.org/wiki/Parity_flag
- https://en.wikipedia.org/wiki/Parity_bit points out that parity is also the inverted (sum mod 2) of all the bits. (Because
XOR
is add-without-carry). Parity of an integer wider than 8 bits can be computed withpopcnt eax, eax
/not eax
/and eax, 1
. (Or use BMIandn eax, eax, ecx
withecx=1
set outside a loop to do the not-and part in one instruction.) Or just use the inverted parity value, where 1 = odd parity.
此答案有几个示例,说明了如何从结果中位的水平XOR.在您的情况下,这8位是test
内部生成的AND结果.
This answer has several examples of how PF is set from the horizontal-XOR of the bits in a result. In your case, the 8 bits are the AND result that test
internally generates.
这篇关于英特尔程序集TEST PF标志操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!