- 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
Binary to BCD conversion in 8051
In this problem, we will see how to convert an 8-bit binary number to its BCD equivalent. The binary number is stored at location 20H. After converting, the results will be stored at 30H and 31H. The 30H will hold the MS portion, and 31H will hold the LS portion.
So let us assume the data is D5H. The program converts the binary value of D5H to BCD value 213D.
Address | Value |
---|---|
. . . | |
20H | D5 |
21H | |
. . . |
Program
MOVR1,#20H;Takethe address 20H into R1 MOVA,@R1;Takethe data into Acc MOVB,#0AH;LoadB with AH = 10D DIVAB ;DivideA with B MOVR5,B;Storethe remainder MOVB,#0AH;LoadB with AH = 10D DIVAB ;DivideA with B MOVR1,#30H;Loaddestination address MOV@R1,A;Storethe MS portion MOVA,B;LoadB content to A SWAPA;Swapthe nibbles ADDA,R5;Addstored remainder with A INCR1;Increasethe address MOV@R1,A HALT: SJMPHALT
Here we are just taking the binary number into the accumulator. And then divide the content of accumulator by 0AH (10D). So the remainder partis stored into a separate register. This will be added later. Then again divide the quotient by 0AH, and generate the MS bits. After storing the MS bits, get the number from register B to the accumulator. Swap the nibbles of the accumulator to generate four zeros at the LSbits. Then add the previously stored remainder to generate the result.
Output
Address | Value |
---|---|
. . . | |
20H | D5 |
21H | |
. . . | |
30H | 02 |
31H | 13 |
. . . |
- Related Articles
- BCD to binary conversion in 8051
- Hex to ASCII conversion in 8051
- Conversion of four-digit hex to ASCII in 8051
- Shift a multi-byte BCD number to the right in 8051
- Binary Tree to Binary Search Tree Conversion in C++
- Decimal to Binary conversion\n
- Decimal to binary list conversion in Python
- Binary to original string conversion in JavaScript
- Program for Binary To Decimal Conversion in C++
- Program for Decimal to Binary Conversion in C++
- Decimal to binary conversion using recursion in JavaScript
- 8085 Program to convert a two-digit BCD to binary
- 8085 Program to convert an 8-bit binary to BCD
- Conversion of Binary to Gray Code\n
- Conversion of Gray Code to Binary\n
