In the 8086/8088, the overflow flag is set when the result of an arithmetic instruction exceeds the bounds of the signed representation of a number. This is not the same as the carry flag, which is used for the unsigned representation. Both flags get set as needed. You decide which one to pay attention to.
FLAGS REGISTER="h2headingh3"style="color:rgb(0,0,0);"name="flags_register">Flags Register - determines the current state of the processor. They are modified automatically by CPU after mathematical operations and allow one to determine the type of the result as well as determine conditions to transfer control to other parts of the program. Generally you cannot access these registers directly.Carry Flag (CF) - this flag is set to 1 when there is an unsigned overflow. For example when you add bytes 255 + 1 (result is not in range 0...255). When there is no overflow this flag is set to 0.Parity Flag (PF) - this flag is set to 1 when there is even number of one bits in result, and to 0 when there is odd number of one bits.Auxiliary Flag (AF) - set to 1 when there is an unsigned overflow for low nibble (4 bits).Zero Flag (ZF) - set to 1 when result is zero. For non-zero result this flag is set to 0.Sign Flag (SF) - set to 1 when result is negative. When result is positive it is set to 0. (This flag takes the value of the most significant bit.)Trap Flag (TF) - Used for on-chip debugging.Interrupt enable Flag (IF) - when this flag is set to 1 CPU reacts to interrupts from external devices.Direction Flag (DF) - this flag is used by some instructions to process data chains, when this flag is set to 0 - the processing is done forward, when this flag is set to 1 the processing is done backward.Overflow Flag (OF) - set to 1 when there is a signed overflow. For example, when you add bytes 100 + 50 (result is not in range -128...127).
The carry flag indicates that an arithmetic operation between two numbers resulted in an unsigned carry or borrow. The overflow flag indicates that an arithmetic operation between two numbers resulted in an unexpected change in sign, i.e. an overflow. Carry is also like overflow. The difference is in interpretation. Do you consider the numbers signed or unsigned? Its all in interpretation because the hardware logic needed to add two numbers works the same, no matter if they are considered signed or unsigned. Both flags are set or cleared together, so you can use whichever you wish.
There are nine flags in the 8086/8088.SF - Sign Flag - The result is negativeZF - Zero Flag - The result is zeroAF - Auxillary Carry Flag - A BCD carry occurredPF - Parity Flag - Indicates the oddness or evenness of the number of bitsCF - Carry Flag - An unsigned carry occurredOF - Overflow Flag - A signed overflow/carry occurredDF - Direction Flag - Controls the direction of repeated string operationsIF - Interrupt Flag - Enables or disables interruptsTF - Trace Flag - Controls the debug single step interruptIn general, most of these flags are set as a result of some arithmetic or logical instruction and can be tested using the conditional branch instructions. Exceptions are DF, which controls the directionality of repeated string operations, IF, which controls interrupts, and TF, which controls debugging.
There are nine flags in the 8086/8088.SF - Sign Flag - The result is negativeZF - Zero Flag - The result is zeroAF - Auxillary Carry Flag - A BCD carry occurredPF - Parity Flag - Indicates the oddness or evenness of the number of bitsCF - Carry Flag - An unsigned carry occurredOF - Overflow Flag - A signed overflow/carry occurredDF - Direction Flag - Controls the direction of repeated string operationsIF - Interrupt Flag - Enables or disables interruptsTF - Trace Flag - Controls the debug single step interruptIn general, most of these flags are set as a result of some arithmetic or logical instruction and can be tested using the conditional branch instructions. Exceptions are DF, which controls the directionality of repeated string operations, IF, which controls interrupts, and TF, which controls debugging.
The flags are testable conditions that are set after many arithmetic or logical instructions to indicate something about the result of the result. For instance, the Z flag means the result is zero, the N flag means it is negative, the O flag means a signed overflow occurred, the C flag means an unsigned overflow occurred, and the P flag means an even number of bits is set in the result. You can use the various flag testable jump instructions, such as JZ or JNZ to test the flag after performing an operation that sets or resets the flag.
When two numbers multiply, the Overflow (O) and Carry (C) flag bits are affected based on the result of the multiplication. The Overflow flag is set if the result exceeds the maximum representable value for the given data type, indicating a signed overflow. The Carry flag is typically set if there is a carry out from the most significant bit, which occurs in unsigned multiplication when the result exceeds the capacity of the destination register. Thus, both flags indicate potential issues with the result's representation.
OR AX Will clear carry and overflow, leaving AX alone.
Conditional FlagsConditional flags represent result of last arithmetic or logical instruction executed. Conditional flags are as follows:1. CF (Carry Flag)This flag indicates an overflow condition for unsigned integer arithmetic. It is also used in multiple-precision arithmetic.2. AF (Auxiliary Flag)If an operation performed in ALU generates a carry/barrow from lower nibble (i.e. D0 - D3) to upper nibble (i.e. D4 - D7), the AF flag is set i.e. carry given by D3 bit to D4 is AF flag. This is not a general-purpose flag; it is used internally by the processor to perform Binary to BCD conversion.3. PF (Parity Flag)This flag is used to indicate the parity of result. If lower order 8-bits of the result contains even number of 1's, the Parity Flag is set and for odd number of 1's, the Parity Flag is reset.4. ZF (Zero Flag)It is set; if the result of arithmetic or logical operation is zero else it is reset.5. SF (Sign Flag)6. SF (Sign Flag)In sign magnitude format the sign of number is indicated by MSB bit. If the result of operation is negative, sign flag is set.7. OF (Overflow Flag)This stands for over flow flag. It occurs when signed numbers are added or subtracted. An OF indicates that the result has exceeded the capacity of machine. It becomes set if the sign result cannot express within the number of bites.Read More: http://www.daenotes.com/electronics/digital-electronics/8086-8088-microprocessor
Carry flag is the the bit 7 of the 8 bit PSW register, whenever there is an addition or subtraction process that has a carry on its 7th bit, the carry flag (C/CY) will be set to 1. OV is set to 1 when there is an arithmetic overflow. this applies to signed and unsigned operations.
Flag Register (PSW)Status is indicated with individual bits: 0 - CF - Carry Flag2 - PF - Parity Flag4 - AF - Auxiliary carry Flag6 - ZF - Zero Flag7 - SF - Sign Flag8 - TF - Trap Flag9 - IF - Interrupt Flag10 - DF - Direcetion Flag11 - OF - Overflow Flag
In the context of the 8086 microprocessor, PSW stands for Program Status Word. It is a 16-bit register that contains flags and status bits that reflect the outcome of arithmetic and logical operations performed by the processor. The PSW includes flags such as the zero flag, carry flag, sign flag, and overflow flag, which are crucial for controlling program flow and making decisions in assembly language programming. The PSW plays a significant role in determining the execution path of a program based on the results of previous instructions.
In general, the best way to change the flag register is to perform some operation that sets or clears flags. If you are careful, you can also push the flags onto the stack, manipulate the stored value, and then pop them back off. This is often the method used by a debugger to set the single step flag. When using this method, it is important to not set an inconsistent combination of flags.