
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
8085 Program to Reverse 16 Bit Number
In this program we will see how to reverse the digits of a 16-bit number using 8085.
Problem Statement
Write 8085 Assembly language program to reverse a 16-bit number stored at location 8000H-8001H. Also, store the result at 8050H – 8051H.
Discussion
Here the task is too simple. There are some rotating instructions in 8085. The RRC, RLC are used to rotate the Accumulator content to the right and left respectively without carry. We can use either RRC or RLC to perform this task. In the final result each digit of the H and L are reversed, and also the H and L values are reversed. Thus the total reverse operation is done.
Input
Address |
Data |
---|---|
… |
… |
8000 |
AB |
8001 |
CD |
… |
… |
Flow Diagram
Program
Address |
HEX Codes |
Labels |
Mnemonics |
Comments |
---|---|---|---|---|
F000 |
2A, 00, 80 |
|
LHLD 8000H |
Take the number into HL pair |
F003 |
7D |
|
MOV A,L |
Load L to A |
F004 |
0F |
|
RRC |
Rotate right without carry four times |
F005 |
0F |
|
RRC |
|
F006 |
0F |
|
RRC |
|
F007 |
0F |
|
RRC |
|
F008 |
6F |
|
MOV L,A |
Store reversed number into L again |
F009 |
7C |
|
MOV A,H |
Load LH to A |
F00A |
0F |
|
RRC |
Rotate right without carry four times |
F00B |
0F |
|
RRC |
|
F00C |
0F |
|
RRC |
|
F00D |
0F |
|
RRC |
|
F00E |
65 |
|
MOV H,L |
Take L to H |
F00F |
6F |
|
MOV L,A |
Store reversed number into L |
F010 |
22, 50, 80 |
|
SHLD 8050H |
Store the result at memory |
F013 |
76 |
|
HLT |
Terminate the program |
Output
Address |
Data |
---|---|
… |
… |
8050 |
DC |
8051 |
BA |
… |
… |
Advertisements