0% found this document useful (0 votes)
461 views12 pages

The Processor Status and THR Flags Register

The document discusses the processor status and flag register of the 8086 CPU. It describes the nine flag bits that indicate the processor's current state, including conditional flags like carry, zero, and overflow flags, as well as control flags. Examples are provided to demonstrate how the flags work and how they are set based on the results of arithmetic operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
461 views12 pages

The Processor Status and THR Flags Register

The document discusses the processor status and flag register of the 8086 CPU. It describes the nine flag bits that indicate the processor's current state, including conditional flags like carry, zero, and overflow flags, as well as control flags. Examples are provided to demonstrate how the flags work and how they are set based on the results of arithmetic operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

The Processor Status and the

Flags Register
Bijan Paul
Senior Lecturer
Department of CSE
University of Liberal Arts Bangladesh
Overview
• The circuits in the CPU can perform simple
decision making based on the current state of
the processor
• The processor state is implemented as nine
individual bits called flags
• Each decisions made by the 8086 is based on
the value of these flags
• In the chapter we will study about Flag
registers
Flag Registers of 8086
• Flag register in EU is of 16-bit and is shown in
figure

• Flags Register determines the current state of the


processor.
• 8086 has 9 flags and they are divided into two
categories:
 Conditional Flags(Located in 0, 2, 4, 6, 7, 11)
 Control Flags(Located in 8, 9, 10)
Conditional Flags
 Conditional flags represent result of last arithmetic or logical instruction
executed. Conditional flags are as follows:
• Carry Flag (CF): This flag indicates an overflow condition for unsigned
integer arithmetic.
– The carry flag(CF) is set to 1 if there is a carry out from the most
significant bit(msb) on addition, or there is a borrow into the msb on
subtraction. CF is also affected by shift and rotate instructions
• Auxiliary Flag (AF): If an operation performed in ALU generates a
carry/borrow from lower nibble (i.e. D0 – D3) to upper nibble (i.e. D4 –
D7).
– Set if there was a carry from or borrow to bits 0-3 in the AL register. it
is used to perform Binary to BCD conversion.
• Parity Flag (PF): This flag is used to indicate the parity of result.
– If lower byte 8-bits of the result contains even number of 1’s, the
Parity Flag is set and for odd number of 1’s, the Parity Flag is reset.
Conditional Flags Cont.
• Zero Flag (ZF): ZF=1 for a zero result and ZF=0 for a nonzero result.
• Sign Flag (SF): In sign magnitude format the sign of number is indicated by
MSB bit. If the msb of a result is 1, sign flag is 1; it means the result is
negative.
• Overflow Flag (OF): It occurs when signed numbers are added or
subtracted. An OF indicates that the result has exceeded the capacity of
machine.
– set to 1 when there is a signed overflow. For example, when you add
bytes 100 + 50 (result is not in range -128...127).
– If carries into and out of msb don’t match- that is, there is carry into
the msb but no carry out, or if there is a carry out but no carry in then
overflow occurs and set OF = 1
How The Processor Determines That
Overflow Occurred
• Unsigned Overflow
– Unsigned overflow occurs when there is a carry out of the
msb
– The answer is larger than the biggest unsigned number
– On Subtraction, unsigned overflow occurs when there is a
borrower into the msb
• Signed Overflow
– Signed overflow occurs when the sum has a different sign.
– Add 7FFFh and 7FFFh get FFFFh (negative result)
– In addition of numbers with different signs, overflow us
impossible because a sum like A+(-B) where A and B are
small enough to fit in the destination
Overflow Flag (OF)
• The Overflow Flag (OF)
 OF = 1 if signed overflow occurred
 OF = 0 otherwise
• (Signed) Overflow
 Can only occur when adding numbers of the same sign
(subtracting with different signs)
• Detected when carry into MSB is not equal to carry
out of MSB
 Easily detected because this implies the result has a
different sign than the sign of the operands
Unsigned Overflow
•The carry flag is used to indicate if an unsigned operation overflowed
•The processor only adds or subtracts - it does not care if the data is signed or unsigned!
10010110
+ 11110011
10001001
Carry out = 1
Unsigned overflow occurred
CF = 1 (set)
Overflow Flag (OF)
Signed Overflow Example Examples of No Signed Overflow
10010110 10010110
+ 10100011 + 01100011
00111001 11111001
Carry in = 0, Carry out = 1 Carry in = 0, Carry out = 0
Neg+Neg=Pos Neg+Pos=Neg
Signed overflow occurred No Signed overflow occurred
OF = 1 (set) OF = 0 (clear)
00110110 10010110
+ 01100011 + 11110011
10011001 10001001
Carry in = 1, Carry out = 0 Carry in = 1, Carry out = 1
Pos+Pos=Neg Neg+Neg=Neg
Signed overflow occurred No Signed overflow occurred
OF = 1 (set) OF = 0 (clear)
Example1
• Example1 : Add AX, BX where AX contains FFFFh, BX contains
FFFFh.
Solution: FFFFh 1111 1111 1111 1111
FFFFh + 1111 1111 1111 1111
1 FFFEh 1 1111 1111 1111 1110
The result stored in AX is FFFEh = 1111 1111 1111 1110
SF= 1 because the msb is 1
PF = 0 because there are 7(odd no) of 1 bits in the low byte of the result.
ZF = 0 because the result is nonzero
CF = 1 because out of the msb on is a carry addition
OF = 0 because there is a carry into the msb and also a carry out
Example2
• Example1 : Add AL, BL where AL contains 80h, BL contains
80h.
Solution: 80h 1000 0000
80h + 1000 0000
1 00h 1 0000 0000
The result stored in AL is 00h = 0 000 0000
SF= 0 because the msb is 0
PF = 1 because there are 8(even no) of 1 bits in the low byte of result.
ZF = 1 because the result is zero
CF = 1 because there is a carry out of the msb on addition.
OF = 1 because there is no carry into the msb there is a carry out
Example3
• Example1 : Sub AX, BX where AX contains 8000h, BX contains
0001h.
Solution: 8000h 1000 0000 0000 0000
0001h – 0000 0000 0000 0001
7FFFh 0111 1111 1111 1111 = 7FFFh

SF= 0 because the msb is 0


PF = 1 because there are 8(even no) of 1 bits in the low byte of result.
ZF = 0 because the result is nonzero
CF = 0 because a smaller unsigned number is being subtracted from a larger
one.
OF = 1

You might also like