Parity flag

Parity flag

In computer processors the parity flag indicates if the number of set bits is odd or even in the binary representation of the result of the last operation. It is normally a single bit in a processor status register.

For example, assume a machine where a set parity flag indicates even parity. If the result of the last operation were 26 (11010 in binary), the parity flag would be 0 since the number of set bits is odd. Similarly, if the result were 102 (1100110 in binary) then the parity flag would be 1.

x86 Processors

In x86 processors, the parity flag reflects the parity only of the "least significant byte" of the result, and is set if the number of ones is even. According to 80386 Intel manual, the parity flag is changed in the x86 processor family by the following instructions:
* All arithmetic instructions;
* Compare instruction (equivalent to a subtract instruction without storing the result);
* Logical instructions - XOR, AND, OR;
* the TEST instruction (equivalent to the AND instruction without storing the result).
* the POPF instruction

The parity flag is usually used in conditional jumps, where e.g. the JP instruction jumps to the given target when the parity flag is set and the JNP instruction jumps if it is not set. The flag may be also read directly with instructions such as PUSHF, which pushes the flags register on the stack.

One common reason to test the parity flag actually has nothing to do with parity. The FPU has four condition flags (C0 to C3), but they can not be tested directly, and must instead be first copied to the flags register. When this happens, C0 is placed in the carry flag, C2 in the parity flag and C3 in the zero flag [cite web
url=http://www.intel.com/products/processor/manuals/index.htm
title=Intel® 64 and IA-32 Architectures Software Developer's Manual Volume 1: Basic Architecture
year=2008
month=April
pages=pp. 237-238
] . The C2 flag is set when e.g. incomparable floating point values (NaN or unsupported format) are compared with the FUCOM instructions.

References

ee also

* x86 architecture
* x86 assembly language
* x86 Flags Register


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Condition Code Register — Das Statusregister (auch Zustandsregister, engl. Condition Code Register, CCR) ist ein spezielles Register im Steuerwerk eines Mikroprozessors. Da man diese Bits auch als Flags bezeichnet, wird das Statusregister auch Flagregister genannt. Es… …   Deutsch Wikipedia

  • Processor Status Word — Das Statusregister (auch Zustandsregister, engl. Condition Code Register, CCR) ist ein spezielles Register im Steuerwerk eines Mikroprozessors. Da man diese Bits auch als Flags bezeichnet, wird das Statusregister auch Flagregister genannt. Es… …   Deutsch Wikipedia

  • Programmstatuswort — Das Statusregister (auch Zustandsregister, engl. Condition Code Register, CCR) ist ein spezielles Register im Steuerwerk eines Mikroprozessors. Da man diese Bits auch als Flags bezeichnet, wird das Statusregister auch Flagregister genannt. Es… …   Deutsch Wikipedia

  • Statusbits — Das Statusregister (auch Zustandsregister, engl. Condition Code Register, CCR) ist ein spezielles Register im Steuerwerk eines Mikroprozessors. Da man diese Bits auch als Flags bezeichnet, wird das Statusregister auch Flagregister genannt. Es… …   Deutsch Wikipedia

  • Statusregister — Das Statusregister (auch Zustandsregister, engl. condition code register, CCR, oder Programmstatuswort, engl. program status word, PSW) ist ein spezielles Register im Steuerwerk eines Mikroprozessors. Da man diese Bits auch als Flags bezeichnet,… …   Deutsch Wikipedia

  • EFLAGS — RFLAGS Le registre RFLAGS aussi dit registre de drapeaux est un registre spécifique des processeurs de la famille x86 64 (64 bits). Il est compatible avec les registres EFLAGS et FLAGS hérités des familles x86 (32 bits) et précédente (16 bits).… …   Wikipédia en Français

  • FLAGS — RFLAGS Le registre RFLAGS aussi dit registre de drapeaux est un registre spécifique des processeurs de la famille x86 64 (64 bits). Il est compatible avec les registres EFLAGS et FLAGS hérités des familles x86 (32 bits) et précédente (16 bits).… …   Wikipédia en Français

  • RFLAGS — Le registre RFLAGS aussi dit registre de drapeaux est un registre spécifique des processeurs de la famille x86 64 (64 bits). Il est compatible avec les registres EFLAGS et FLAGS hérités des familles x86 (32 bits) et précédente (16 bits). Il… …   Wikipédia en Français

  • Intel 8086 — Produced From 1978 to 1990s Common manufacturer(s) Intel, AMD, NEC, Fujitsu, Harris (Intersil), OKI, Siemens AG …   Wikipedia

  • Status register — A status register or flag register (also: condition code register, program status word, PSW, etc.) is a collection of flag bits for a processor. An example is the FLAGS register of the x86 architecture. The status register is a hardware register… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”