
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 Check if 16-Bit Number is Palindrome
In this program, we will see how to check a 16-bit number is a palindrome or not.
Problem Statement
Write the 8085 Assembly language program to check a 16-bit number is palindrome or not. The number is stored at location 8000H and 8001H.
Discussion
A number is a palindrome if the number and its reversed sequence is the number itself. For example, 5225 is a palindrome, but ABCD is not a palindrome.
In this problem, we are taking the number and store it into the HL pair. Then we are performing the reverse operation on L content. If the H and updated L value are the same, then the number is a palindrome. To check that we are doing XOR operation on H and L. When the result is 0, it is a palindrome, otherwise, it is not a palindrome.
If the number is palindrome we are storing FFH at location 8050H, and when it is not palindrome the 00H is stored at 8050H.
Input
Address |
Data |
---|---|
… |
… |
8000 |
25 |
8001 |
52 |
… |
… |
Input
Address |
Data |
---|---|
… |
… |
8000 |
CD |
8001 |
AB |
… |
… |
Flow Diagram
Program
Address |
HEX Codes |
Labels |
Mnemonics |
Comments |
---|---|---|---|---|
F000 |
2A, 00, 80 |
|
LHLD 8000H |
Take the 16-bit number from memory to HL pair |
F003 |
7D |
|
MOV A,L |
Take L to A |
F004 |
0F |
|
RRC |
Rotate Acc four times |
F005 |
0F |
|
RRC |
|
F006 |
0F |
|
RRC |
|
F007 |
0F |
|
RRC |
|
F008 |
AC |
|
XRA H |
XOR Acc and H |
F009 |
3E, FF |
|
MVI A,FFH |
Load FFH into A |
F00B |
CA, 0F, F0 |
|
JZ STORE |
If Z = 1, jump to store |
F00E |
AF |
|
XRA A |
Otherwise load A = 0 |
F00F |
32, 50, 80 |
STORE |
STA 8050H |
Store result at 8050H |
F012 |
67 |
|
HLT |
Terminate the program |
Output
Address |
Data |
---|---|
… |
… |
8050 |
FF |
… |
… |
Output
Address |
Data |
---|---|
… |
… |
8050 |
00 |
… |
… |