Overflow flag

Overflow flag

In computer processors, the overflow flag (sometimes called V flag) is usually a single bit in a system status register used to indicate when an arithmetic overflow has occurred in an operation, indicating that the signed two's-complement result would not fit in the number of bits used for the operation (the ALU width). Some architectures may be configured to automatically generate an exception on an operation resulting in overflow.

Although not very precise, the overflow flag could be considered a two's complement form of a carry flag, but the typical usage is quite different.

An illustrative example is what happens if we add 127 and 127 using 8-bit registers. 127+127 is 254, but using 8-bit aritmetics the result would be 1111 1110 binary, which is -2 in two's complement, and thus negative. A negative result out of positive operands (or vice versa) is an overflow. The overflow flag would then be set so the program can be aware of the problem and mitigate this or signal an error. The overflow flag is thus set when the most significant bit (here considered the sign bit) is changed by adding two numbers with the same sign (or subtracting two numbers with opposite signs). Overflow never occurs when the sign of two addition operands are different (or the sign of two subtraction operands are the same).

Internally, the overflow flag is usually generated by an exclusive or of the internal carry into and out of the sign bit. As the sign bit is the same as the most significant bit of a number considered unsigned, the overflow flag is "meaningless" and normally ignored when unsigned numbers are added or subtracted.

The overflow flag is typically changed by all arithmetic operations, including compare instructions (equivalent to a subtract instruction without storing the result). In many processor architectures, the overflow flag is cleared by bitwise operations (and, or, xor, not), possibly including shifts and rotates, but it may also be left undefined by these. Instructions such as multiply and divide often leave the flag undefined, or affected by the last partial result.

Notes and references


Wikimedia Foundation. 2010.

Игры ⚽ Поможем решить контрольную работу

Look at other dictionaries:

  • Flag byte — A flag byte is a generic term for a byte used to indicate conditions within a binary computer. In particular, the byte can be used to show up to 8 discrete conditions. Essentially, each bit represents one flag, capable of showing two states.… …   Wikipedia

  • Flag (Informatik) — Mit Flag [flæg] wird eine binäre Variable oder ein Statusindikator bezeichnet, welcher als Hilfsmittel zur Kennzeichnung bestimmter Zustände benutzt werden kann. Ein Flag kann gesetzt, gelöscht oder ausgelesen werden. Flags im Prozessor Ein Flag… …   Deutsch Wikipedia

  • Overflow Crowds Band — Datos generales Origen New York,New York,Estados Unidos …   Wikipedia Español

  • Flag (computing) — In computer programming, flag refers to one or more bits that are used to store a binary value or code that has an assigned meaning. Flags are typically found as members of a defined data structure, such as a database record, and the meaning of… …   Wikipedia

  • Arithmetic overflow — The term arithmetic overflow or simply overflow has the following meanings. In a computer, the condition that occurs when a calculation produces a result that is greater in magnitude than that which a given register or storage location can store… …   Wikipedia

  • Carry flag — In computer processors the carry flag (usually indicated as the C flag) is a single bit in a system status (flag) register used to indicate when an arithmetic carry or borrow has been generated out of the most significant ALU bit position. When… …   Wikipedia

  • Buffer overflow protection — refers to various techniques used during software development to enhance the security of executable programs by detecting buffer overflows on stack allocated variables as they occur and preventing them from becoming serious security… …   Wikipedia

  • Stack buffer overflow — In software, a stack buffer overflow occurs when a program writes to a memory address on the program s call stack outside of the intended data structure; usually a fixed length buffer.cite web last = Fithen first = William L coauthors = Seacord,… …   Wikipedia

  • Flash Bulb Emergency Overflow Cavalcade of Remixes — Infobox Album Name = Flash Bulb Emergency Overflow Cavalcade of Remixes Type = Remix Artist = Pigeonhed Released = 1998 Recorded = Genre = Alternative rock Length = Label = Subpop Producer = Reviews = Last album = This album = Next album = Flash… …   Wikipedia

  • Branch (computer science) — For other uses, see Branch (disambiguation). A branch is sequence of code in a computer program which is conditionally executed depending on whether the flow of control is altered or not (at the branching point). The term can be used when… …   Wikipedia

Share the article and excerpts

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