University of Asia Pacific
6/22/2014
1
What is FLAGS Register??
 The FLAGS register is the status register in Intel
x86 microprocessors that contains the current
state of the processor. This register is 16 bits wide.
Its successors, the EFLAGS and RFLAGS
registers, are 32 bits and 64 bits wide,
respectively. The wider registers retain
compatibility with their smaller predecessors. We
are going to discuss about the FLAGS registers
here.
6/22/2014 2
Category of FLAGS
Registers
There are 2 types of FLAGS register.
• Status Flags
• Control Flags
This register is 16 bits wide. The Status Flags are
located in 0, 2, 4, 6, 7 and 11 bits. Control Flags
are located in 8, 9 and 10 Bits and the System
Flags are located in 12,13 and 14 bits and others
left bits are reserved bits.
6/22/2014 3
Status Flags
There are 6 status flags in 8086 processor.
• Carry Flag
• Parity Flag
• Adjust Flag
• Zero Flag
• Sign Flag
• Overflow Flag
6/22/2014 4
Carry Flag
In 8086 processors the carry flag (usually
indicated as the C flag) is a single bit in a system
status (flag) register used to indicate when an
arithmetic carry or borrow has been generated
out of the most significant ALU bit position. The
carry flag enables numbers larger than a single
ALU width to be added/subtracted by carrying
(adding) a binary digit from a partial
addition/subtraction to the least significant bit
position of a more significant word. It is located in
the 0 bits if a 8086 processor
6/22/2014 5
Parity Flag
In 8086 processors the parity flag indicates if
the number of set bits is odd or even in the
binary representation of the result of the last
operation. It is normally a single bit(2) in a
processor status register. For example,
assume a machine where a set parity flag
indicates even parity. If the result of the last
operation were 26 (11010 in binary), the parity
flag would be 0 since the number of set bits is
odd. Similarly, if the result were 102 (1100110
in binary) then the parity flag would be 1.
6/22/2014 6
Adjust Flag
 The Adjust flag (also known as the Auxiliary
flag) is a flag stored in the FLAGS register on
all 8086 processors. It is bit 4. It is used to
indicate when an arithmetic carry or borrow
has been generated out of the 4 least
significant bits. It is primarily used in BCD
arithmetics.
 Auxiliary flag is set (AF=1) if there is a carry
from low nibble to high nibble or a borrow from
a high nibble to low nibble of the low order 8-
bit of a 16-bit number.(for example, in BCD
addition or subtraction.)
6/22/2014 7
Zero Flag
The Zero Flag is a single bit flag located in 6 bit of a
8086 processor. The zero flag is used to check the
result of an arithmetic operation, including bitwise
logical instructions. It is set if an arithmetic result is
zero, and reset otherwise. This includes results which
are not stored, as most traditional instruction sets
implement the compare instruction as a subtract
where the result is discarded. It is also common that
processors have a bitwise AND-instruction that does
not store the result.
In most processors, the zero flag is mainly used in
conditional branch instructions, which alter control
flow on previous instruction results, but there are often
other uses as well.
6/22/2014 8
Sign Flag
In a 8086 processor the sign flag or
negative flag is a single bit in a system status
(flag) register used to indicate whether the
result of the last mathematical operation
resulted in a value whose most significant bit
was set. In a two's complement interpretation
of the result, the negative flag is set if the
result was negative.
For example, in an 8-bit signed number
system, -37 will be represented as 1101 1011
in binary (the most significant bit is 1), while
+37 will be represented as 0010 0101 (the
most significant bit is 0).
6/22/2014 9
Overflow flag
In 8086 processors, the overflow flag
(sometimes called V flag) is usually a single bit in
a system status register used to indicate when an
arithmetic overflow has occurred in an operation,
indicating that the signed two's-complement result
would not fit in the number of bits used for the
operation (the ALU width). Some architectures
may be configured to automatically generate an
exception on an operation resulting in overflow.
6/22/2014 10
Control Flags
There are 3 Control flags in 8086
processor.
• Trap Flag
• Interrupt Enable Flag
• Direction Flag
6/22/2014 11
Trap flag
A trap flag permits operation of a processor in
single-step mode. If such a flag is available,
debuggers can use it to step through the execution
of a computer program. The 8086 has no
instruction to directly set or reset the trap flag.
These operations are done by pushing the flag
register on the stack, changing the trap flag bit to
what the programmer wants it to be, and then
popping the flag register back off the stack.
6/22/2014 12
Interrupt flag
 Interrupt Flag is a system flag bit in the 8086
processor’s FLAGS register, which determines
whether or not the CPU will handle maskable
hardware interrupts.
 The bit, which is bit 9 of the FLAGS register,
may be set or cleared by programs with
sufficient privileges, as usually determined by
the Operating System. If the flag is set to 1,
maskable hardware interrupts will be handled.
If cleared (set to 0), such interrupts will be
ignored. IF does not affect the handling of non-
maskable interrupts or software interrupts
generated by the INT instruction.
6/22/2014 13
Direction flag
 The direction flag is a flag that controls the left-to-
right or right-to-left direction of string processing,
stored in the FLAGS register on all 8086
processors. It is bit number 10.
 When it is set to 0 (using the clear-direction-flag
instruction CLD),it means that instructions that
auto increment the source index and destination
index (like MOVS) will increase both of them. In
case it is set to 1 (using the set-direction-flag
instruction STD), the instruction will decrease
them.
 This flag is used to determine the direction
(forward or backward) in which several bytes of
data will be copied from one place in the memory,6/22/2014 14
THE END
6/22/2014 15

