Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

Chapter 5

By Hasan Murad
Lecturer
CSE,UAP
Chapter Name
• The processor status and the flags register
Why Flags Register?
• Processor can make decision
• Based on Current Status
• 8086 processor Status consists of 9 individual bits called flags
FLAGS Register
Bit Number 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Flags OF DF IF TF SF ZF AF PF CF
Types of Flag
• Classified into two group
• 1. Status Flags
• 2. Control Flags
Status Flag
• The status flags reflect the result of a computation
Bit Number 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Flags OF SF ZF AF PF CF

Bit Name Symbol


0 Carry Flag CF
2 Parity Flag PF
4 Auxiliary Carry Flag AF
6 Zero Flag ZF
7 Sign Flag SF
11 Overflow Flag OF
Control Flag
• The control flags are used for enable or disable certain operations like
Jump Instruction
Bit Number 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Flags DF IF TF

Bit Name Symbol


8 Trap Flag TF
9 Interrupt Flag IF
10 Direction Flag DF
Status Flag
• The status flags reflect the result of a computation
• SUB AX,AX
• ZF(Zero Flag) = 1
Status Flag
• The status flags reflect the result of a computation
Bit Name Symbol
0 Carry Flag CF
2 Parity Flag PF
4 Auxiliary Carry Flag AF
6 Zero Flag ZF
7 Sign Flag SF
11 Overflow Flag OF
Carry Flag(CF)
• CF = 1, if there is a carry out from the most significant(msb) on
addition, or there is a borrow into the msb on subtraction.
• CF = 0, otherwise
• Moreover, CF is also affected by shift and rotate instructions
Parity Flag(PF)
• PF = 1, if the low byte of a result has an even number of one
bits(Even parity)
• PF = 0, otherwise
• Result = FFFEh
• Low Byte = FEh = 11111110b
• PF = 0
Auxiliary Carry Flag(AF)
• AF = 1 if there is a carry out from bit 3 on addition or a borrow into bit
3 on subtraction
• AF is used in BCD operations
Zero Flag(ZF)
• ZF = 1 for a zero result
• ZF = 0 fro nonzero result
Sign Flag(SF)
• SF =1 if the msb of a result is 1, it means result is negative
• SF = 0, otherwise
Overflow(OF)
• OF = 1 if signed overflow occurred
• OF = 0, otherwise
Overflow
• Signed number range of 16 bit word: -32768 to 32767
• Signed number range of 8 bit byte: -128 to 127
• Unsigned number range of 16 bit word: 0 to 65535
• Unsigned number range of 8 bit byte: 0 to 255
• If the result of an operation falls outside these ranges, overflow
occurs.
Types of Overflow
• No overflow
• Signed overflow only
• Unsigned overflow only
• Both Signed overflow
No Overflow

AX 0000 0000 0000 0001


BX 0000 0000 0000 0010
--------------------------------------
AX 0000 0000 0000 0011
Unsigned Overflow Only

AX 1111 1111 1111 1111


BX 0000 0000 0000 0001
--------------------------------------
AX 1 0000 0000 0000 0000
Unsigned Overflow Only
• Unsigned Case
• AX = FFFFh = 65535
• BX = 0001h = 1
• Resultant AX = 0 (Real Result = 65536)
• Signed Case
• AX = FFFFh = -1
• BX = 0001h = 1
• Resultant AX = 0 (Real Result = 0)
Signed Overflow Only

AX 0111 1111 1111 1111


BX 0111 1111 1111 1111
--------------------------------------
AX 1111 1111 1111 1110
Signed Overflow Only
• Unsigned Case
• AX = 7FFFh = 32767
• BX = 7FFFh = 32767
• Resultant AX = 65536 (Real Result = 65536)
• Signed Case
• AX = 7FFFh = 32767
• BX = 7FFFh = 32767
• Resultant AX = -2 (Real Result = 65536)
Both Signed and Unsigned Overflow
Overflow
• OF =1 if signed overflow
• CF = 1 if unsigned overflow
• Shortcut if the carries into and out of the msb do not match then
OF = 1
How instructions affect the flags
Instruction Affects flags
MOV/XCHG None
ADD/SUB All
INC/DEC All except CF
NEG All

You might also like