PSW Register in 8051 Microcontroller with detailed explanation

In a 8051 microcontroller, the PSW register is one of the most important registers used to store information during program execution. PSW stands for Program Status Word. It is an 8-bit register, and out of these 8 bits, 6 bits are commonly used during program execution. Each bit acts as a flag.

PSW register in 8051 micro controller
PSW Register in 8051 micro controller

In the PSW register, four flags are used to indicate the result of arithmetic and logical operations. These four flags are:

  • CY – Carry
  • AC – Auxiliary Carry
  • P – Parity
  • OV – Overflow

The bits PSW.3 and PSW.4 are used to select register banks where data is interpreted.
The bits PSW.1 and PSW.5 are general-purpose flags, which are available for the programmer to use according to application requirements.

00000000Value after Reset
CACF0RS1RS0OVPFlag Name
76543210Bit No

Let us see each flag in detail to understand its function and usage.

Flag and Bit Details in PSW register

1. Parity (P) (PSW.0)

This is used to indicate the number of 1’s bits (high bits) in the accumulator. If the accumulator contains an even number of 1’s, this flag is automatically set to 1 (high). Otherwise, it is cleared and set to 0 (low).

The important function of the Parity bit is to detect errors during data transmission, especially when data is transferred from one memory to another or received via serial communication.

2. Bit-1 (PSW.1)

This bit indented to use for future version of micro controllers.

3. Over Flow (OV) (PSW.2)

Over flow bit is used during arithmetical operations of signed values. When ADD / SUBTRACT signed values, it definitely overflows than defined memory range of micro controller. if it overflows, overflow bit will be set as 1 (High). Otherwise it will be cleared to 0 (Low).

4. Register Bank Select Bits (RS0 and RS1) (PSW.3 and PSW.4)

The register bank selection bits are:

  • RS1 – PSW.4
  • RS0 – PSW.3

These bits are used to select one of the four register banks available in the internal RAM of the 8051 microcontroller.
Each register bank contains eight registers (R0–R7).

To select a register bank, the RS0 and RS1 bits are set to either 0 or 1 as shown in the table below:

RS1 (PSW.4)RS0 (PSW.3)Register BankAddress Range
00Bank 000H – 07H
01Bank 108H – 0FH
10Bank 210H – 17H
11Bank 318H – 1FH

Upon reset, the PSW register is cleared, and Register Bank 0 is selected by default in the 8051 microcontroller.

5. Flag 0 (F0) (PSW.5)

This is a general-purpose flag. It is available for user-defined operations and can be used as required by the programmer.

6. AC (Auxiliary Carry) (PSW.6)

The Auxiliary Carry flag is mainly used for BCD (Binary Coded Decimal) operations.

  • If a carry or borrow is generated from bit 3 (D3) to bit 4 (D4) during an arithmetic operation, this flag is set.
  • Otherwise, it is cleared.

7. Carry (C) (PSW.7)

The Carry flag is located at PSW.7.
It is used in all arithmetic and shift operations.

  • During arithmetic operations (ADD / SUB), if any carry or borrow is generated, it is stored in this flag.
  • The instructions SETB C and CLR C are used to set and clear the carry flag respectively.

Download For PSW register of 8051 microcontroller

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top