Saturday 26 January 2013

Flag Register

Program Status Word (PSW) Register

The program status word (PSW) register, also referred to as the flag register, is an 8 bit register.

Only 6 bits are used

  • These four are CY (carry), AC (auxiliary carry), P (parity), and OV (overflow)
    • They are called conditional flags, meaning that they indicate some conditions that resulted after an instruction was executed
  • The PSW3 and PSW4 are designed as RS0 and RS1, and are used to change the bank
  • The two unused bits are user-definable
CY
AC
F0
RS1
RS0
OV
--
P
CY
PSW.7
Carry flag
AC
PSW.6
Auxiliary carry flag
--
PSW.5
Available to the user for general purpose
RS1
PSW.4
Register Bank selector bit 1
RS0
PSW.3
Register Bank selector bit 0
OV
PSW.2
Overflow flag
--
PSW.1
User definable bit
P
PSW.0
Parity flag. Set/cleared by hardware each instruction cycle to indicate an  odd/even number of 1 bits in the accumulator.

Instructions that affect flag bits

Instruction
CY
OV
AC
ADD
X
X
X
ADDC
X
X
X
SUBB
X
X
X
MUL
0
X

DIV
0
X

DA
X


RPC
X


PLC
X


SETB C
1


CLR C
0


CPL C
X


ANL C, bit
X


ANL C, /bit
X


ORL C, bit
X


ORL C, /bit
X


MOV C, bit
X


CJNE
X



Example:

Show the status of the CY, AC and P flag after the addition of 38H and 2FH in the following instructions.

                MOV A, #38H
                ADD A, #2FH      ;after the addition A=67H, CY=0

Solution:
                38           00111000
            + 2F            00101111
               67            01100111
CY = 0 since there is no carry beyond the D7 bit
AC = 1 since there is a carry from the D3 to the D4 bi
P = 1 since the accumulator has an odd number of 1s (it has five 1s)


Example:

Show the status of the CY, AC and P flag after the addition of 9CH and 64H in the following instructions.


MOV A, #9CH
ADD A, #64H      ;after the addition A=00H, CY=1

Solution:

9C           10011100
         + 64           01100100
         100             00000000

CY = 1 since there is a carry beyond the D7 bit
AC = 1 since there is a carry from the D3 to the D4 bi
P = 0 since the accumulator has an even number of 1s (it has zero 1s)

Example:

Show the status of the CY, AC and P flag after the addition of 88H and 93H in the following instructions.
MOV A, #88H
ADD A, #93H      ;after the addition A=1BH, CY=1

Solution:

88           10001000
         + 93          10010011
          11B           00011011

CY = 1 since there is a carry beyond the D7 bit
AC = 0 since there is no carry from the D3 to the D4 bi
P = 0 since the accumulator has an even number of 1s (it has four 1s)

No comments:

Post a Comment