Welcome
Group : V
OUR GROUP
Swapnil Saha 151-15-4939
Safayet Hossain 151-15-4938
Md. Shahadat Hoseen 151-15-5187
Fahmida Al Ikra 151-15-5076
Khurshida Jahan 151-15-5190
FLAGS resister
and
Their changes due to
of 8086
What is FLAGS register ??
FLAGS resister:
The FLAGS register is the status register in Intel x86
microprocessors that contains the current state of the processor.
 8086 has 16 flag registers among which 9 are active.
 The purpose of the FLAGS register is to indicate the status of
the processor.
 It does this by setting the individual bits called flags.
Types of FLAGS:
There are two kinds of FLAGS.
1. Status FLAGS
2. Control FLAGS
Types of FLAGS
Status FLAGS :
 Status FLAGS reflect the result of an operation executed by
the processor
Control FLAGS :
 The control FLAGS enable or disable certain operations of
the processor.
FLAG Register Bits
Status Flags
The Carry Flag (CF) :
 CF = 1 if there is a carry out
from the msb (most significant
bit) on addition, or there is a
borrow into the msb on
subtraction.
 CF = 0 otherwise
 CF is also affected by shift and
rotate instructions
Status Flags
The Parity Flag (PF):
PF = 1 if the low byte of
a result has an even
number of one bits (even
parity)
PF = 0 otherwise (odd
parity)
Status Flags
The Auxiliary Carry Flag
(AF):
AF = 1 if there is a carry out from
bit 3 on addition, or there is a
borrow into the bit 3 on
subtraction
AF = 0 otherwise
AF is used in binary-coded decimal
(BCD) operations
Status Flags
The Zero Flag (ZF) :
 ZF = 1 for a zero result
 ZF = 0 for a non-zero result
 In this example the result is not
zero. So ZF=0
Status Flags
The Sign Flag (SF) :
SF = 1 if the msb of a result
is 1; it means the result is
negative if you are giving a
signed interpretation
SF = 0 if the msb is 0
In this Example the msb of
the result is 1. So SF=1
Status Flags
The Overflow Flag (OF):
OF = 1 if signed overflow occurred
OF = 0 otherwise
Overflow flag is 2 types:
1.Signed
2. Unsigned
Control Flags
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.
Interrupt enable Flag (IF):
 when this flag is set to 1 CPU reacts to interrupts from
external devices.
Trap Flag (TF):
Used for on-chip debugging.
How instruction affect the flags
Instruction affect flags
MOV/XCHG none
ADD/SUB all
INC/DEC all except CF
NEG all(CF=1 unless result is 0 ;OF=1 if word
operand is 8000h or byte operand is 80h)

Example1:
ADD AX,BX,where AX contains
FFFFh,BX contains FFFFh.
Solution:
FFFFh
+FFFFh
1FFFEh
The result stored in AX is FFFEh
=1111 1111 1111 1110
Example2:
ADD Al,Bl,where Al contains 80h,Bl contains
80h.
Solution:
80h
+80h
100h
Result stored in Al is 00h.
Example 3:
INC AL , where AL contains FFh.
Solution :
FFh
+ 1h
100h
The result stored in AL is 00h. SF = 0, PF =1, Zf =1. Even though there is a carry out,
CF is unaffected by INC. this means that if CF = 0 before the execution of the
instruction , CF will still be 0 afterward.
OF = 0 because numbers of unlike sign are being added (there is a carry into the
msb and also a carry out ).
Example 4:
MOV AX,-5
Solution:
The result stored in AX is -5=FFFBh.
None of the flags are affected by MOV.
Example 5 :
NEG AX , where AX contains 8000h
Solution :
8000h=1000 0000 0000 0000
One’s complement=0111 1111 1111 1111
+1
1000 0000 0000 0000=8000h
The result stored in AX is 8000h.
SF=1, PF=1 ,ZF=0.
CF=1, because for NEG CF is always 1 unless the result is 0.
OF=1, because the result is 8000h; when a number is negated, we
would expect a sign change, but because 8000h is its own two’s
complement , there is no sign change.
Thanks

