8085 program to reverse 16 bit number
Problem – Write an assembly language program in 8085 microprocessor to reverse 16 bit number.
Example – Assume 16 bit number is stored at memory location 2050 and 2051.

Algorithm –
- Load contents of memory location 2050 in register L and contents of memory location 2051 in register H
- Move contents of L in accumulator A
- Reverse the contents of A by executing RLC instruction 4 times
- Move the contents of A in L
- Move the contents of H in A
- Reverse the contents of A by executing RLC instruction 4 times
- Move the contents of L in H
- Move the contents of A in L
- Store the content of L in memory location 2050 and contents of H in memory location 2051
Program –
| MEMORY ADDRESS | MNEMONICS | COMMENT |
|---|---|---|
| 2000 | LHLD 2050 | L <- M[2050], H <- M[2051] |
| 2003 | MOV A, L | A <- L |
| 2004 | RLC | Rotate accumulator content left by 1 bit without carry |
| 2005 | RLC | Rotate accumulator content left by 1 bit without carry |
| 2006 | RLC | Rotate accumulator content left by 1 bit without carry |
| 2007 | RLC | Rotate accumulator content left by 1 bit without carry |
| 2008 | MOV L, A | L <- A |
| 2009 | MOV A, H | A <- H |
| 200A | RLC | Rotate accumulator content left by 1 bit without carry |
| 200B | RLC | Rotate accumulator content left by 1 bit without carry |
| 200C | RLC | Rotate accumulator content left by 1 bit without carry |
| 200D | RLC | Rotate accumulator content left by 1 bit without carry |
| 200E | MOV H, L | H <- L |
| 200F | MOV L, A | L <- A |
| 2010 | SHLD 2050 | M[2050] <- L, M[2051] <- H |
| 2013 | HLT | END |
Explanation – Registers A, H, L are used for general purpose.
- LHLD 2050: loads contents of memory location 2050 in L and 2051 in H.
- MOV A, L: moves content of L in A.
- RLC: shift the content of A left by one bit without carry. Repeat the current instruction 4 times so that contents of A get reversed.
- MOV L, A: moves the content of A in L.
- MOV A, H: moves the content of H in A.
- RLC: shift the content of A left by one bit without carry. Repeat the current instruction 4 times so that contents of A get reversed.
- MOV H, L: moves the content of L in H.
- MOV L, A: moves the content of A in L.
- SHLD 2050: stores the content of L in 2050 and H in 2051.
- HLT: stops executing the program and halts any further execution.
Recommended Posts:
- 8085 program to reverse 8 bit number
- 8085 program to check whether the given number is even or odd
- 8085 program to convert an 8 bit number into Grey number
- 8085 program to convert an 8 bit BCD number into hexadecimal number
- 8085 program to find square of a 8 bit number
- 8085 program to determine if the number is prime or not
- 8085 program to find 1's and 2's complement of 8-bit number
- 8085 program to check whether the given 16 bit number is palindrome or not
- 8085 program to count number of elements which are less than 0A
- 8085 program to convert a BCD number to binary
- 8085 program to find the factorial of a number
- 8085 program to find nth power of a number
- 8085 program to find 1’s and 2’s complement of 16-bit number
- 8085 program to find sum of digits of 8 bit number
- 8085 program to count number of once in the given 8-bit number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



