SlideShare a Scribd company logo
FLAGS
Special Purpose Registers
• IP- the instruction pointer.
• Flags Register - determines the current state of the processor.
• IP register always works together with CS segment register and it
points to currently executing instruction.
• Flags Register is modified automatically by CPU after mathematical
operations, this allows to determine the type of the result, and to
determine conditions to transfer control to other parts of the
program. Generally you cannot access these registers directly
processor status register (or Flags)
• As you may see there are 16 bits in this register, each bit is
called a flag and can take a value of 1 or 0.
processor status register (or Flags)
• Bits of flag register are categorized into two portions
• Status Flags: bit 0, 2, 4, 6 and 11
• Control Flags: bit 8, 9 and 10
• Other bits have no significance
• All flags have specific names, we will call them by its names
processor status register (or Flags)
• Carry Flag (CF) - 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.
• Zero Flag (ZF) - set to 1 when result is zero. For none zero
result this flag is set to 0.
• Sign Flag (SF) - 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.
processor status register (or Flags)
• Overflow Flag (OF) - set to 1 when there is a signed overflow.
For example, when you add bytes 100 + 50 (result is not in
range -128...127).
• 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. Even if result is a word only 8 low bits are
analyzed!
• Auxiliary Flag (AF) - set to 1 when there is an unsigned
overflow for low nibble (4 bits).
processor status register (or Flags)
• 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.
FlagsRegister(StatusRegister)
• A flag is a single bit of information whose meaning
is independent from any other bit
• Each flag has a two-letter symbol
CF - Carry Flag
1. If the result of an arithmetic or shift operation "carries out" a bit from the operand, CF becomes
set
11111111 + 00000001 = 100000000  CF = 1
2. The carry (borrow) flag is also set if the subtraction of two numbers requires a borrow into MSB
subtracted
00000000 - 00000001 = 11111111  CF = 1
• In unsigned arithmetic, watch the carry flag to detect errors.
• In signed arithmetic, the carry flag tells you nothing interesting.
00000000 - 00000001 = 11111111
• unsigned arithmetic => 11111111 = 255 (decimal) => got the wrong answer
• signed arithmetic => 11111111 = -1 (decimal) => got right answer, do not care about
value of CF
OF – Overflow Flag
1. 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  OF = 1
2. 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  OF = 1
3. Otherwise, the overflow flag is turned off.
0100 + 0001 = 0101  OF = 0
0110 + 1001 = 1111  OF = 0
1000 + 0001 = 1001  OF = 0
1100 + 1100 = 1000  OF = 0
• In signed arithmetic, overflow flag on means the answer is wrong - you added two positive
numbers and got a negative, or you added two negative numbers and got a positive.
• In unsigned arithmetic, the overflow flag tells you nothing interesting.
ZF – Zero Flag - set if result is zero; cleared otherwise
add 0, 0  ZF = 1
SF – Sign Flag becomes set when the result of an operation is negative (i.e. MSB of the result is 1)
• all arithmetic operations except multiplication and division
• compare instructions - CMP
• logical instructions - XOR, AND, OR
• TEST instructions (equivalent to AND instructions without storing the result)
sub 00000000, 00000001  11111111  SF = 1
PF – Parity Flag - set if low-order eight bits of result contain an even number of "1" bits; cleared
otherwise
add 11010, 1 (result is 11011  4 bits are ‘1’  PF = 1)
add 11000, 1 (result is 11001  3 bits are ‘1’  PF = 0)
AF – Auxiliary Carry Flag (or Adjust Flag) is set if there is a carry from low nibble (4 bits) to high nibble
or a borrow from a high nibble to low nibble
1111 + 0001 = 10000  AF = 1
first nibble second nibble
ZF, SF, PF, and AF Flags

More Related Content

What's hot

Register transfer and micro operation
Register transfer and micro operationRegister transfer and micro operation
Register transfer and micro operation
Kamal Acharya
 
flag register of 8086
flag register of 8086flag register of 8086
flag register of 8086
asrithak
 
Unit 4 memory system
Unit 4   memory systemUnit 4   memory system
Unit 4 memory systemchidabdu
 
