The Wayback Machine - https://web.archive.org/web/20240929152518/https://www.geeksforgeeks.org/flag-register-8086-microprocessor/
Open In App

Flag register of 8086 microprocessor

Last Updated : 05 May, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Prerequisite – Flag register in 8085 microprocessor The Flag register is a Special 

Introduction :

The flag register is a 16-bit register in the Intel 8086 microprocessor that contains information about the state of the processor after executing an instruction. It is sometimes referred to as the status register because it contains various status flags that reflect the outcome of the last operation executed by the processor.

The flag register is an important component of the 8086 microprocessor because it is used to determine the behavior of many conditional jump and branch instructions. The various flags in the flag register are set or cleared based on the result of arithmetic, logic, and other instructions executed by the processor.

The flag register is divided into various bit fields, with each bit representing a specific flag. Some of the important flags in the flag register include the carry flag (CF), the zero flag (ZF), the sign flag (SF), the overflow flag (OF), the parity flag (PF), and the auxiliary carry flag (AF). These flags are used by the processor to determine the outcome of conditional jump instructions and other branching instructions.

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 register There 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:

  1. Sign Flag (S)
  2. Zero Flag (Z)
  3. Auxiliary Carry Flag (AC)
  4. Parity Flag (P)
  5. Carry Flag (CY) These first five flags are defined here
  6. 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)
  1. 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:

  1. 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.
  2. 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.
  3. 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.

Uses of Flag register in 8086 microprocessor :

The flag register in the 8086 microprocessor has several important uses, including:

  1. Conditional branching: The flags in the flag register can be used to control conditional branching in assembly language programming. Conditional jump instructions allow a program to take different paths based on the state of the flags in the flag register.
  2. Arithmetic and logic operations: The flag register is used to store the results of arithmetic and logic operations. The flags in the flag register provide information about the outcome of these operations, such as whether a result is negative or zero, or whether there was an overflow or carry.
  3. Error detection and handling: The flag register can be used to detect errors and exceptions, such as overflow or divide-by-zero errors. This allows programs to handle these errors gracefully and to take appropriate corrective action.
  4. Debugging: The flag register provides a convenient way to access important information about the status of the processor after executing an instruction. This information can be used to debug programs and to optimize performance.
  5. Optimization: The flag register can be used to optimize the performance of assembly language programs by avoiding unnecessary instructions or reducing the number of conditional jumps required.

Advantages :

The flag register in the 8086 microprocessor provides several advantages, including:

  1. Efficient conditional branching: The flag register enables efficient conditional branching in assembly language programming. Programmers can use conditional jump instructions to make decisions based on the state of the flags in the flag register, allowing for more efficient and optimized code.
  2. Improved arithmetic and logic operations: The flag register is used to store the results of arithmetic and logic operations, allowing for more complex calculations to be performed efficiently. The various flags in the flag register provide information about the outcome of these operations, such as whether a result is negative or zero, or whether there was an overflow or carry.
  3. Easy access to processor status information: The flag register provides a convenient way to access important information about the status of the processor after executing an instruction. This information can be used to debug programs and to optimize performance.
  4. Improved error handling: The flag register can be used to detect errors and exceptions, such as overflow or divide-by-zero errors. This allows programs to handle these errors gracefully and to take appropriate corrective action.

Dis-advantages :

There are not many disadvantages of the flag register in the 8086 microprocessor, but some potential drawbacks include:

  1. Limited number of flags: The 8086 flag register has a limited number of flags, which can make it difficult to handle complex calculations or to detect certain types of errors or exceptions.
  2. Limited precision: The flags in the flag register are often limited in precision, which can lead to inaccuracies or errors in certain types of calculations or operations.
  3. Difficulty in understanding and using: The flag register can be difficult for beginners to understand and use effectively, which can lead to mistakes or errors in programming.
  4. Overhead in execution time: Accessing the flag register can add overhead to program execution time, which can impact performance in certain types of applications.

Previous Article
Next Article

Similar Reads

