views:

64

answers:

3

In X86 assembly, is it possible to clear the Parity Flag in one and only one instruction, working under ANY initial register configuration?

This is equivalent to creating a result register with an ODD number of bits, with any operation that sets flags (expressly excluding "mov").

For contrast, setting the parity flag can be done in one instruction.

cmp bl, bl

And there are many ways to clear the parity flag with two instructions

and bl, 0 
or  bl, 1

However, the one instruction method remains elusive.

A: 

It's possible. Parity is tad more... uhm annoying.

There are some specific instructions such as CLC, CLD, CLI (Clear, Carry-Direction-Interrupt) that will clear their respective flags. A thing you could do is PUSHFD which will push the flags onto the stack... though you have to pop it eventually or things can go haywire unless your confident enough with playing with the stack. Another one you can use is SAHF (Store AH into Flags), though you might still need an extra instruction for this. (such as mov AH,0)

w3b_wizzard
I'm sorry, but this is all wrong information. CLC, CLD, CLI, PUSHFD, none of those clear the PF bit in EFLAGS.
Michael Foukarakis
I'm sorry but I did not say that it cleared the parity flag. But that it cleared specific flags.
w3b_wizzard
+1  A: 

Not possible.

None of the PF-changing commands can produce an odd-parity result when applied to two copies or a register (like or al, al). Likewise, none of the arithmetic commands produces an odd-parity result when applied to a register and a constant that completely defines the result (like and al, 0 or or al, ffh). As for commands where the second operand is any other constant, the result would depend on the initial value of the register, and we have no control over that.

Seva Alekseyev
A: 

I think the only way to do it besides mov (I smell interview question) is to find (miraculously, admittedly) a register or register pair that will satisfy TEST src, dst. See here, Operation.

At this moment, no such x86 register/register pair that could satisfy that condition spring to mind.

Michael Foukarakis
Or a memory location that has a well-known value. It was quite possible back in DOS days, when one had a fair chance to encounter and assembly question on an interview.
Seva Alekseyev

related questions