ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

Flag Register of 8085

Updated on July 31, 2015

Flag Register

Flag Register
Flag Register

The 8085 has 8 bit flag register specifying the status of the result generated in accumulator. The flag register contain status bits that indicates various status about the result generated. There are following flag bits used into the flag registers:

  • SF (Sign Flag)
  • ZF (Zero Flag)
  • AC (Auxiliary Carry Flag)
  • PF (Parity Flag)
  • CF (Carry Flag)

SIGN FLAG (SF): The sign flag indicates whether result generated is positive or negative. The sign flag is set to 1 whenever the result generated is negative. If the sign flag is set to 0 than the result generated is positive. The negative result sets the SF to 1. Generally the MSB is considered as the bit that indicates if the result is positive or negative. The MSB = 1 means the result is negative and if MSB=0 than the result is positive.

ZERO FLAG(ZF): The ZF indicates the result generated is zero or non-zero. If the result generated is zero than the Zero Flag is set to 1 else if the result is non-zero than the ZF=0.

AUXILIARY CARRY FLAG(AC): The Auxiliary Carry flag is set to 1 whenever there is a carry or borrow at nibble in the data. If the carry generated from 4th bit to 5th bit or borrow is taken from 5th bit to 4th bit than the Auxiliary Carry Flag is set to 1.

PARITY FLAG(PF): The Parity Flag is set to 1 when even parity of 1s into the result. The Parity Flag is reset to 0 when odd parity of 1s into the result.

  • If the number of 1s into the result is ODD than the parity flag is reset to 0.
  • If the number of 1s into the result is EVEN than the parity flag is set to 1.

CARRY FLAG(CF): The Carry flag is set to 1 whenever there is a carry from MSB or borrow to MSB.

Example

Here we will take a look at the examples that will explain how the flag bits are affected by the instruction execution.

SIGN FLAG:

Start

MVI A, 0F5H //... A = 1111 0101

MVI B, 03H //... B = 0000 0011

SUB B //... A = 1111 0010 = F2

HLT

So here the subtraction of 0F5H and 03H results into F2h. The MSB here in result is set to 1 so we can say the result is negative and SF=1. Although you might wonder 0F5h- 03h should be positive result but as the result of the subtraction has MSB=1, it is considered as arithmetically negative. Hence the SF=1. So in short the value of SF=MSB

ZERO FLAG(ZF): The zero flag is set to 1 whenever the result generated is equals to zero. Let's see an example of it.

START:

MVI A, 04h

MVI B, 04h

SUB B

HLT

The result generated is A-B (04-04) = 00h. Hence the zero flag is set to 1.

Auxiliary Carry: The Auxiliary Carry(AC) is set to 1 when the carry from nibble is generated. The following examples shows the example when AC is set:

START:

MVI A, 88h //... 1000 1000

MVI B, 39h //... 0011 1001

ADD B //... 1100 0001 Carry from 4th bit of result to 5th bit causes the AC=1

HLT

The above example shows that the carry is generated from 4th bit to 5th bit of result and that sets the AC of flag to 1.

PARITY FLAG: The parity flag is set to 1 whenever there is an even parity. The parity flag is set to 0 whenever there is the odd parity in result.

START:

MVI A, 02H

MVI B, 04H

ADD B

HLT

The answer of the instruction ADD B will be A=06h(0000 0110). The result contains 2(even) number of 1s in the result. That means the PF will be set to 1.

START:

MVI A, 12H

MVI B, 04H

ADD B

HLT

The answer of the instruction ADD B will be A=16h(0001 0110). Here the result contains the ODD(3) number of 1s in the result, so the PF=0.

CARRY FLAG: The carry flag is set to 1 whenever the MSB generates carry or borrow.

START:

MVI A, 88h // 1000 1000

MVI B, 99h // 1001 1001

ADD B //CF=1 0010 0001

HLT

The above example shows the carry generated at MSB and the CARRY FLAG is set to 1.

START:

MVI A,00h //.... 0000 0000

MVI B, 49h //.... 0100 1001

SUB B //CF=1 1011 0111

HLT

The example shows that the result generated has the borrow to MSB and sets the CF=1.

Comments

    0 of 8192 characters used
    Post Comment

    • profile image

      Dips 9 months ago

      Very helpful.Thanks!!!

    Click to Rate This Article