Assembly Program to check for Palindrome String



This program will get a string from the user and tell whether it is palindrome or not. Palindrome string is a string that remains the same if it gets reversed.

The basic idea is after getting the string from the user and storing it. The program reverses that stored string and stores the reversed string as well after storing the string the program compare both strings character by character.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
.MODEL SMALL
.STACK 100H
.DATA 
MSG DB "ENTER A STRING: $"
STRING1 DB 10 DUP(?)
STRING2 DB 10 DUP(?)
PALINDROMEMSG DB 0DH, 0AH, "STRING IS PALINDROME $"
NOTPALINDROMEMSG DB 0DH, 0AH, "STRING IS NOT PALINDROME $"
.CODE
MAIN PROC
    
    MOV AX, @DATA
    MOV DS, AX
    MOV ES, AX
    
    MOV AH, 9
    LEA DX, MSG
    INT 21H
    
    LEA DI, STRING1
    
    MOV BX, 0 
    MOV AH, 1
    READ:
    INT 21H
    CMP AL, 0DH
    JE ENDOFSTRING
    STOSB
    INC BX
    JMP READ
    
    ENDOFSTRING:
    MOV CX, BX
    DEC BX
    LEA SI, STRING1+BX
    LEA DI, STRING2
    STD

    INC BX
    
    AGAIN:
    MOVSB
    ADD DI, 2
    DEC BX
    CMP BX, 0
    JNE AGAIN
    
    LEA SI, STRING1
    LEA DI, STRING2
    
    MOV BX, 0
    COMPARE:
    MOV AH, STRING1[BX]
    MOV AL, STRING2[BX]
    CMP AH, 0H
    JE PALINDROME
    CMP AH, AL
    JNE NOTPALINDROME
    INC BX
    JMP COMPARE
    
    PALINDROME:
    
    MOV AH, 9
    LEA DX, PALINDROMEMSG
    INT 21H 
    
    JMP EXIT
    
    NOTPALINDROME: 
    
    MOV AH, 9
    LEA DX, NOTPALINDROMEMSG
    INT 21H 
    
    EXIT:
    
MAIN ENDP

END MAIN

Output:



No comments