- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- 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
Shift a multi-byte BCD number to the right in 8051
Here we will see a problem to shift some multi-byte BCD number to the right. The BCD numbers are shifted by two digits (8-bit).
Let us consider a four-byte BCD number (45 86 02 78) is stored at location 20H, 21H, 22H,23H. The address 10H holds the number of bytes of the whole BCD number. So after executing this code, the contents will be shifted to the right and 20H will hold 00H.
CLRA;Clear the Register A MOVR2,10H;TakeByte Count INCR2;Increase R2 for loop MOVR1,#20H;Takethe address 20H into R1 LOOP: XCHA,@R1; Get content, which is pointed out by R1 value INCR1;IncreaseR1 for next location JNZR2, LOOP ;Check R2 is 0 or not to loop back HALT: SJMPHALT ;Stop the program
Here the XCH instruction is used. By using this instruction, the value of register A and content of address pointed by R1 is swapped. Afters wapping, the address is moving one byte to the right, then exchange again to put the old value and take the new value. By using this procedure, the BCD bytes are shifted.
The counter value is increased by 1 at the beginning to run the program one more than the byte count. If the value is not incremented, the last byte will not be shifted, it will be discarded.
- Related Articles
- 8085 Program to Add two multi-byte BCD numbers
- 8085 Program for subtraction of multi-Byte BCD numbers
- Program for subtraction of multi-byte BCD numbers in 8085 Microprocessor
- Binary to BCD conversion in 8051
- BCD to binary conversion in 8051
- Shift right in a BigInteger in Java
- 8085 Program to Subtract two multi-Byte numbers
- Left Shift and Right Shift Operators in C/C++
- Program to Add two multi-byte numbers in 8085 Microprocessor
- Addition of multi-byte numbers in Z-80
- How to shift the colorbar position to right in matplotlib?
- Java Program to shift array elements to the right
- Bitwise right shift operators in C#
- What are Left Shift and Right Shift Operators (>> and