Flag Register in 8086 microprocessor




Flag Register :- Flag register or Status register is a type of special purpose register
which contains a number of flags, either to indicate certain conditions(arising after ALU operations) or to control certain operations.
The Flags which indicate certain conditions are called Condition/Status Flags.
The Flags which indicate certain operations are called Control Flags.
These flags are in bits, which is called as Flag Bits.
It Changes from 0 to 1 or 1 to 0 (Depending upon the value of result after ALU operation).
A flag is a flip-flop which is SET(means 1) or RESET(means 0) by the processor either to
indicate certain conditions or SET(1)/RESET(0) by the programmers to control certain Operations.

Intel 8086 microprocessor contains 16 bit flag register, in which only 9 are Valid/Active Flag bits, remaining 7 bits are undefined.
Intel 8086 microprocessor contains 6 Status/Condition flags & 3 Control flags.
Condition/Status Flag:-
    1.Carry Flag(C)
    2.Parity Flag(P)
    3.Auxiliary Carry Flag(A)
    4.Zero Flag(Z)
    5.Sign Flag(S)
    6.Overflow(O)
Control Flag:-
    1.Trap Flag(TF)
    2.Interrupt Enable(IE)
    3.Direction Flag(D)
We will understand about each flags in detail, but before we need to know these terms:-
Nibble - Group of 4 bits is called Nibble.
MSB - MSB stands for Most Significant Bit. It is the left-most bit in the binary number series. It has the greatest numerical value.
LSB - LSB stands for Least Significant Bit. It is the right-most bit in the binary number series. It has the lowest numerical value.

So now, Coming back to the point...
Condition/Status Flag:-

 1.Carry Flag:- Carry flag indicates that after an ALU operation whether there is a carry is generated or not.
if YES then Carry flag is SET(1)
or
if NO  then Carry flag is RESET(0).

2.Parity Flag :- Parity Flag indicates that whether the result contains even numbers of 1s or ODD numbers of 1s.
if the no. of 1s is Even, then the Parity Flag is SET(1)
or
if the no. of 1s is ODD, then the Parity Flag is RESET(0).

3.Auxiliary Carry :- Auxiliary Carry is SET when there is a carry from Lower nibble (or Lower Half) to Higher nibble (or Upper Half),after an ALU operation.
if YES then Auxiliary Carry is SET(1)
or
if NO  then Auxiliary Carry is RESET(0).
In other words we can say that, Auxiliary Carry is SET when there is carry from lower nibble to higher nibble(In Addition) or Borrow from Higher Nibble to Lower Nibble(In Subtraction).
Note : These Auxiliary carry is not accessible by the programmers.It is used internally by the ALU (arithmetic & logical Unit) for BCD (Binary Coded Decimal) addition.

4.Zero Flag :- Zero flag indicates that whether the result of arithmetic & logical operation is Zero or Non-Zero.
After an ALU operation,
if the Result = 00H , then the Zero Flag is SET(1)
or
if the Result  00H , then the Zero Flag is RESET(0).

 5.Sign Flag :- Sign flag indicates that whether the result is Positive(+ve) or Negative(-ve).
After ALU operation,
if the MSB(Most Significant Bit) of the result is 1 then it indicates that,the number is Negative(-ve)
& the Sign flag is SET(1)
or
if the MSB(Most Significant Bit) of the result is 0 then it indicates that,the number is Positive(+ve)
& the Sign flag is RESET(0).

6.Overflow :- Overflow is SET(1) when the result of Signed Operation operation is too large to fit in the number of bits available to represent it.
Range: -2^n to 2^n-1
For 16 bit Register this range will be from  -65536 to 65535
So if the result doesn't fit in this range then the Overflow flag is SET(1)
or
if the result fits in this range then the Overflow flag is RESET(0).

Control Flag :- Control Flags are used Enable or Disable some basic operations of microprocessors. It is SET(1) or RESET(0) to control  the execution of a Program.
1.Trap Flag(TF):- Trap flag is used for debugging purposes.
So, if the Trap flag is SET(1) then it works in Single Step Mode. After every instruction, an internal interrupt is generated which helps to execute program instruction by instruction & in this way the program can be debugged 
or
if the Trap flag is RESET(0) , then no interrupt is generated.

2.Interrupt Enable Flag (IF):- Interrupt Enable flag is used to Enable or Desable the Interrupt Request(INTR).
So, if the Interrupt Flag is SET(1) , then the microprocessor will recognize the Interrupt Request(INTR) coming from the Peripherals.
or
if the Interrupt Flag is RESET(0) , then the microprocessor will not recognize any Interrupt Request(INTR) & it will ignore them.

3.Direction Flag(D):-Before we know Direction Flag we need to know about String Instruction.
String: String are the group of data bytes/words whose memory is always allocated in Sequential Order. String Instruction operates on string of bytes\words.(Operations like storing strings in memory, loading strings from memory, comparing strings from memory, scanning strings, etc)
Now coming back to the point. 
Direction flag is specifically used for String instruction.
So, if the Direction flag is SET(1) , then the string will be accessed from Higher Memory Address to Lower Memory Address ,
or
if the Direction flag is RESET(0) , then it will be accessed form Lower Memory Address to Higher Memory Address.

Microtricks Learning YouTube team made a special video on Flag Register. You guys can watch that video on YouTube.
Link - https://youtu.be/8E6KDVUzvb8

Comments

Post a Comment

Popular posts from this blog

What is CPU Register?