- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Bit manipulation program in 8051
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)
Set b6
Reset bit b3
Input is AEH
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
Address | Value |
---|---|
. . . | |
10H | AEH |
11H | |
. . . | |
30H | 72H |
31H | |
. . . |
- Related Articles
- Java Program to display Bit manipulation in Integer
- Bit-processing group in 8051
- 8051 Program to Add two 8 Bit numbers
- 8051 Program to Subtract two 8 Bit numbers
- 8051 Program to Multiply two 8 Bit numbers
- 8051 Program to Divide two 8 Bit numbers
- Program to Subtract two 8 Bit numbers in 8051 Microprocessor
- Program to Multiply two 8 Bit numbers in 8051 Microprocessor
- Program to Divide two 8 Bit numbers in 8051 Microprocessor
- Program branch group in 8051
- Program memory structure of Intel 8051
- Compile 32-bit program on 64-bit gcc in C and C++
- Matrix manipulation in Python
- Arithmetic group in 8051
- Logical Group in 8051
