You are on page 1of 16

Flags in Assembly Language

Rehmat Ullah
Flag Register in 8086
● A flag is a flip flop which indicates some conditions produced by the
execution of an instruction or controls certain operations ot the Execution
Unit (EU).
● It is a 16 bit register.
● Flag register is divided into useful/active and undefined bits.
● There are total 9 useful bits.
■ Further divided into:
● 6 status flags which contains some conditions
● 3 control flags enable or disable certain operations of the microprocessor.
● There are total 7 undefined/unused bits represented by x
Flag Register in 8086
Status Flags
● Carry Flag (CF)
● Parity Flag (PF)
● Auxiliary Flag (AF)
● Zero Flag (ZF)
● Sign Flag (OF)
Control Flags
● Direction Flag (DF)
● Trap Flag (TF)
● Interrupt Flag (IF)
Flag Register in 8086
Flag Register in 8086
Carry Flag (CF):
● CF will be on when last carry out occur from MSB during some calculation or
when Cout=1 , CF will be on.
● CF will be on when the borrow occur on MSB during some calculation
● Otherwise CF will be off.
● Sub 7591h, 8248h
❖ Suppose al=EFh and bI= 18h
Last Carry out = 1 0001 1000 CF = 1
0000 0111
1110 1111
Parity Flag
● When there are even no of 1’s in the lower byte then Parity flag will be on.
● When there are odd no of 1’s in the lower byte then Parity flag will be off.
● FE sum 97

1 0010101

Total 1’s = 4
Since 4 is even so, PF=1
Parity Flag (PF) in 8086
● Suppose cx= 7591h and dx 8248h
● Borrow

● Borrow occurs on MSB, so CF=1


● Since there are odd no 0f 1’s, so PF=0
● Suppose al= 89h and bl=48h
Auxiliary Flag (AF) in 8086
When carry or borrow occurs on 4th bit or carry comes out from 4th bit in half lower byte
(1 nibble then AF will be on otherwise AF will be off.

Total 1’s =4
Since 4 is even so PF =1
As carry occurs on 4th bit, so AF=1
Zero Flag (ZF) in 8086
● When the result is zero, ZF will be on
● When the result is not zero, ZF will be off

Since result is zero, so ZF=1


Sign Flag (SF) in 8086

● If the MSB of the result is 1 then SF will be on


● If the MSB of the result is 0 then SF will be off
Overflow Flag (OF) in 8086

There are two types of overflow in 8086:


● Signed overflow
● Unsigned Overflow
Overflow Flag (OF) in 8086

Since Cin = Cout, so OF=0


Direction, Interrupt and Trap Flag
❖ Direction Flag (DF) - It is used with string operations. When set, it causing
string instructions to auto - decrement or to process strings from right to left.

● For example, Assembly. (Default direction: Left to Right)


● Wiren DF=1 then string will be printed from right to left direction. So,
vIbmessA will be printed.
● When DF=0 then string will be printed from left to right direction. So,
Assembly will be printed
Interrupt Flag (IF) in 8086

● If interrupt flag is on, the microprocessor will recognize interrupt requests


from the peripherals.
● If interrupt flag is off, the microprocessor will not recognize any interrupt
requests and will ignore them.
Trap Flag (TF) in 8086

● Trap/Single-step flag (TF) -put 8086 in the single step mode.


● When we do single step debugging then TF=1 otherwise TF=0.

You might also like