Flag Register of 8086 Microprocessor

In this article, we are going to study about the one of the registers named flag registers of 8086 microprocessor. We are also going to know where and how to use the Flag register of 8086 microprocessor.

What is Flag Register?

Flag register is one of the special purpose registers. The Flag Register is a 16-bit register and there are only 9 accessible flags on the 8086 microprocessors. Therefore the remaining 7 bits are idle.

With the inclusion of an overflow flag, the condition code flag register is identical to the 8085-flagregister. The flag register's uppermost byte is the control flag register.

It has three flags:

  1. The direction (D) flag
  2. The interrupt (I) flag
  3. The trap flag (T).

Out of the total of 16, there are 9 active flags. The final seven flags with the letter "U" are undefined flags.

There are total of 9 active flags, and they are further divided into two parts namely status flags and control flags. Now, we are going to study briefly about each status flags.

Carry flag

It is set anytime a result's MSB (most significant bit) is carried or borrowed out. For an 8-bit operation, use D7, and for a 16-bit operation, use D15.The result in the ALU will be a maximum of 9 or 17 bits when the microprocessor conducts the addition of two 8- or 16-bit values. Direct copying of the most recent carry created into the carry flag. Similar results are obtained when the microprocessor subtracts (x - y) from two 8-bit or 16-bit values.

The additional borrowing needed to execute subtraction is zero if x y, hence CF = 0.

Additional borrowing is necessary if x y. The result of the subtraction (x - y) will be a negative number represented using the 2's complement method because CF = 1.

Parity flag

Only the 8 LSBs (least significant bits) of the 8 or 16-bit result are stored in the parity flag when the microprocessor executes an arithmetic or logical operation in the ALU.

Auxiliary Carry flag

This flag is used to signify a decimal number in binary code but is inaccessible to programmers.

Zero flag

When the microprocessor's ALU completes an arithmetic or logical operation and all 8 or 16 LSBs of the result are zero, ZF = 1. If the ALU's 8-bit or 16-bit result is not zero, ZF = 0. Additionally, whenever a certain register becomes zero as a result of an action, this flag is set.

Sign flag

When an 8-bit number is subjected to an arithmetic or logical operation by the CPU, the result's MSB (D7 bit) is immediately copied into the sign flag. Like this, the MSBs of the result (D15 bit) are directly duplicated into the sign flag when the CPU executes an arithmetic or logical operation on a 16-bit number. The outcome will be negative if the sign flag is set, while the outcome will be positive otherwise.

Overflow flag

If the result of an arithmetic operation on signed binary numbers performed by the CPU falls inside the range, then OF = 0. OF = 1 if the signed result is out of bounds. The 8-bit signed number range is from +7F to -80H, and the 16-bit signed number range is from +7FFF to -8000H.

Now, let’s discuss about another category that is control flags.

Control flags

Following are the three control flags:

  • Interrupt flag
  • Direction flag
  • Trap flag

Interrupt flag

The hardware interrupt pin INTR can be enabled or disabled using the interrupt flag. When the interrupt flag is set to zero with the CLI (Clear interrupt flag) instruction, the INTR interrupt is disabled.

Direction flag

A block or chain of data is handled by string instructions, and a block of bytes or words is moved from one point in memory to another using the MOV SB/MOV SW instruction

Trap flag

The microprocessor will perform the entire program in one operation, known as a free-running operation if the trap flag is set to zero. The microprocessor will run the program in single-stepping mode if the trap flag is set to one. When debugging software, faults in the program are found using the single-stepping mode.