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 b1 and store to C (b7)
Reset bit b3
The output will be 72H
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.