SlideShare a Scribd company logo
1 of 14
The Processor Status
And The FLAGS Register
Outline
• The FLAGS register
• Overflow
• How instructions affect the flags
• The DEBUG program
2
The FLAGS Register
• In 8086, the processor state is implemented as nine individual
bits called flags
• Each decision made by 8086 is based on the values of these
flags
• The flags are placed in the FLAGS register
• Two types of flags: Status flags and control flags
• Status flags reflect the result of a computation.They are
located in bits 0,2,4,6,7 and 11
• Control flags enable or disable certain operations of the
processor.They are located in bits 8,9 and 10
• The other bits have no significance
3
The FLAGS Register
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OF DF IF TF SF ZF AF PF CF
4
Bit Name Symbol
0 Carry Flag CF
2 Parity Flag PF
4 Auxiliary Carry Flag AF
6 Zero Flag ZF
7 Sign Flag SF
11 Overflow Flag OF
8 Trap Flag TF
9 Interrupt Flag IF
10 Direction Flag DF
Status Flag
Control Flag
The Status Flags
• Carry Flag(CF)
• CF=1 if there is a carry out in the MSB on addition, if there is a borrow into
the MSB on subtraction
• Otherwise CF=0
• It is also affected by shift and rotate instructions
• Parity Flag(PF)
• PF=1 if the low byte of a result has even parity
• PF=0 if the low byte of a result has odd parity
• Auxiliary Carry Flag(AF)
• AF=1 if there is a carry out from bit 3 on addition or a borrow into bit 3 on
subtraction
• Otherwise AF=0
• AF is used in BCD operations
5
The Status Flags
• Zero Flag(ZF)
• ZF=1 for a zero result
• ZF=0 for a non-zero result
• Sign Flag(SF)
• SF=1 if the MSB of a result is 1 that means the result is negative
• SF=0 if the MSB of a result is 0 that means the result is positive
• Overflow Flag(OF)
• OF=1 if signed overflow occured
• OtherwiseOF=0
6
Overflow
• The range of signed numbers that can be represented by a
• 16-bit word is -32768 to 32767
• 8-bit byte is -128 to 127
• The range of unsigned numbers that can be represented by a
• 16-bit word is 0 to 65535
• 8-bit byte is 0 to 255
• If the result of an operation falls out of these ranges then overflow occurs
and the truncated result that is saved will be incorrect
• When we perform an arithmetic operation such as addition there are four
possible outcomes:
• No overflow
• Signed overflow only
• Unsigned overflow only
• Both signed and unsigned overflows
7
Example of Unsigned
Overflow Only
• Suppose AX contains FFFFh(-1), BX contains 0001h(1). Add the
contents of AX and BX
• Solution
ADD AX,BX
• If it is an unsigned interpretation the correct answer
10000h=65535 but this is out of range for a word operation
• A 1 is carried out of the MSB and the answer stored in AX is 0000h
which is wrong so unsigned overflow occurs
• But signed overflow does not occur as the stored answer is
correct as a signed number
8
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Example of Signed
Overflow Only
• Suppose AX contains 7FFFh(32767), BX contains 7FFFh(32767).
Add the contents of AX and BX
• Solution
ADD AX,BX
• If it is a signed interpretation the answer is FFFEh =-2 but this
incorrect as the result should be 65534. So signed overflow occurs
• The unsigned interpretation of FFFEh is 65534, which is the right
answer. So unsigned overflow does not occur
9
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
+ 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
Overflow Indicates by
Processor
• The processor sets OF=1 for signed overflow
• The processor sets CF=1 for unsigned overflow
10
Overflow Occur
Determination by Processor
• Unsigned overflow
• On addition when there is a carry out in the MSB.This means the result
is larger than the biggest unsigned number
• On subtraction when there is a borrow in the MSB.This means the
correct answer is smaller than 0
• Signed overflow
• On addition the numbers with the same sign produces result of
different sign
• On subtraction the result has a different sign than expected
• Subtraction of numbers with different signs means addition of number
with same sign.
11
How Instructions Affect
the Flags
Instruction Affected 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
12
How Instructions Affect the
Flags
• ADD AX,BX where AX contains FFFFh and BX contains FFFFh
• Solution
• The result stored in AX is FFFEh = 1111 1111 1111 1110
• SF=1 because the MSB is 1
• PF=0 because there are odd number of 1 bits in the low byte of the result
• ZF=0 because the result is non zero
• CF=1 because there is a carry out of the MSB on addition
• OF=0 There is a carry into the MSB and also a carry out
13
F F F F h
+ F F F F h
1 F F F E h
Assignment 05
• For each of the following instructions, give the new
destination contents and the new settings of CF,SF,ZF,PF and
OF. Suppose that the flags are initially 0 in each part of this
question
• ADDAX, BX where AX contains 7FFFh and BX contains 0001h
• DECAL whereAl contains 00h
• NEG AL whereAL contains 7Fh
• XCHGAX, BX whereAX contains 1ABCh and BX contains 712Ah
14