Code Converters & Parity Checker
Code Converters & Parity CheckerCode Converters & Parity Checker
Code Converters & Parity Checker
.AIR UNIVERSITY ISLAMABAD
 
Register & flags
Register & flagsRegister & flags
Register & flags
fazli khaliq
 
8086 String Instructions.pdf
8086 String Instructions.pdf8086 String Instructions.pdf
8086 String Instructions.pdf
A. S. M. Badrudduza
 
Part I:Introduction to assembly language
Part I:Introduction to assembly languagePart I:Introduction to assembly language
Part I:Introduction to assembly languageAhmed M. Abed
 
Fixed point and floating-point numbers
Fixed point and  floating-point numbersFixed point and  floating-point numbers
Fixed point and floating-point numbers
MOHAN MOHAN
 
Logic microoperations
Logic microoperationsLogic microoperations
Logic microoperationsNitesh Singh
 
KARNAUGH MAP(K-MAP)
KARNAUGH MAP(K-MAP)KARNAUGH MAP(K-MAP)
KARNAUGH MAP(K-MAP)
mihir jain
 
review of number systems and codes
review of number systems and codesreview of number systems and codes
review of number systems and codes
srinu247
 
Registers
RegistersRegisters
Registers
Sahil Bansal
 
Mapping
MappingMapping
Register Transfer Language,Bus and Memory Transfer
Register Transfer Language,Bus and Memory TransferRegister Transfer Language,Bus and Memory Transfer
Register Transfer Language,Bus and Memory Transfer
lavanya marichamy
 
Computer instructions
Computer instructionsComputer instructions
Computer instructionsAnuj Modi
 
Parity Generator and Parity Checker
Parity Generator and Parity CheckerParity Generator and Parity Checker
Parity Generator and Parity Checker
Jignesh Navdiya
 
Computer registers
Computer registersComputer registers
Computer registers
DeepikaT13
 
Program control
Program controlProgram control
Program control
Rahul Narang
 

What's hot (20)

Register transfer and micro operation
Register transfer and micro operationRegister transfer and micro operation
Register transfer and micro operation
 
flag register of 8086
flag register of 8086flag register of 8086
flag register of 8086
 
Unit 4 memory system
Unit 4   memory systemUnit 4   memory system
Unit 4 memory system
 
Code Converters & Parity Checker
Code Converters & Parity CheckerCode Converters & Parity Checker
Code Converters & Parity Checker
 
Register & flags
Register & flagsRegister & flags
Register & flags
 
8086 String Instructions.pdf
8086 String Instructions.pdf8086 String Instructions.pdf
8086 String Instructions.pdf
 
Part I:Introduction to assembly language
Part I:Introduction to assembly languagePart I:Introduction to assembly language
Part I:Introduction to assembly language
 
Fixed point and floating-point numbers
Fixed point and  floating-point numbersFixed point and  floating-point numbers
Fixed point and floating-point numbers
 
Logic microoperations
Logic microoperationsLogic microoperations
Logic microoperations
 
KARNAUGH MAP(K-MAP)
KARNAUGH MAP(K-MAP)KARNAUGH MAP(K-MAP)
KARNAUGH MAP(K-MAP)
 
Lecture 09
Lecture 09Lecture 09
Lecture 09
 
review of number systems and codes
review of number systems and codesreview of number systems and codes
review of number systems and codes
 
Registers
RegistersRegisters
Registers
 
Mapping
MappingMapping
Mapping
 
Register Transfer Language,Bus and Memory Transfer
Register Transfer Language,Bus and Memory TransferRegister Transfer Language,Bus and Memory Transfer
Register Transfer Language,Bus and Memory Transfer
 
Assignment on alp
Assignment on alpAssignment on alp
Assignment on alp
 
Computer instructions
Computer instructionsComputer instructions
Computer instructions
 
Parity Generator and Parity Checker
Parity Generator and Parity CheckerParity Generator and Parity Checker
Parity Generator and Parity Checker
 
Computer registers
Computer registersComputer registers
Computer registers
 
Program control
Program controlProgram control
Program control
 

Similar to Flags

Flags register in central processing unit
Flags register in central processing unitFlags register in central processing unit
Flags register in central processing unit
AhsanRazaKolachi
 
Assignment on alp
Assignment on alpAssignment on alp
Assignment on alp
Jahurul Islam
 