Auxiliary Carry Flag in 8086 Microprocessor
Auxiliary Carry Flag (AF) is one of the six status flags in the 8086 microprocessor. This flag is used in BCD (Binary-coded Decimal) operations.The status of this flag is updated for every arithmetic or logical operation performed by ALU.This flag is set to one if there is a CARRY from the lower nibble or BORROW for the lower nibble in binary repre
1 min read
8085 program to access and exchange the content of Flag register with register B
Problem - Write an assembly language program in 8085 microprocessor to access Flag register and exchange the content of flag register F with register B. Example - Assumptions - Initial values of flag register, register B and stack pointer are is 00, 3F, and 3FFF respectively. PSW stands for PROGRAM STATUS WORD. PSW combines accumulator A and flag r
3 min read
Flag register in 8085 microprocessor
In the 8085 microprocessor, the Flag Register is a kind of 8-bit register comprising five flags that indicate the results from arithmetic and logical operations. These flags include the Sign flag, indicating whether the result is negative; the Zero flag, set in case the result is zero; the Auxiliary Carry flag used in BCD operations; the Parity fla
9 min read
8085 program to find 2's complement of the contents of Flag Register
Problem – Write an assembly language program in 8085 microprocessor to find 2's complement of the contents of Flag Register. Example - Algorithm – Initialize the value of Stack Pointer (SP) to 3999 Push the contents of PSW (Register pair formed by Accumulator and Flag Register) into the memory stack Pop the contents from the stack into register pai
2 min read
Register content and Flag status after Instructions
Basically, you are given a set of instructions and the initial content of the registers and flags of 8085 microprocessor. You have to find the content of the registers and flag status after each instruction. Initially, Below is the set of the instructions: SUB A MOV B, A DCR B INR B SUI 01H HLT Assumption: Each instruction will use the result of th
3 min read
Arithmetic instructions in 8086 microprocessor
Arithmetic Instructions are the instructions which perform basic arithmetic operations such as addition, subtraction and a few more. Unlike in 8085 microprocessor, in 8086 microprocessor the destination operand need not be the accumulator. Following is the table showing the list of arithmetic instructions: OPCODE OPERAND EXPLANATION EXAMPLE ADD D,
2 min read
Logical instructions in 8086 microprocessor
Introduction : Logical instructions in the 8086 microprocessor are instructions that perform logical operations on data stored in registers or memory locations. These instructions can manipulate bits within a byte, set or clear individual bits, or perform Boolean operations such as AND, OR, XOR, and NOT. Some of the commonly used logical instructio
5 min read
Data transfer instructions in 8086 microprocessor
Introduction : Data transfer instructions in the 8086 microprocessor are used to move data between memory locations, registers, and input/output (I/O) devices. These instructions are essential for manipulating data within a program, as well as for communicating with external devices. Data transfer instructions are a fundamental part of programming
4 min read
Reset Accumulator (8085 & 8086 microprocessor)
1. Problem - Write the 8085 instructions which reset the accumulator. Solution - There are 4 instructions to reset the accumulator in 8085. These instructions are: S.No.MNEMONICSCOMMENT1MVI A, 00A <- 002ANI 00A AND 003XRA AA XOR A4SUB AA <- A - A Explanation - MVI A, 00: instruction copies 00 to A.ANI 00: instruction performs bit by bit AND o
4 min read
Process control instructions in 8086 microprocessor
Process control instructions are the instructions which control the processor's action by setting(1) or resetting(0) the values of flag registers. Following is the table showing the list of process control instructions: OPCODEOPERANDEXPLANATIONEXAMPLESTCnonesets carry flag to 1STCCLCnoneresets carry flag to 0CLCCMCnonecompliments the carry flagCMCS
1 min read
Memory Segmentation in 8086 Microprocessor
Prerequisite - Segmentation Segmentation is the process in which the main memory of the computer is logically divided into different segments and each segment has its own base address. It is basically used to enhance the speed of execution of the computer system, so that the processor is able to fetch and execute the data from the memory easily and
3 min read
Addressing modes in 8086 microprocessor
Prerequisite - Addressing modes, Addressing modes in 8085 microprocessor The way of specifying data to be operated by an instruction is known as addressing modes. This specifies that the given data is an immediate data or an address. It also specifies whether the given operand is register or register pair. Types of addressing modes: Register mode -
2 min read
Program execution transfer instructions in 8086 microprocessor
Prerequisite - Branching instructions in 8085 microprocessor Program execution transfer instructions are similar to branching instructions and refer to the act of switching execution to a different instruction sequence as a result of executing a branch instruction. The two types of program execution transfer instructions are: Unconditional Conditio
3 min read
Interrupts in 8086 microprocessor
An interrupt is a condition that halts the microprocessor temporarily to work on a different task and then returns to its previous task. An interrupt is an event or signal that requests the CPU's attention. This halt allows peripheral devices to access the microprocessor. Whenever an interrupt occurs, the processor completes the current instruction
3 min read
Bus Cycles of 8086 Microprocessor
The bus cycle is also named as machine cycle. Bus cycle of 8086 is used to access memory, peripheral devices (Input/Output devices), and Interrupt controller. Bus cycle corresponds to a sequence of events that starts with an address being output on system address bus followed by a write or read data transfer. During these operations, a series of co
2 min read
Minimum mode configuration of 8086 microprocessor (Min mode)
Overview : The 8086 microprocessor operates in minimum mode when MN/MX' = 1.In minimum mode,8086 is the only processor in the system which provides all the control signals which are needed for memory operations and I/O interfacing.Here the circuit is simple but it does not support multiprocessing.The other components which are transceivers, latches
5 min read
Difference Between Minimum Mode and Maximum Mode in 8086 Microprocessor
Introduction : In the 8086 microprocessor, there are two modes of operation: minimum mode and maximum mode. Minimum mode is used when the 8086 microprocessor is operating as a standalone processor without any external coprocessors or support chips. In this mode, the 8086 uses a single 8-bit bus for both data and instructions, and a single 20-bit ad
3 min read
String manipulation instructions in 8086 microprocessor
In this Article, We will be going through the String Manipulation Instruction, We will start our Article with the Introduction of the String Manipulation Instruction in the 8086, Then We will go through the different String Manipulation Instructions with some Examples, and At last, we will conclude our Article with Some FAQs. What are String Manipu
5 min read
Immediate Addressing Mode in 8086 Microprocessor
Immediate addressing mode in 8086 microprocessor contains the instruction where the first operand may be a register or memory location and the second operand is an immediate value that represents the operand. In this article, we will explore the immediate addressing mode in detail along with the examples of immediate addressing mode. Also, we will
4 min read
Types of Registers in 8086 Microprocessor
A microprocessor is a register-based clock-driven digital device that is used for data processing. It is a multipurpose device that is capable of producing outputs when provided binary data as input. In computers, the microprocessor is like the brain, handling tasks and calculations. Inside the microprocessor are tiny storage units called registers
7 min read
Maximum mode configuration of 8086 microprocessor (Max mode)
The 8086 microprocessor is an 8-bit/16-bit microprocessor designed by Intel in the late 1970s. It is the first member of the x86 family of microprocessors, which includes many popular CPUs used in personal computers. The architecture of the 8086 microprocessor is based on a complex instruction set computer (CISC) architecture, which means that it s
4 min read
General purpose registers in 8086 microprocessor
It is one of the most important chips ever created due to its part in the development of x86-based architecture. One significant aspect of this microprocessor is that it contains general registers. Efficiency and speed of computations in the processor are influenced by these registers since they determine arithmetic operations execution and data ma
6 min read
Pin diagram of 8086 microprocessor
The 8086 chip, presented by Intel in 1978, is a critical part in the development of processing innovation. Its pin outline is a basic part of figuring out its design and usefulness. The pin chart gives a visual portrayal of the chip's outer associations and their individual capabilities, including power supply, ground, information, address, and con
8 min read
Differences between 8085 and 8086 microprocessor
A Microprocessor is an important part of a computer architecture without which you will not be able to perform anything on your computer. It is a programmable device that takes in input performs some arithmetic and logical operations over it and produces the desired output. As famous processors, there are 8085 and 8086 microprocessors made by Intel
7 min read
Difference between Register Mode and Register Indirect Mode
In the computer system, addressing modes refer to how the operands of an instruction is located or accessed. There are two critical addressing modes namely the Register Mode and Register Indirect Mode. These modes are often used to address data present in the registers in the course of running of programs. In this article, we will define concepts o
5 min read
Register indirect addressing mode in 8085 Microprocessor
Register indirect mode in 8085 microprocessors is an addressing mode in which the address part of the instruction specifies the address of the register, and the register holds the effective address of the operand. The operand is present in the effective address specified by the register. In this article, we will explore register indirect addressing
4 min read
8086 program to sort an integer array in ascending order
Problem - Write a program in 8086 microprocessor to sort numbers in ascending order in an array of n numbers, where size “n” is stored at memory address 2000 : 500 and the numbers are stored from memory address 2000 : 501. Example - Example explanation: Pass-1: F9 F2 39 05 F2 F9 39 05 F2 39 F9 05 F2 39 05 F9 (1 number got fix) Pass-2: F2 39 05 F9 3
3 min read
8086 program to divide a 16 bit number by an 8 bit number
Problem - Write an assembly language program in 8086 microprocessor to divide a 16 bit number by an 8 bit number. Example - Algorithm - Assign value 500 in SI and 600 in DI Move the contents of [SI] in BL and increment SI by 1 Move the contents of [SI] and [SI + 1] in AX Use DIV instruction to divide AX by BL Move the contents of AX in [DI]. Halt t
2 min read
8086 program to subtract two 16-bit numbers with or without borrow
Problem - Write a program to subtract two 16-bit numbers where starting address is 2000 and the numbers are at 3000 and 3002 memory address and store result into 3004 and 3006 memory address. Example - Algorithm - Load 0000H into CX register (for borrow) Load the data into AX(accumulator) from memory 3000 Load the data into BX register from memory
2 min read
8086 program to add two 16-bit numbers with or without carry
Problem - Write a program to add two 16-bit numbers where starting address is 2000 and the numbers are at 3000 and 3002 memory address and store result into 3004 and 3006 memory address. Example - Algorithm - Load 0000H into CX register (for carry) Load the data into AX(accumulator) from memory 3000 Load the data into BX register from memory 3002 A
2 min read