8085 program to check whether the given 16 bit number is palindrome or not

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.

Data

8000
25
8001
52

Data

8000
CD
8001
AB

Program

HEX Codes
Labels
Mnemonics
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
F00B
CA, 0F, F0

JZ STORE
F00E
AF

XRA A
F00F
32, 50, 80
STORE
STA 8050H
Store result at 8050H
F012
67

HLT
Terminate the program

Data

8050
FF

Output

Data

8050
00

Updated on: 30-Jul-2019

234 Views