8086 Microprocessor
8086 Microprocessor8086 Microprocessor
8086 Microprocessor
Md.Galib Hossain
 
Lecture #3 Flag Register.pptx
Lecture #3 Flag Register.pptxLecture #3 Flag Register.pptx
Lecture #3 Flag Register.pptx
ImranBhatti58
 
Intel 8086
Intel 8086Intel 8086
Intel 8086
BELLALHOSSAIN31
 
Assembly Lab Sheet 5 About Status of Flag Register.pptx
Assembly Lab Sheet 5 About Status of Flag Register.pptxAssembly Lab Sheet 5 About Status of Flag Register.pptx
Assembly Lab Sheet 5 About Status of Flag Register.pptx
ishitasabrincse
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
Bilal Amjad
 
Cpe103 03 [processor flags]
Cpe103   03 [processor flags]Cpe103   03 [processor flags]
Cpe103 03 [processor flags]
Nessabel Bacani
 
Flag register 8086 assignment
Flag register 8086 assignmentFlag register 8086 assignment
Flag register 8086 assignment
Zia3130
 
Flag Register in 8086.pptx with the notenot
Flag Register in 8086.pptx with the notenotFlag Register in 8086.pptx with the notenot
Flag Register in 8086.pptx with the notenot
gaherwarsaloni1234
 
8086 architecture
8086 architecture8086 architecture
8086 architecture
karthiga selvaraju
 
Registers
RegistersRegisters
Registers
waqar bashir
 
126.pptx
126.pptx126.pptx
Chapter 6
Chapter 6Chapter 6
Microprocessor 8086 and Microcontoller
Microprocessor 8086 and MicrocontollerMicroprocessor 8086 and Microcontoller
Microprocessor 8086 and Microcontoller
Saad Tanvir
 
Flag control
Flag controlFlag control
Flag control
Robert Almazan
 
Dsp Datapath
Dsp DatapathDsp Datapath
Dsp Datapath
Abhishek Tiwari
 
Microprocessor and assambly language programming
Microprocessor and assambly language programmingMicroprocessor and assambly language programming
Microprocessor and assambly language programming
Shami Al Rahad
 
Flag registers, addressing modes, instruction set
Flag registers, addressing modes, instruction setFlag registers, addressing modes, instruction set
Flag registers, addressing modes, instruction setaviban
 

Similar to Flags (20)

Flags register in central processing unit
Flags register in central processing unitFlags register in central processing unit
Flags register in central processing unit
 
Assignment on alp
Assignment on alpAssignment on alp
Assignment on alp
 
8086 Microprocessor
8086 Microprocessor8086 Microprocessor
8086 Microprocessor
 
Lecture #3 Flag Register.pptx
Lecture #3 Flag Register.pptxLecture #3 Flag Register.pptx
Lecture #3 Flag Register.pptx
 
Intel 8086
Intel 8086Intel 8086
Intel 8086
 
Assembly Lab Sheet 5 About Status of Flag Register.pptx
Assembly Lab Sheet 5 About Status of Flag Register.pptxAssembly Lab Sheet 5 About Status of Flag Register.pptx
Assembly Lab Sheet 5 About Status of Flag Register.pptx
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
 
Cpe103 03 [processor flags]
Cpe103   03 [processor flags]Cpe103   03 [processor flags]
Cpe103 03 [processor flags]
 
Flag register 8086 assignment
Flag register 8086 assignmentFlag register 8086 assignment
Flag register 8086 assignment
 
Flag Register in 8086.pptx with the notenot
Flag Register in 8086.pptx with the notenotFlag Register in 8086.pptx with the notenot
Flag Register in 8086.pptx with the notenot
 
8086 architecture
8086 architecture8086 architecture
8086 architecture
 
Registers
RegistersRegisters
Registers
 
126.pptx
126.pptx126.pptx
126.pptx
 
Chapter 6
Chapter 6Chapter 6
Chapter 6
 
Al2ed chapter7
Al2ed chapter7Al2ed chapter7
Al2ed chapter7
 
Microprocessor 8086 and Microcontoller
Microprocessor 8086 and MicrocontollerMicroprocessor 8086 and Microcontoller
Microprocessor 8086 and Microcontoller
 
