# Bit manipulation program in 8051

Microprocessor8085

In this section, we will see some bit manipulation operation using 8051. The 8051 supports some operations on different bits of an 8-bit number. The operations are like complementing, setting to 1, moving, ANDing, ORing etc.

In this example, we are taking a number AEH from location 10H, then after performing following bit related operations on that data, we are just storing the result at location 30H.

The bit related operations that will be performed on that data, are as follows −

• Complement bit b2

• Move b5to b4

• OR b0and complement of band store to C (b7)

• Set b6

• Reset bit b3

BitPosition
b7
b6
b5
b4
b3
b2
b1
b0
Value
1
0
1
0
1
1
1
0

## Output

BitPosition
b7
b6
b5
b4
b3
b2
b1
b0
Value
0
1
1
1
0
0
1
0

The output will be 72H

## Program

MOV24H,10H;Copy item from 10H to 24H
CPL24.2;Complement bit b2
MOVC,24.5;Copy b5 to C
MOV24.4,C;Move C to b4
MOVC,24.0;Make copy of b0 to C
ORLC,/1;OR C and complement of b1
SETB24.6;Set bit b6
CLR24.3;Reset bit b3
MOV30H,24H; Store the result at 30H
HALT:   SJMP HALT

From the program, we can easily get the logic. To use bit addressable operation, we have to access the location 20H to 2FH. These 16-bytes are used for bit addressable operations.

In Bit addressable operation, the Carry flag acts like the 1-bit accumulator.

## Output

Value

.
.
.
10H
AEH
11H

.
.
.
30H
72H
31H

.
.
.
Updated on 27-Jun-2020 12:54:00