assembly flag resister

  • 1.
  • 2.
    OUR GROUP Swapnil Saha151-15-4939 Safayet Hossain 151-15-4938 Md. Shahadat Hoseen 151-15-5187 Fahmida Al Ikra 151-15-5076 Khurshida Jahan 151-15-5190
  • 3.
  • 4.
    What is FLAGSregister ?? FLAGS resister: The FLAGS register is the status register in Intel x86 microprocessors that contains the current state of the processor.  8086 has 16 flag registers among which 9 are active.  The purpose of the FLAGS register is to indicate the status of the processor.  It does this by setting the individual bits called flags.
  • 5.
    Types of FLAGS: Thereare two kinds of FLAGS. 1. Status FLAGS 2. Control FLAGS
  • 6.
    Types of FLAGS StatusFLAGS :  Status FLAGS reflect the result of an operation executed by the processor Control FLAGS :  The control FLAGS enable or disable certain operations of the processor.
  • 8.
  • 9.
    Status Flags The CarryFlag (CF) :  CF = 1 if there is a carry out from the msb (most significant bit) on addition, or there is a borrow into the msb on subtraction.  CF = 0 otherwise  CF is also affected by shift and rotate instructions
  • 10.
    Status Flags The ParityFlag (PF): PF = 1 if the low byte of a result has an even number of one bits (even parity) PF = 0 otherwise (odd parity)
  • 11.
    Status Flags The AuxiliaryCarry Flag (AF): AF = 1 if there is a carry out from bit 3 on addition, or there is a borrow into the bit 3 on subtraction AF = 0 otherwise AF is used in binary-coded decimal (BCD) operations
  • 12.
    Status Flags The ZeroFlag (ZF) :  ZF = 1 for a zero result  ZF = 0 for a non-zero result  In this example the result is not zero. So ZF=0
  • 13.
    Status Flags The SignFlag (SF) : SF = 1 if the msb of a result is 1; it means the result is negative if you are giving a signed interpretation SF = 0 if the msb is 0 In this Example the msb of the result is 1. So SF=1
  • 14.
    Status Flags The OverflowFlag (OF): OF = 1 if signed overflow occurred OF = 0 otherwise Overflow flag is 2 types: 1.Signed 2. Unsigned
  • 15.
    Control Flags 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. Interrupt enable Flag (IF):  when this flag is set to 1 CPU reacts to interrupts from external devices. Trap Flag (TF): Used for on-chip debugging.
  • 16.
    How instruction affectthe flags Instruction affect flags MOV/XCHG none ADD/SUB all INC/DEC all except CF NEG all(CF=1 unless result is 0 ;OF=1 if word operand is 8000h or byte operand is 80h) 
  • 17.
    Example1: ADD AX,BX,where AXcontains FFFFh,BX contains FFFFh. Solution: FFFFh +FFFFh 1FFFEh The result stored in AX is FFFEh =1111 1111 1111 1110
  • 18.
    Example2: ADD Al,Bl,where Alcontains 80h,Bl contains 80h. Solution: 80h +80h 100h Result stored in Al is 00h.
  • 19.
    Example 3: INC AL, where AL contains FFh. Solution : FFh + 1h 100h The result stored in AL is 00h. SF = 0, PF =1, Zf =1. Even though there is a carry out, CF is unaffected by INC. this means that if CF = 0 before the execution of the instruction , CF will still be 0 afterward. OF = 0 because numbers of unlike sign are being added (there is a carry into the msb and also a carry out ).
  • 20.
    Example 4: MOV AX,-5 Solution: Theresult stored in AX is -5=FFFBh. None of the flags are affected by MOV.
  • 21.
    Example 5 : NEGAX , where AX contains 8000h Solution : 8000h=1000 0000 0000 0000 One’s complement=0111 1111 1111 1111 +1 1000 0000 0000 0000=8000h The result stored in AX is 8000h. SF=1, PF=1 ,ZF=0. CF=1, because for NEG CF is always 1 unless the result is 0. OF=1, because the result is 8000h; when a number is negated, we would expect a sign change, but because 8000h is its own two’s complement , there is no sign change.
  • 22.