Flags Register:

Flags Register
The ALU influences a number of flip flops called flags which store information related to the results of arithmetic and logical operations. Taken together this flags constitute a flag register. The Flag register is a Special Purpose Register and is completely different from the other registers in a microprocessor. Flag register is an 8-bit register accessible to the user through instruction. Each bit in the flag register has a specific function.The other 3 are left vacant and are in the future Intel versions. Therefore, 8085 has five flags - Sign flag, Zero flag, Auxillary carry flag, Parity flag and the Carry flag. Only 5 bits out of 8 bits are used as shown below: 


D7
D6
D5
D4
D3
D2
D1
D0
S
Z
X
AC
X
P
X
CY

The three crossed bit are redundant bits and not used. They can be either ‘0’ or ‘1’ but normally they are forced to be zero. The other five bits are affected as a result of execution of an instruction. All instructions do not affect these flags e.g. data transfer operation do not affect these flags. The meaning and the effect of these flags are as follows. 
  • CY (Carry) Flag Bit
Also known as the Least Significant bit( LSB ). This particular bit is SET (=1) if there is a carry from the MSB position during an addition operation or if there is a borrow during the subtraction operation otherwise the flag is reset (=0). The processor, by design, does the subtraction operation also by taking 2’s complement of one operand and adding it to another operand.


One Byte Number
Upper Nibble
Lower Nibble
                1 Carry
Add
+

1000
1010

1101
1100
Sum
1
0110
0110
  • P (Parity) Flag Bit
The parity flag test for the number of ‘1’s in the accumulator. If the accumulator holds on an even number of 1’s, it is said that even parity exists and the parity flag is set to ‘1’. However, if the accumulator holds an odd number of ‘1’ it is called odd parity and the parity flag is reset to ‘0’. In other words, if the module-2 sum of the bit is ‘0’, this flag is set otherwise the flag is reset.
  • AC (Auxiliary Carry) Flag Bit
It occupies the 4th bit of the flag register. This bit is set if there is a carry from 3rd  bit to 4th bit of accumulator during addition operation otherwise it is reset. The AC flag is useful for BCD arithmetic and is used in a particular instruction known as DAA (Decimal Adjust Accumulator). 


One Byte Number
Upper Nibble
Lower Nibble
                  1 Auxiliary Carry
Add
+
1000
1010
0101
1100
Sum
1110
0110

  • Z (Zero) Flag Bit

Zero flag occupies the 6th bit of the flag register. Zero flag bit is SET if the result of an operation is zero, otherwise it is RESET.

  • Sign Flag Bit
Sign flag occupies the 7th bit of the flag register which is also known as the Most Significant Bit (MSB). It helps the programmer to know whether the number stored in the accumulator is positive or negative. A set '1' (binary number) sign flag represents a negative number, where as a reset '0' (binary number) flag means a positive number.

REFERENCES
  1.  R. S. Gaonkar, Microprocessor Architecture, Programming, and Applications with the 8085, Fifth Edition, Penram International Publishing (India) Private Limited.
  2. S Ghoshal, Microprocessor Based System Design, Macmillan India Limited, 1996.
  3. M. Mano, Digital Logic and Computer Design, Prentice – Hall India.
  4. B. Ram - Fundamentals of Microprocessor and Microcontrollers.
  5. “Microprocessors: Principles and Applications” by A Pal.
  6. “Microprocessors and Microcontrollers : Architecture, Programming and Interfacing Using 8085, 8086 and 8051” by Soumitra Kumar Mandal.
  7. “Introduction to Microprocessors and Microcontrollers” by Crisp John Crisp.
  8. “Microprocessors And Microcontrollers” by A Nagoor Kani.
  9. “Microprocessors And Microcontrollers : Architecture, Programming and System Design 8085, 8086, 8051, 8096” by Krishna Kant.
  10. 8 - Bit Microprocessor” by Vibhute

Comments