Knowledge

Overflow flag

Source 📝

158:, 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. 27: 182:(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 an 146:
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
147:
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).
139:
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.
142:
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 the
277: 91: 63: 186:
value. Shifts and multiplies do permit a well-defined value, but it is not consistently implemented. For example, the
270: 190:
instruction set only defines the overflow flag for multiplies and 1-bit shifts; multi-bit shifts leave it undefined.
110: 70: 343: 318: 77: 48: 44: 208: 499: 263: 59: 135:
used to indicate when an arithmetic overflow has occurred in an operation, indicating that the signed
374: 216: 473: 303: 468: 237: 37: 392: 333: 84: 8: 368: 143: 136: 463: 183: 179: 380: 298: 245: 458: 386: 313: 155: 132: 448: 431: 426: 416: 351: 328: 493: 362: 323: 308: 162: 18:
Processor flag indicating whether signed arithmetic overflow has occurred
478: 421: 411: 166: 255: 441: 26: 453: 356: 187: 161:
Internally, the overflow flag is usually generated by an
238:"The CARRY flag and OVERFLOW flag in binary arithmetic" 51:. Unsourced material may be challenged and removed. 491: 271: 209:"Overflow Detection: Signed Numbers Addition" 278: 264: 111:Learn how and when to remove this message 206: 285: 492: 242:DAT 2343 Computer Systems Architecture 213:CIS77 Introduction to Computer Systems 131:) is usually a single bit in a system 259: 235: 49:adding citations to reliable sources 20: 13: 236:Allen, Ian D. (25 February 2011). 207:Kholodov, Igor (1 November 2008). 14: 511: 25: 36:needs additional citations for 319:Low-level programming language 229: 200: 1: 193: 123:In computer processors, the 7: 10: 516: 402: 375:Microsoft Macro Assembler 342: 291: 217:Bristol Community College 304:Comparison of assemblers 150:When binary values are 127:(sometimes called the 393:Open Watcom Assembler 334:x86 assembly language 474:Instruction listings 45:improve this article 500:Computer arithmetic 469:Calling conventions 369:High Level Assembly 286:x86 assembly topics 464:Processor register 180:Bitwise operations 487: 486: 381:Netwide Assembler 299:Assembly language 246:Algonquin College 121: 120: 113: 95: 507: 280: 273: 266: 257: 256: 250: 249: 244:(course notes). 233: 227: 226: 224: 223: 215:(course notes). 204: 165:of the internal 156:unsigned numbers 144:two's complement 137:two's-complement 116: 109: 105: 102: 96: 94: 53: 29: 21: 515: 514: 510: 509: 508: 506: 505: 504: 490: 489: 488: 483: 459:Program counter 404: 398: 387:Turbo Assembler 338: 314:Instruction set 287: 284: 254: 253: 234: 230: 221: 219: 205: 201: 196: 133:status register 117: 106: 100: 97: 60:"Overflow flag" 54: 52: 42: 30: 19: 12: 11: 5: 513: 503: 502: 485: 484: 482: 481: 476: 471: 466: 461: 456: 451: 449:Memory address 446: 445: 444: 439: 434: 432:Interrupt flag 429: 427:Direction flag 424: 414: 408: 406: 400: 399: 397: 396: 390: 384: 378: 372: 366: 360: 357:Flat Assembler 354: 348: 346: 340: 339: 337: 336: 331: 329:Microassembler 326: 321: 316: 311: 306: 301: 295: 293: 289: 288: 283: 282: 275: 268: 260: 252: 251: 228: 198: 197: 195: 192: 176:the sign bit. 119: 118: 33: 31: 24: 17: 9: 6: 4: 3: 2: 512: 501: 498: 497: 495: 480: 477: 475: 472: 470: 467: 465: 462: 460: 457: 455: 452: 450: 447: 443: 440: 438: 437:Overflow flag 435: 433: 430: 428: 425: 423: 420: 419: 418: 415: 413: 410: 409: 407: 401: 394: 391: 388: 385: 382: 379: 376: 373: 370: 367: 364: 363:GNU Assembler 361: 358: 355: 353: 350: 349: 347: 345: 341: 335: 332: 330: 327: 325: 322: 320: 317: 315: 312: 310: 307: 305: 302: 300: 297: 296: 294: 290: 281: 276: 274: 269: 267: 262: 261: 258: 247: 243: 239: 232: 218: 214: 210: 203: 199: 191: 189: 185: 181: 177: 175: 171: 168: 164: 159: 157: 153: 148: 145: 140: 138: 134: 130: 126: 125:overflow flag 115: 112: 104: 93: 90: 86: 83: 79: 76: 72: 69: 65: 62: –  61: 57: 56:Find sources: 50: 46: 40: 39: 34:This article 32: 28: 23: 22: 16: 436: 324:Machine code 309:Disassembler 241: 231: 220:. Retrieved 212: 202: 178: 173: 169: 163:exclusive or 160: 151: 149: 141: 128: 124: 122: 107: 101:January 2008 98: 88: 81: 74: 67: 55: 43:Please help 38:verification 35: 15: 403:Programming 152:interpreted 422:Carry flag 412:Call stack 344:Assemblers 222:2020-12-30 194:References 71:newspapers 479:Registers 442:Zero flag 184:undefined 494:Category 352:A86/A386 85:scholar 454:Opcode 405:issues 395:(WASM) 389:(TASM) 383:(NASM) 377:(MASM) 359:(FASM) 292:Topics 174:out of 129:V flag 87:  80:  73:  66:  58:  417:Flags 371:(HLA) 365:(GAS) 167:carry 92:JSTOR 78:books 172:and 170:into 64:news 188:x86 154:as 47:by 496:: 240:. 211:. 279:e 272:t 265:v 248:. 225:. 114:) 108:( 103:) 99:( 89:· 82:· 75:· 68:· 41:.

Index


verification
improve this article
adding citations to reliable sources
"Overflow flag"
news
newspapers
books
scholar
JSTOR
Learn how and when to remove this message
status register
two's-complement
two's complement
unsigned numbers
exclusive or
carry
Bitwise operations
undefined
x86
"Overflow Detection: Signed Numbers Addition"
Bristol Community College
"The CARRY flag and OVERFLOW flag in binary arithmetic"
Algonquin College
v
t
e
Assembly language
Comparison of assemblers
Disassembler

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.