More Related Content

Similar to Assembly Lab Sheet 5 About Status of Flag Register.pptx

Similar to Assembly Lab Sheet 5 About Status of Flag Register.pptx (20)

assembly flag resister
assembly flag resisterassembly flag resister
assembly flag resister
 
Chap3 8086 artithmetic
Chap3 8086 artithmeticChap3 8086 artithmetic
Chap3 8086 artithmetic
 
8086 ins2 math
8086 ins2 math8086 ins2 math
8086 ins2 math
 
Chapter 3 8086 ins2 math
Chapter 3 8086 ins2 mathChapter 3 8086 ins2 math
Chapter 3 8086 ins2 math
 
Microprocessor.pptx
Microprocessor.pptxMicroprocessor.pptx
Microprocessor.pptx
 
Arithmetic instrctions
Arithmetic instrctionsArithmetic instrctions
Arithmetic instrctions
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
 
8086 Microprocessor
8086 Microprocessor8086 Microprocessor
8086 Microprocessor
 
Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)
 
Hemanth143
Hemanth143 Hemanth143
Hemanth143
 
Arithmetic instructions
Arithmetic instructionsArithmetic instructions
Arithmetic instructions
 
8086 Instruction set
8086 Instruction set8086 Instruction set
8086 Instruction set
 
Arithmetic and logical instructions set
Arithmetic and logical instructions setArithmetic and logical instructions set
Arithmetic and logical instructions set
 
Notes arithmetic instructions
Notes arithmetic instructionsNotes arithmetic instructions
Notes arithmetic instructions
 
Microprocessor and assambly language programming
Microprocessor and assambly language programmingMicroprocessor and assambly language programming
Microprocessor and assambly language programming
 
Assembly language.pptx
Assembly language.pptxAssembly language.pptx
Assembly language.pptx
 
8086inst logical
8086inst logical8086inst logical
8086inst logical
 
8086 Register organization and Architecture details
8086 Register organization and Architecture details8086 Register organization and Architecture details
8086 Register organization and Architecture details
 
8086 microprocessor assembler directives.ppt
8086   microprocessor assembler directives.ppt8086   microprocessor assembler directives.ppt
8086 microprocessor assembler directives.ppt
 
Microprocessor Based Design and operations
Microprocessor Based Design and operationsMicroprocessor Based Design and operations
Microprocessor Based Design and operations
 

Recently uploaded

Cybercrimes in the Darknet and Their Detections: A Comprehensive Analysis and...
Cybercrimes in the Darknet and Their Detections: A Comprehensive Analysis and...Cybercrimes in the Darknet and Their Detections: A Comprehensive Analysis and...
Cybercrimes in the Darknet and Their Detections: A Comprehensive Analysis and...
dannyijwest
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
pritamlangde
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
Kamal Acharya
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
HenryBriggs2
 

Recently uploaded (20)

Cybercrimes in the Darknet and Their Detections: A Comprehensive Analysis and...
Cybercrimes in the Darknet and Their Detections: A Comprehensive Analysis and...Cybercrimes in the Darknet and Their Detections: A Comprehensive Analysis and...
Cybercrimes in the Darknet and Their Detections: A Comprehensive Analysis and...
 
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)
 
Adsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) pptAdsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) ppt
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptx
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
 
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdflitvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
 
Post office management system project ..pdf
Post office management system project ..pdfPost office management system project ..pdf
Post office management system project ..pdf
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Compressing and Sparsifying LLM in GenAI Applications
Compressing and Sparsifying LLM in GenAI ApplicationsCompressing and Sparsifying LLM in GenAI Applications
Compressing and Sparsifying LLM in GenAI Applications
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 