Flag control
Flag controlFlag control
Flag control
 
Dsp Datapath
Dsp DatapathDsp Datapath
Dsp Datapath
 
Microprocessor and assambly language programming
Microprocessor and assambly language programmingMicroprocessor and assambly language programming
Microprocessor and assambly language programming
 
Flag registers, addressing modes, instruction set
Flag registers, addressing modes, instruction setFlag registers, addressing modes, instruction set
Flag registers, addressing modes, instruction set
 

Flags

  • 2. Special Purpose Registers • IP- the instruction pointer. • Flags Register - determines the current state of the processor. • IP register always works together with CS segment register and it points to currently executing instruction. • Flags Register is modified automatically by CPU after mathematical operations, this allows to determine the type of the result, and to determine conditions to transfer control to other parts of the program. Generally you cannot access these registers directly
  • 3. processor status register (or Flags) • As you may see there are 16 bits in this register, each bit is called a flag and can take a value of 1 or 0.
  • 4. processor status register (or Flags) • Bits of flag register are categorized into two portions • Status Flags: bit 0, 2, 4, 6 and 11 • Control Flags: bit 8, 9 and 10 • Other bits have no significance • All flags have specific names, we will call them by its names
  • 5. processor status register (or Flags) • Carry Flag (CF) - 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. • Zero Flag (ZF) - set to 1 when result is zero. For none zero result this flag is set to 0. • Sign Flag (SF) - 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.
  • 6. processor status register (or Flags) • Overflow Flag (OF) - set to 1 when there is a signed overflow. For example, when you add bytes 100 + 50 (result is not in range -128...127). • 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. Even if result is a word only 8 low bits are analyzed! • Auxiliary Flag (AF) - set to 1 when there is an unsigned overflow for low nibble (4 bits).
  • 7. processor status register (or Flags) • 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.
  • 8. FlagsRegister(StatusRegister) • A flag is a single bit of information whose meaning is independent from any other bit • Each flag has a two-letter symbol
  • 9. CF - Carry Flag 1. If the result of an arithmetic or shift operation "carries out" a bit from the operand, CF becomes set 11111111 + 00000001 = 100000000  CF = 1 2. The carry (borrow) flag is also set if the subtraction of two numbers requires a borrow into MSB subtracted 00000000 - 00000001 = 11111111  CF = 1 • In unsigned arithmetic, watch the carry flag to detect errors. • In signed arithmetic, the carry flag tells you nothing interesting. 00000000 - 00000001 = 11111111 • unsigned arithmetic => 11111111 = 255 (decimal) => got the wrong answer • signed arithmetic => 11111111 = -1 (decimal) => got right answer, do not care about value of CF
  • 10. OF – Overflow Flag 1. 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  OF = 1 2. 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  OF = 1 3. Otherwise, the overflow flag is turned off. 0100 + 0001 = 0101  OF = 0 0110 + 1001 = 1111  OF = 0 1000 + 0001 = 1001  OF = 0 1100 + 1100 = 1000  OF = 0 • In signed arithmetic, overflow flag on means the answer is wrong - you added two positive numbers and got a negative, or you added two negative numbers and got a positive. • In unsigned arithmetic, the overflow flag tells you nothing interesting.
  • 11. ZF – Zero Flag - set if result is zero; cleared otherwise add 0, 0  ZF = 1 SF – Sign Flag becomes set when the result of an operation is negative (i.e. MSB of the result is 1) • all arithmetic operations except multiplication and division • compare instructions - CMP • logical instructions - XOR, AND, OR • TEST instructions (equivalent to AND instructions without storing the result) sub 00000000, 00000001  11111111  SF = 1 PF – Parity Flag - set if low-order eight bits of result contain an even number of "1" bits; cleared otherwise add 11010, 1 (result is 11011  4 bits are ‘1’  PF = 1) add 11000, 1 (result is 11001  3 bits are ‘1’  PF = 0) AF – Auxiliary Carry Flag (or Adjust Flag) is set if there is a carry from low nibble (4 bits) to high nibble or a borrow from a high nibble to low nibble 1111 + 0001 = 10000  AF = 1 first nibble second nibble ZF, SF, PF, and AF Flags