Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Overflow flag

From Wikipedia, the free encyclopedia

Processor flag indicating whether signed arithmetic overflow has occurred
icon
This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed.
Find sources: "Overflow flag" – news ·newspapers ·books ·scholar ·JSTOR
(January 2008) (Learn how and when to remove this message)

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

An example, suppose we add 127 and 127 using 8-bit registers. 127+127 is 254, but using 8-bit arithmetic the result would be 1111 1110 binary, which is thetwo's complement encoding of −2, a negative number. A negative sum 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 cannot occur when the sign of two addition operands are different (or the sign of two subtraction operands are the same).[1]

When binary values areinterpreted asunsigned numbers, the overflow flag is meaningless and normally ignored. One of the advantages of two's complement arithmetic is that the addition and subtraction operations do not need to distinguish between signed and unsigned operands. For this reason, most computer instruction sets do not distinguish between signed and unsigned operands, generating both (signed) overflow and (unsigned) carry flags on every operation, and leaving it to following instructions to pay attention to whichever one is of interest.[2]

Internally, the overflow flag is usually generated by anexclusive or of the internalcarryinto andout of the sign bit.

Bitwise operations (and, or, xor, not, rotate) do not have a notion of signed overflow, so the defined value varies on different processor architectures. Some processors clear the bit unconditionally (which is useful because bitwise operations set the sign flag, and the clear overflow flag then indicates that the sign flag is valid), others leave it unchanged, and some set it to anundefined value. Shifts and multiplies do permit a well-defined value, but it is not consistently implemented. For example, thex86 instruction set only defines the overflow flag for multiplies and 1-bit shifts; multi-bit shifts leave it undefined.

References

[edit]
  1. ^Kholodov, Igor (1 November 2008)."Overflow Detection: Signed Numbers Addition".CIS77 Introduction to Computer Systems (course notes).Bristol Community College. Retrieved2020-12-30.
  2. ^Allen, Ian D. (25 February 2011)."The CARRY flag and OVERFLOW flag in binary arithmetic".DAT 2343 Computer Systems Architecture (course notes).Algonquin College.
x86 assembly topics
Topics
Assemblers
Programming
issues
Retrieved from "https://en.wikipedia.org/w/index.php?title=Overflow_flag&oldid=1116985111"
Category:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp