0% found this document useful (0 votes)
35 views17 pages

Processor Status, Flags

Flags in CO&AL

Uploaded by

muzammilsohail76
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)
35 views17 pages

Processor Status, Flags

Flags in CO&AL

Uploaded by

muzammilsohail76
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
You are on page 1/ 17

Computer Organization &

Assembly Language

6– Processor Status & Flags


The FLAG Register
 Nine individual bits called as flag are used to
 represent the 8086 processor state.
 Flags are placed in FLAG Register.
 Two types of flags:
 Status Flags: Reflects the result of a computation. Located in
bits: 0, 2, 4, 6, 7 and 11.
 Control Flags: Used to enable/disable certain operations of the
processor. Located in bits 8, 9 and 10.
The Status Flags
Carry Flag:
 Set (CY), Unset (NC)
 This flag is set to 1 when there is an unsigned overflow. For example when you add
bytes 255 + 1 (result is not in range 0...255). When there is no overflow this flag is
set to 0.
 The Carry Flag is set to 1 when there is a carry out from MSB on addition
or there is a borrow into the MSB on subtraction. Also affected by shift and
rotate instructions.
 Examples:
 0FFh + 11h = 110h
 1000 0001b – 1000 0010b = 11111111b
2. Parity Flag:
– Set (PE), Unset (PO)
– This flag is set to 1 when there is even number of one bits in result, and
to 0 when there is odd number of one bits. Even if result is a word only 8
low bits are analyzed!
– PE (Even Parity): If the low byte of a result has an even number of one
bits. For Even parity, PF =1
– PO (Odd Parity): If the low byte of a result has odd number of one bits.
For Even parity, PF = 0
– Examples:
– 1000 0001b – 1000 0010b = 11111111b (Number of one’s in result = 8,
so PF = 1)
3. Auxiliary Carry Flag:
– Set (AC), Unset (NA)
– set to 1 when there is an unsigned overflow for low nibble (4 bits).
– The Auxiliary Carry Flag is set to 1 if there is a carry out from bit 3
on addition, or a borrow into bit 3 on subtraction.
– Used in Binary Coded Decimal (BCD) Operations.
– Examples
– 1000 0001b – 0000 0010b = 01111111b (Borrow from bit 4 to bit 3)
4. Zero Flag:
– Set (ZR), Unset (NZ)
– set to 1 when result is zero. For none zero result this flag is set to 0.
– Zero Flag is set when the result is zero.
– Zero Flag is unset when result is non zero.
– Examples:
0FFh – 0FFh = 00h
5. Sign Flag:
Set to 1 when result is negative. When result is positive it is set
to 0. Actually this flag take the value of the most significant bit.
– Set when MSB of a result is 1; it means the result is negative
(signed interpretation)
– Unset when MSB is 0 i.e. result is positive.
– Examples:
0FFh – 0FFh = 00h (MSB = 0, PF = 0)
6. Overflow Flag:
– Set (OV), Unset (NV)
– set to 1 when there is a signed overflow. Set if signed overflow occurred,
otherwise it is 0.
Examples
If the sum of two numbers with the sign bits off yields a result number with the sign
bit on, the "overflow" flag is turned on. 0100 + 0100 = 1000 (overflow flag is
turned on)
If the sum of two numbers with the sign bits on yields a result number with the sign
bit off, the "overflow" flag is turned on. 1000 + 1000 = 0000 (overflow flag is
turned on)
• The Processor sets:
– Overflow Flag = 1 for Signed Overflow
– Carry Flag = 1 for Unsigned Overflow
• Unsigned Overflow:
– Addition: Carry out from MSB
– The correct Answer is largest than the biggest unsigned
number FFFFh for a word and FFh for a byte.
– Subtraction: Borrow into MSB
• Signed Overflow:
– Addition: Same sign but sum has a different sign (e.g.:
when you add two positive numbers and answer is
negative)
– Subtraction: If result has different sign than expected
Control Flags
1.Direction Flag: Controls the assumed direction used by string
processing instructions. 1=Up, 0=Down. This is directional flag.
This is used in string related operations. D = 1, then the string will be
accessed from higher memory address to lower memory address,
and if D = 0, it will do the reverse
2.Interrupt Flag: Enable/Disable external interrupt.
3.Trap Flag: Determines whether or not CPU will be halted after
each instruction

You might also like