Flag register of 8086

Flag register of 8086 is a 16-bit register where status of the latest Arithmetic operation performed.

flag register of 8086
flag register of 8086

As it has 16-bits , it has 16 flags. These 16 flags are classified as

  • 7 are don’t care flags.
  • 3 are control flags ( accessible to programmers ).
  • 6 are status flags ( not accessible to programmers ).

Status flags:

CF:

It stands for carry flag. 

If CF = 1 ; it means carry is generated from the MSB.

If CF = 0 ; no carry is generated out of MSB.

CF flag of flag register of 8086

PF:

It stands for parity flag. 

If PF = 1 ; it means it is even parity in the result ( there are even numbers of 1’s ).

If PF = 0 ; it means it is odd parity.

PF flag of flag register of 8086

In example 1, there are 4 ones’ which is even , in the second example there are 5 ones’ which is odd in count.

AF:

AF stands for auxiliary flag. As 8-bits form a byte, similarly 4 bits form a nibble. So in 16 bit operations there are 4 nibbles.

If AF = 1 ; there is a carry out from lower nibble.

If AF = 0 ;no carry out of lower nibble.

AF flag in flag register of 8086

ZF:

This is zero flag. Whenever the output is 0 this flag is 1.

If ZF = 1 ; output is zero.

If ZF = 0 ; output is non zero.

OF:

OF stands for overflow flag.

The are two types of numbers 

  • Signed
  • Unsigned

Unsigned:

This is a 8 bit positive number which ranges from 0 to 255. In hexadecimal it’s range is from 00 to FF. In the OF flag, it has nothing to do with unsigned numbers. Only signed numbers are considered in the OF flag.

Signed:

  This is also a 8-bit number( can be 16-bit too ) which is equally distributed among +ve and -ve numbers. By considering MSB , it is decided whether it is a positive or negative number. If MSB=1 , it is a negative number or else negative number.

Eg: 1011 0011 is -ve 

      0111 1001 is +ve

So it’s positive range is from 0 to 127 [ 00 to 7F (in hexadecimal ) ], it consists of 128 +ve values.

It also has 128 negative numbers ranging from -1 to -128 [ -01 to -80 ( in hexadecimal ) ].

Whenever a negative number is saved, it is saved as it’s  2’s complement. To access the number we have to make its 2’s complement again. A number is considered as negative whenever its MSB is 1, and its 2’s complement is the actual negative number.

For eg: 1011 0011

It is a negative number and its 2’s complement is 0100 1101, which is equivalent

to 4D ( hexadecimal ) . so it is -4DH.

So there is a well defined limit for signed numbers ( 00 to 7F and -01 to 80 ). If the result or operands exceeds the limit, it is known as overflow. If there is overflow, then the MSB would show incorrect values, if there is overflow then

MSB = 1 , then it is +ve number

MSB = 0 , then it is -ve number. This is the reverse with the original case. 

How does the processor come to know about overflow ?

XOR operation is performed on C6 and C7 carry. C0 is carried from 0th bit to 1st bit and so on. If the XOR operation gives output as 1, then the operation is going out of the limit.

SF:

This stands for sign flag. In short it copies the value of MSB. It shows wrong notation in the case of overflow.

CF, AF, PF, ZF, OF, SF , these were status flags, and these keep changing after every arithmetic operation. And these flags are not controlled by the user, these are controlled by the ALU.

Control flag:

There are three types of control flags, and by default all are zero.

TF:

This stands for trap flag. Generally processors give output after the complete program, but when TF = 1, output is given after every instruction.

This is useful to check logical errors, when the program is too long.

TF flag in flag register of 8086

IF:

This is interrupt flag. 

IF = 1, then enable interrupts

IF = 0, then interrupts are disabled. By default interrupts are disabled.

DF:

This stands for direction flag. In the case string operation, by default address keeps incrementing for instruction execution. It means after execution of an instruction, whether the processor should execute next instruction or previous instruction.

If DF = 0 ; address is auto incrementing ( processor executes next instruction ).

If DF = 1 ; address is auto decrementing ( processor executes previous instruction ).

Related topic
Flag register of 8051

Spread knowledge

1 thought on “Flag register of 8086”

Leave a Comment

Your email address will not be published. Required fields are marked *