0% found this document useful (0 votes)
50 views

Lecture-3 (Microprocessor Internal Architectres - Flag) NOTES

The 8086 flag register is a 16-bit register that stores status and control flags. It contains 6 status flags that are set or reset based on arithmetic/logical operations to indicate values like zero, carry, sign, and overflow. It also contains 3 control flags that control operations like interrupts and instruction processing direction. Common status flags include the carry flag, zero flag, and sign flag that are useful for conditional operations.

Uploaded by

LHK
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Lecture-3 (Microprocessor Internal Architectres - Flag) NOTES

The 8086 flag register is a 16-bit register that stores status and control flags. It contains 6 status flags that are set or reset based on arithmetic/logical operations to indicate values like zero, carry, sign, and overflow. It also contains 3 control flags that control operations like interrupts and instruction processing direction. Common status flags include the carry flag, zero flag, and sign flag that are useful for conditional operations.

Uploaded by

LHK
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

8086 Flag Register

Dept. of Computer Science and Engineering


BRAC University
CSE 341 Team
Lecture References:
� Book:
� Microprocessors and Interfacing: Programming and Hardware,
Chapter # 2, Author: Douglas V. Hall

2 CSE – 341: Microprocessors


BRAC University
8086 Flag Register
� 16-Bit register
• 7 bits are undefined/unused (marked by red x in the
figure below)
• 6 status/condition flags (marked by blue circles)
• 3 control flags (those in grey boxes)
� The condition flags are set (1) or reset (0) depending on the
result of an arithmetic/logical operation.
� Control flags control the operations of the CPU
Bit Positions
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

3 CSE – 341: Microprocessors


BRAC University
Status Flags

Flags are useful in programming e.g. when writing conditions such as:
• If answer is zero, do … else …. // zero flag comes in hand here
• If answer is less than zero, do … else …. // sign flag can be used here

4 CSE – 341: Microprocessors


BRAC University
Status Flags
� Carry Flag (CF) - is set to ’1’ when there is an unsigned overflow.

E.g. when you add bytes 255 + 1 (result is not in range 0...255).

When there is no overflow this flag is reset to 0.

� Parity Flag (PF) - set to ’1’ when there is even number of one bits

in result, and reset to ’0’ when there is odd number of one

bits. Even if result is a word only lower 8 bits are analyzed!

� Auxiliary Flag (AF) - set to ’1’  when there is an unsigned

overflow for low nibble (4 bits). 


5 CSE – 341: Microprocessors
BRAC University
Status Flags
� Zero Flag (ZF) - set to ’1’  when result is zero. For non-zero result

this flag is reset to ’0’.

� Sign Flag (SF) - set to ’1’ when result is negative. When result

is positive it is reset to ‘0’. (This flag takes the value of the most

significant bit). 

� Overflow Flag (OF) - set to ’1’ when there is a signed overflow.

For example, when you add bytes 100 + 50.

6 CSE – 341: Microprocessors


BRAC University
NB:
OF is set to 1 if there is a carry from:
• the 7th bit to the 8th bit ONLY or
• from the 8th bit to the 9th bit ONLY
Status Flags If there is a carry from the 7th bit to the 8th bit and from the 8th bit to the 9th
bit at THE SAME TIME then OF = 0

OF=1 AF=0
Set because there is a carry from the 7th bit to the 8th bit Reset because there is NO carry from the
ONLY lower nibble to the upper nibble
Carry 1 1 1

� MOV AL, 50
50h ( 0 1 0 1 0 0 0 0 )
� MOV BL, 32h
32 ( 0 0 1 1 0 0 1 0 )
� ADD AL, BL (x 1 0 0 0 0 0 1 0 )
ZF=0
CF=0 Reset because the answer is NOT zero
Reset because the answer has NO carry
PF=1
Set because the answer has an EVEN
SF=1 number of 1s
Set because the MSB is 1 indicating a
negative answer

7 CSE – 341: Microprocessors


BRAC University
NB:
OF is reset to 0 if:
• there is a carry from the the 7th bit to the 8th bit and from the 8th bit to the
9th bit at THE SAME TIME or
Status Flags • there is NO carry from the the 7th bit to the 8th bit and from the 8th bit to
the 9th bit at THE SAME TIME

OF=0
Reset because there is a carry from the 7th bit to the 8th
bit and from the 8th bit to the 9th bit at THE SAME
TIME

Carry 1 1 1 1 1 1 1 1 AF=1
Set because there IS a carry from the
lower nibble to the upper nibble

� MOV AL, FFh 1 1 1 1 1 1 1 1


� MOV BL, 01h 0 0 0 0 0 0 0 1
� ADD AL, BL 1 0 0 0 0 0 0 0 0
ZF=1
CF=1 Set because the answer IS zero
Set because the answer has a carry
PF=1
SF=0 Set because the answer has an EVEN
Reset because the MSB is 0 indicating a number of 1s
positive answer

8 CSE – 341: Microprocessors


BRAC University
Control Flags:

9 CSE – 341: Microprocessors


BRAC University
Control Flags:
� Trap Flag (TF) - Used for on-chip single-step debugging.

� Interrupt enable Flag (IF) - when this flag is set


to ’1’ CPU reacts to interrupts from external devices.
� Direction Flag (DF) - this flag is used by some
instructions to process data chains, when this flag is set
to ’0’ - the processing is done forward, when this flag is
set to ‘1’ the processing is done backward.

10 CSE – 341: Microprocessors


BRAC University
Quiz: Status Flag Values?

� MOV AX, ABCDh

� MOV BX, 9876h

� ADD AX, BX

11 CSE – 341: Microprocessors


BRAC University
Thank You !!

12 CSE – 341: Microprocessors


BRAC University

You might also like