Flag register of 8086 microprocessor - GeeksforGeeks

22 May, 2018
Prerequisite – Flag register in 8085 microprocessorThe Flag register is a Special Purpose Register. Depending upon the value of result after any arithmetic and logical operation the flag bits become set (1) or reset (0).
Figure – Format of flag registerThere are total 9 flags in 8086 and the flag register is divided into two types:
(a) Status Flags – There are 6 flag registers in 8086 microprocessor which become set(1) or reset(0) depending upon condition after either 8-bit or 16-bit operation. These flags are conditional/status flags. 5 of these flags are same as in case of 8085 microprocessor and their working is also same as in 8085 microprocessor. The sixth one is the overflow flag.
The 6 status flags are:
Sign Flag (S)Zero Flag (Z)Auxiliary Cary Flag (AC)Parity Flag (P)Carry Flag (CY)These first five flags are defined hereOverflow Flag (O) – This flag will be set (1) if the result of a signed operation is too large to fit in the number of bits available to represent it, otherwise reset (0). After any operation, if D[6] generates any carry and passes to D[7] OR if D[6] does not generates carry but D[7] generates, overflow flag becomes set, i.e., 1. If D[6] and D[7] both generate carry or both do not generate any carry, then overflow flag becomes reset, i.e., 0.Example: On adding bytes 100 + 50 (result is not in range -128...127), so overflow flag will set.MOV AL, 50 (50 is 01010000 which is positive)
MOV BL, 32 (32 is 00110010 which is positive)
ADD AL, BL (82 is 10000010 which is negative)
Overflow flag became set as we added 2 +ve numbers and we got a -ve number.
Sign Flag (S)
Zero Flag (Z)
Auxiliary Cary Flag (AC)
Parity Flag (P)
Carry Flag (CY)These first five flags are defined here
Overflow Flag (O) – This flag will be set (1) if the result of a signed operation is too large to fit in the number of bits available to represent it, otherwise reset (0). After any operation, if D[6] generates any carry and passes to D[7] OR if D[6] does not generates carry but D[7] generates, overflow flag becomes set, i.e., 1. If D[6] and D[7] both generate carry or both do not generate any carry, then overflow flag becomes reset, i.e., 0.Example: On adding bytes 100 + 50 (result is not in range -128...127), so overflow flag will set.MOV AL, 50 (50 is 01010000 which is positive)
MOV BL, 32 (32 is 00110010 which is positive)
ADD AL, BL (82 is 10000010 which is negative)
Overflow flag became set as we added 2 +ve numbers and we got a -ve number.
Example: On adding bytes 100 + 50 (result is not in range -128...127), so overflow flag will set.
MOV AL, 50 (50 is 01010000 which is positive)
MOV BL, 32 (32 is 00110010 which is positive)
ADD AL, BL (82 is 10000010 which is negative)

Overflow flag became set as we added 2 +ve numbers and we got a -ve number.
(b) Control Flags – The control flags enable or disable certain operations of the microprocessor. There are 3 control flags in 8086 microprocessor and these are:
Directional Flag (D) – This flag is specifically used in string instructions.If directional flag is set (1), then access the string data from higher memory location towards lower memory location.If directional flag is reset (0), then access the string data from lower memory location towards higher memory location.Interrupt Flag (I) – This flag is for interrupts.If interrupt flag is set (1), the microprocessor will recognize interrupt requests from the peripherals.If interrupt flag is reset (0), the microprocessor will not recognize any interrupt requests and will ignore them.Trap Flag (T) – This flag is used for on-chip debugging. Setting trap flag puts the microprocessor into single step mode for debugging. In single stepping, the microprocessor executes a instruction and enters into single step ISR.If trap flag is set (1), the CPU automatically generates an internal interrupt after each instruction, allowing a program to be inspected as it executes instruction by instruction.If trap flag is reset (0), no function is performed.
Directional Flag (D) – This flag is specifically used in string instructions.If directional flag is set (1), then access the string data from higher memory location towards lower memory location.If directional flag is reset (0), then access the string data from lower memory location towards higher memory location.
Interrupt Flag (I) – This flag is for interrupts.If interrupt flag is set (1), the microprocessor will recognize interrupt requests from the peripherals.If interrupt flag is reset (0), the microprocessor will not recognize any interrupt requests and will ignore them.
Trap Flag (T) – This flag is used for on-chip debugging. Setting trap flag puts the microprocessor into single step mode for debugging. In single stepping, the microprocessor executes a instruction and enters into single step ISR.If trap flag is set (1), the CPU automatically generates an internal interrupt after each instruction, allowing a program to be inspected as it executes instruction by instruction.If trap flag is reset (0), no function is performed.
Shivi_Aggarwal
microprocessor
Computer Organization & Architecture
microprocessor
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Computer Organization and Architecture | Pipelining | Set 1 (Execution, Stages and Throughput)
Memory Hierarchy Design and its Characteristics
Computer Organization | RISC and CISC
Direct Access Media (DMA) Controller in Computer Architecture
Interrupts
Computer Organization and Architecture | Pipelining | Set 2 (Dependencies and Data Hazard)
Programmable peripheral interface 8255
Computer Organization | Von Neumann architecture
Architecture of 8085 microprocessor
Write Through and Write Back in Cache