PSW Register in 8051 Microcontroller | Program Status Word

  • Flags are single bit register and used to store the result of certain function after executing instruction. Flags are grouped inside PSW and PCON registers.
  • PSW register in 8051 microcontroller contains math flags and PCON contains general user flags.
  • Math flags are grouped in PSW of microcontroller 8051 and they are Carry(C), Auxiliary Carry (AC), Over flow (OV), and Parity (P). The general user flags are GF0 and GF1 which are grouped in PCON register.

PSW Register in 8051

  • The PSW is accessible fully as an 8-bit register, with the address D0H.
  • The bit pattern of this flag register is
psw register in 8051 microcontroller, psw format for microcontroller 8051
Figure 1: Format of PSW register in 8051 Microcontroller

Parity bit (P)

    • This parity flag bit is used to show the number of 1s in the accumulator only. If the accumulator register contains an odd number of 1s, then this flag set to 1.
    • If accumulator contains even number of 1s, then this flag cleared to 0.

Overflow flag (OV)

    • This flag is set during ALU operations, to indicate overflow in the result. It is set to 1 if there is a carry out of either the D7 bit or the D6 bit of the accumulator.
    • Overflow flag is set when arithmetic operations such as add and subtract result in sign conflict.
    • The conditions under which the OV flag is set are as follows:
      • Positive + Positive = Negative
      • Negative + Negative = Positive
      • Positive – Negative = Negative
      • Negative – Positive = Positive

Register bank select bits (RS1 and RS0)

    • These two bits are used to select one of four register banks of RAM. By setting and clearing these bits, registers R0-R7 are stored in one of four banks of RAM as follows.

RS1

RS0

Bank Selected

Address of Registers

0

0

Bank 0

00h-07h

0

1

Bank 1

08h-0Fh

1

0

Bank 2

10h-17h

1

1

Bank 3

18h-1Fh

    • These bits are user-programmable. They can be set by the programmer to point to the correct register banks.
    • The register bank selection in the programs can be changed using these two bits.

General-purpose flag (F0)

    • This is a user-programmable flag; the user can program and store any bit of his/her choice in this flag, using the bit address.

Auxiliary carry flag (AC)

    • It is used in association with BCD arithmetic. This flag is set when there is a carry out of the D3 bit of the accumulator.

Carry flag (CY)

    • This flag is used to indicate the carry generated after arithmetic operations. It can also be used as an accumulator, to store one of the data bits for bit-related Boolean instructions.
  • The 8051 supports bit manipulation instructions.
  • This means that in addition to the byte operations, bit operations can also be done using bit data.
  • For this purpose, the contents of the PSW are bit-addressable.
Instructions that affects the flags in 8051 microcontroller
Figure 2: Instructions that affect the flags in 8051 microcontroller

Recent posts

2 thoughts on “PSW Register in 8051 Microcontroller | Program Status Word”

  1. I have read a few good stuff here. Definitely price bookmarking for revisiting. I wonder how much attempt you put to make this type of wonderful informative web site.

Comments are closed.