Flag Register
What is Flag register in 8085 microprocessor?
8085 is a second generation 8 bit microprocessor.
It is the base for studying and using all the modern microprocessors available in the market.
The Flag register is nothing but a Status Register of size 8 bit.
It can carry 8 bits and only 5 of them are useful in 8085 and the other 3 are left vacant.
**Therefore, 8085 has five flags -
1. Sign flag (S)
2. Zero flag (Z)
3. Auxillary carry flag (AC)
4. Parity flag (P)
5. Carry flag (C)
PIC : - BIT POSITIONS OF VARIOUS FLAGS IN A FLAG REGISTER OF 8085
Well. Let’s discuss all the flags in a sequential manner.
1.SIGN FLAG:
After execution of any arithmetic or logical instruction if the result of accumulator i.e. most significant bit(i.e. d7 th) is 1 then Sign Flag is set to 1 else reset to 0.
(After execution of arithmetic and logical instruction if the result is positive then sign flag is reset and if result is negative then sign flag is set)
i.e. if answer is positive d7=0 then S = 0
And
when answer is negative d7=1 then S = 1
2. ZERO FLAG:
After execution of any arithmetic or logical instruction if the result of accumulator is zero ( i.e. all 8 bits are zero) then Zero Flag is set to 1 else reset to 0.
i.e. if the result is Zero then Z= 1
And if the result is non-zero then Z=0
3. AUXILLARY CARRY FLAG:
After execution of any arithmetic or logical instruction if the d3 bit generates carry towards d4 bit of the result then Auxiliary Carry Flag is set to 1 else reset to 0.
ie... if there is carry from lower nibble to higher nibble then AC = 1 else AC =0
Example of binary addition in which auxillary carry is generated.
4. PARITY FLAG:
After execution of any arithmetic or logical instruction if the result of accumulator consist if even occurence of 1 then Parity falg is set else reset.
I.e... if the result contains even numbers of 1 then P= 1
And
if the result contains odd numbers of 1 then P= 0
5. CARRY FLAG:
After execution of any arithmetic or logical instruction if there is a carry (i.e 8th bit) in the result of accumulator then the Carry Flag is set to 1 else reset to 0.
I.e. if d8 th bit is present then C=1
And if d8th bit is absent then C=0
Example:
1111 1111
+0101 0101
1 0101 0100
S Z -- AC -- P -- C
0 0 0 1. 0 0 0 1
1. 1
Flag value= 11H
PURPOSE OF USING FLAG REGISTER:-
By now, you must have known that the flag acts like a Status Register which provides the status of the ALU operations performed in the microprocessor. It means that the information stored in the accumulator is provided to the programmer via the flag register and this is the main function of the flag.
EXAMPLE:-
Let’s assume the value of the flag register to be 15 H, i.e. 0001 0101
Now let’s check what each bit means. Refer the above explanations simultaneously to connect them with these examples.
7th bit is reset(0), which means number stored in the accumulator is positive.
6th bit is also reset(0), thus result of the operations performed in the ALU is non-zero.
4th bit is set(1). Therefore, Auxillary carry is generated in the operations performed in the ALU operation.
2nd bit is set(1). It means that even parity exists,i.e. accumulator holds even number of 1s.
0th bit is set(1), which means carry flag is generated in the arithmetic operation.
I hope that now you are well aware of the significance of the Flag Register.
P.S.
This is my first answer on quora. Please upvote if you think the answer deserves it. It would motivate me to write more.
THANK YOU!!!
Comments
Post a Comment