2. TABLE OF CONTENT
• Define flag
• Kind of flag
• Status Flag
• Control flag
• Discuss 16bits of flag
• Examples
12/28/2017
Computer organization and Assembly Language
2
3. FLAG REGISTER
• Flag register contains 16 bits that show the status of some activities
• Instructions that involve comparison and arithmetic will change the flag status
4. KINDS OF FLAGS
• The status flags are set/reset depending on the results of some arithmetic or logical
operations during program execution
• The control flags to control the operation of CPU
12/28/2017
Computer organization and Assembly Language
4
5. FLAGS
X X X X OF DF IF TF SF ZF X AF X PF X CF
Bits marks X is
undefined
direction Trap Zero
Auxiliary
parity Carry
interrupt
Sign
overflow
6 are status flags
3 are control flags
12/28/2017 5
8. CARRY FLAG
• When there is last carry out : 1
• When there is not last carry out: 0
12/28/2017
Computer organization and Assembly Language
8
9. ZERO FLAG (ZF)
• Set to 1 when result is 0.
• For non zero result this flag is set to 0.
12/28/2017
Computer organization and Assembly Language
9
10. SIGN FLAG(SF)
• Set to 1 when result is negative.
• When result is positive it is set to 0.
12/28/2017
Computer organization and Assembly Language
10
11. OVERFLOW FLAG(OF)
• When result is to big to fit in the destination: 1
• When result is not to big to fit in the destination: 0
12/28/2017
Computer organization and Assembly Language
11
12. PARITY FLAG(PF)
• 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.
12/28/2017
Computer organization and Assembly Language
12
13. AUXILIARY FLAG(AF)
• Every third bit will handle by Auxiliary flag
• When 3rd bit carry exits: 1
• When 3rd bit carry does not exits: 0
12/28/2017
Computer organization and Assembly Language
13
14. INTERRUPT FLAG(IF)
When interrupt is called : 1
When interrupt is not called : 0
12/28/2017
Computer organization and Assembly Language
14
15. 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.
12/28/2017
Computer organization and Assembly Language
15
16. TRAP FLAG:
• System use it when debugging is required;
• When single step mode( debugging) is needed: 1
• When single step mode( debugging) is not needed: 0
12/28/2017
Computer organization and Assembly Language
16
17. HOW INSTRUCTION EFFECT THE
FLAG
Instructions
MOV/ XCHG
ADD/SUB
INC/DEC
Affect flag
None
All
All except CF
12/28/2017
Computer organization and Assembly Language
17
18. •Example of Zero Flag
12/28/2017 Computer organization and Assembly Language 18
39. SUMMARY
• We have discussed flag register and kinds of flag
• Flag register contains bits that show the status
• 9 of its 16bits indicate the current status of the computer and the
result of processing