- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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.
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.
- BCD to binary conversion in 8051
- Hex to ASCII conversion in 8051
- Conversion of four-digit hex to ASCII in 8051
- Decimal to Binary conversion
- Shift a multi-byte BCD number to the right in 8051
- Binary Tree to Binary Search Tree Conversion in C++
- Conversion of Binary to Gray Code
- Conversion of Gray Code to Binary
- Decimal to binary list conversion in Python
- C Program for Decimal to Binary Conversion?
- Decimal to Binary conversion using C Programming
- Program for Binary To Decimal Conversion in C++
- Program for Decimal to Binary Conversion in C++