Assembly Lab Sheet 5 About Status of Flag Register.pptx

  • 1. The Processor Status And The FLAGS Register
  • 2. Outline • The FLAGS register • Overflow • How instructions affect the flags • The DEBUG program 2
  • 3. The FLAGS Register • In 8086, the processor state is implemented as nine individual bits called flags • Each decision made by 8086 is based on the values of these flags • The flags are placed in the FLAGS register • Two types of flags: Status flags and control flags • Status flags reflect the result of a computation.They are located in bits 0,2,4,6,7 and 11 • Control flags enable or disable certain operations of the processor.They are located in bits 8,9 and 10 • The other bits have no significance 3
  • 4. The FLAGS Register 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 OF DF IF TF SF ZF AF PF CF 4 Bit Name Symbol 0 Carry Flag CF 2 Parity Flag PF 4 Auxiliary Carry Flag AF 6 Zero Flag ZF 7 Sign Flag SF 11 Overflow Flag OF 8 Trap Flag TF 9 Interrupt Flag IF 10 Direction Flag DF Status Flag Control Flag
  • 5. The Status Flags • Carry Flag(CF) • CF=1 if there is a carry out in the MSB on addition, if there is a borrow into the MSB on subtraction • Otherwise CF=0 • It is also affected by shift and rotate instructions • Parity Flag(PF) • PF=1 if the low byte of a result has even parity • PF=0 if the low byte of a result has odd parity • Auxiliary Carry Flag(AF) • AF=1 if there is a carry out from bit 3 on addition or a borrow into bit 3 on subtraction • Otherwise AF=0 • AF is used in BCD operations 5
  • 6. The Status Flags • Zero Flag(ZF) • ZF=1 for a zero result • ZF=0 for a non-zero result • Sign Flag(SF) • SF=1 if the MSB of a result is 1 that means the result is negative • SF=0 if the MSB of a result is 0 that means the result is positive • Overflow Flag(OF) • OF=1 if signed overflow occured • OtherwiseOF=0 6
  • 7. Overflow • The range of signed numbers that can be represented by a • 16-bit word is -32768 to 32767 • 8-bit byte is -128 to 127 • The range of unsigned numbers that can be represented by a • 16-bit word is 0 to 65535 • 8-bit byte is 0 to 255 • If the result of an operation falls out of these ranges then overflow occurs and the truncated result that is saved will be incorrect • When we perform an arithmetic operation such as addition there are four possible outcomes: • No overflow • Signed overflow only • Unsigned overflow only • Both signed and unsigned overflows 7
  • 8. Example of Unsigned Overflow Only • Suppose AX contains FFFFh(-1), BX contains 0001h(1). Add the contents of AX and BX • Solution ADD AX,BX • If it is an unsigned interpretation the correct answer 10000h=65535 but this is out of range for a word operation • A 1 is carried out of the MSB and the answer stored in AX is 0000h which is wrong so unsigned overflow occurs • But signed overflow does not occur as the stored answer is correct as a signed number 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  • 9. Example of Signed Overflow Only • Suppose AX contains 7FFFh(32767), BX contains 7FFFh(32767). Add the contents of AX and BX • Solution ADD AX,BX • If it is a signed interpretation the answer is FFFEh =-2 but this incorrect as the result should be 65534. So signed overflow occurs • The unsigned interpretation of FFFEh is 65534, which is the right answer. So unsigned overflow does not occur 9 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
  • 10. Overflow Indicates by Processor • The processor sets OF=1 for signed overflow • The processor sets CF=1 for unsigned overflow 10
  • 11. Overflow Occur Determination by Processor • Unsigned overflow • On addition when there is a carry out in the MSB.This means the result is larger than the biggest unsigned number • On subtraction when there is a borrow in the MSB.This means the correct answer is smaller than 0 • Signed overflow • On addition the numbers with the same sign produces result of different sign • On subtraction the result has a different sign than expected • Subtraction of numbers with different signs means addition of number with same sign. 11
  • 12. How Instructions Affect the Flags Instruction Affected 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 12
  • 13. How Instructions Affect the Flags • ADD AX,BX where AX contains FFFFh and BX contains FFFFh • Solution • The result stored in AX is FFFEh = 1111 1111 1111 1110 • SF=1 because the MSB is 1 • PF=0 because there are odd number of 1 bits in the low byte of the result • ZF=0 because the result is non zero • CF=1 because there is a carry out of the MSB on addition • OF=0 There is a carry into the MSB and also a carry out 13 F F F F h + F F F F h 1 F F F E h
  • 14. Assignment 05 • For each of the following instructions, give the new destination contents and the new settings of CF,SF,ZF,PF and OF. Suppose that the flags are initially 0 in each part of this question • ADDAX, BX where AX contains 7FFFh and BX contains 0001h • DECAL whereAl contains 00h • NEG AL whereAL contains 7Fh • XCHGAX, BX whereAX contains 1ABCh and BX contains 712Ah 14