Flags registor of 8086 processor

  • 1.
    University of AsiaPacific 6/22/2014 1
  • 2.
    What is FLAGSRegister??  The FLAGS register is the status register in Intel x86 microprocessors that contains the current state of the processor. This register is 16 bits wide. Its successors, the EFLAGS and RFLAGS registers, are 32 bits and 64 bits wide, respectively. The wider registers retain compatibility with their smaller predecessors. We are going to discuss about the FLAGS registers here. 6/22/2014 2
  • 3.
    Category of FLAGS Registers Thereare 2 types of FLAGS register. • Status Flags • Control Flags This register is 16 bits wide. The Status Flags are located in 0, 2, 4, 6, 7 and 11 bits. Control Flags are located in 8, 9 and 10 Bits and the System Flags are located in 12,13 and 14 bits and others left bits are reserved bits. 6/22/2014 3
  • 4.
    Status Flags There are6 status flags in 8086 processor. • Carry Flag • Parity Flag • Adjust Flag • Zero Flag • Sign Flag • Overflow Flag 6/22/2014 4
  • 5.
    Carry Flag In 8086processors the carry flag (usually indicated as the C flag) is a single bit in a system status (flag) register used to indicate when an arithmetic carry or borrow has been generated out of the most significant ALU bit position. The carry flag enables numbers larger than a single ALU width to be added/subtracted by carrying (adding) a binary digit from a partial addition/subtraction to the least significant bit position of a more significant word. It is located in the 0 bits if a 8086 processor 6/22/2014 5
  • 6.
    Parity Flag In 8086processors the parity flag indicates if the number of set bits is odd or even in the binary representation of the result of the last operation. It is normally a single bit(2) in a processor status register. For example, assume a machine where a set parity flag indicates even parity. If the result of the last operation were 26 (11010 in binary), the parity flag would be 0 since the number of set bits is odd. Similarly, if the result were 102 (1100110 in binary) then the parity flag would be 1. 6/22/2014 6
  • 7.
    Adjust Flag  TheAdjust flag (also known as the Auxiliary flag) is a flag stored in the FLAGS register on all 8086 processors. It is bit 4. It is used to indicate when an arithmetic carry or borrow has been generated out of the 4 least significant bits. It is primarily used in BCD arithmetics.  Auxiliary flag is set (AF=1) if there is a carry from low nibble to high nibble or a borrow from a high nibble to low nibble of the low order 8- bit of a 16-bit number.(for example, in BCD addition or subtraction.) 6/22/2014 7
  • 8.
    Zero Flag The ZeroFlag is a single bit flag located in 6 bit of a 8086 processor. The zero flag is used to check the result of an arithmetic operation, including bitwise logical instructions. It is set if an arithmetic result is zero, and reset otherwise. This includes results which are not stored, as most traditional instruction sets implement the compare instruction as a subtract where the result is discarded. It is also common that processors have a bitwise AND-instruction that does not store the result. In most processors, the zero flag is mainly used in conditional branch instructions, which alter control flow on previous instruction results, but there are often other uses as well. 6/22/2014 8
  • 9.
    Sign Flag In a8086 processor the sign flag or negative flag is a single bit in a system status (flag) register used to indicate whether the result of the last mathematical operation resulted in a value whose most significant bit was set. In a two's complement interpretation of the result, the negative flag is set if the result was negative. For example, in an 8-bit signed number system, -37 will be represented as 1101 1011 in binary (the most significant bit is 1), while +37 will be represented as 0010 0101 (the most significant bit is 0). 6/22/2014 9
  • 10.
    Overflow flag In 8086processors, the overflow flag (sometimes called V flag) is usually a single bit in a system status register used to indicate when an arithmetic overflow has occurred in an operation, indicating that the signed two's-complement result would not fit in the number of bits used for the operation (the ALU width). Some architectures may be configured to automatically generate an exception on an operation resulting in overflow. 6/22/2014 10
  • 11.
    Control Flags There are3 Control flags in 8086 processor. • Trap Flag • Interrupt Enable Flag • Direction Flag 6/22/2014 11
  • 12.
    Trap flag A trapflag permits operation of a processor in single-step mode. If such a flag is available, debuggers can use it to step through the execution of a computer program. The 8086 has no instruction to directly set or reset the trap flag. These operations are done by pushing the flag register on the stack, changing the trap flag bit to what the programmer wants it to be, and then popping the flag register back off the stack. 6/22/2014 12
  • 13.
    Interrupt flag  InterruptFlag is a system flag bit in the 8086 processor’s FLAGS register, which determines whether or not the CPU will handle maskable hardware interrupts.  The bit, which is bit 9 of the FLAGS register, may be set or cleared by programs with sufficient privileges, as usually determined by the Operating System. If the flag is set to 1, maskable hardware interrupts will be handled. If cleared (set to 0), such interrupts will be ignored. IF does not affect the handling of non- maskable interrupts or software interrupts generated by the INT instruction. 6/22/2014 13
  • 14.
    Direction flag  Thedirection flag is a flag that controls the left-to- right or right-to-left direction of string processing, stored in the FLAGS register on all 8086 processors. It is bit number 10.  When it is set to 0 (using the clear-direction-flag instruction CLD),it means that instructions that auto increment the source index and destination index (like MOVS) will increase both of them. In case it is set to 1 (using the set-direction-flag instruction STD), the instruction will decrease them.  This flag is used to determine the direction (forward or backward) in which several bytes of data will be copied from one place in the memory,6/22/2014 14
  • 15.