What is the flag format of 8051

          The program status word (PSW) register is an 8-bit register.It is also referred to as the flag register.Although the PSW register is 8 bits wide, only 6 bits of it are used by the 8051.The two unused bits are user-definable flags. Four of the flags are called conditional flags, meaning that they indicate some conditions that result after an instruction is executed. These four are CY (carry), AC (auxiliary carry), P (parity), and OV (overflow).As seen from below figure, the bits PSW.3 and PSW.4 are designated as RS0 and RS1 as register selection bit, respectively, and are used to change the bank registers.The PSW.5 and PSW.l bits are general-purpose status flag bits and can be used by the programmer for any purpose. In other words, they are user definable. See below Figure for the bits of the PSW register.

FORMAT OF PSW OF 8051 


The following is a brief explanation of four of the flag bits of the PSW register. The impact of instructions on these registers is then discussed.
how the bits of PSW are change after arithmetic & logical operation?


CY, the carry flag

  • This flag is set whenever there is a carry out from the D7 bit. 
  • This flag bit is affected after an 8-bit addition or subtraction. 
  • It can also be set to 1 or 0 directly by an instruction such as “SETB C” and “CLR C” where “SETB C” stands for “set bit carry” and “CLR C” for “clear carry”.

AC, the auxiliary carry flag

  • If there is a carry from D3 to D4 during an ADD or SUB operation, this bit is set; otherwise, it is cleared. 
  • This flag is used by instructions that perform BCD (binary coded decimal) arithmetic.

P, the parity flag

  • The parity flag reflects the number of 1 s in the A (accumulator) register only. 
  • If the A register contains an odd number of Is, then P = 1. Therefore, P = 0 if A has an even number of 1s.

OV, the overflow flag

  • This flag is set whenever the result of a signed number operation is too large, causing the high-order bit to overflow into the sign bit. 
  • In general, the carry flag is used to detect errors in unsigned arithmetic operations. 
  • The overflow flag is only used to detect errors in signed arithmetic operations

instruction that affect flags of PSW

Email ThisBlogThis!Share to TwitterShare to FacebookShare to Pinterest