You are on page 1of 2

.

model small
.stack 64
.data
strAsk db 10,"Enter a word: (Maximum
of 25 Characters)$"
strPrompt db 10,"Do you want to enter
a word again?(y/n)$"
str2 db "Your string is: $"
str3 db "Reverse string: $"
myword db 25 dup("$")
wordrev db 25 dup("$")
NEWLINE DB 10,13,"$"
N DB ?
S DB ?
strPal db 10,"The word you entered is a
palindrome!$"
strNotPal db 10,"The word you entered
is not a palindrome!$"



.code
main proc far
mov ax, @data
mov ds, ax

lea si, myword

;Get String
MOV AH,09H
LEA DX,strask
INT 21H

MOV AH,0AH
MOV DX,SI
INT 21H


MOV AH,09H
LEA DX,NEWLINE
INT 21H
;PRINT THE STRING

MOV AH,09H
LEA DX,STR2
INT 21H

MOV AH,09H
LEA DX,myword+2
INT 21H

MOV AH,09H
LEA DX,NEWLINE
INT 21H
;PRINT THE REVERSE OF THE STRING

MOV AH,09H
LEA DX,STR3
INT 21H

MOV CL,myword+1
ADD CL,1
ADD SI,2

L1:
INC SI

CMP BYTE PTR[SI],"$"
JNE L1

DEC SI

LEA DI,wordrev

L2:MOV AL,BYTE PTR[SI]

MOV BYTE PTR[DI],AL

DEC SI
INC DI
LOOP L2

MOV AH,09H
LEA DX,NEWLINE
INT 21H

MOV AH,09H
LEA DX,wordrev
INT 21H


MOV AH,09H
LEA DX,NEWLINE
INT 21H


;PRINT THE STRING IS PALINDROME OR NOT

LEA SI,myword
LEA DI,wordrev

MOV AH,09H
LEA DX,NEWLINE
INT 21H

ADD SI,2

L7:
MOV BL,BYTE PTR[DI]


CMP BYTE PTR[SI],BL
JNE LL2


INC SI
INC DI

MOV BL,BYTE PTR[DI]

MOV AH,02H
MOV DL,BL
INT 21H

MOV AH,09H
LEA DX,NEWLINE
INT 21H



CMP BYTE PTR[DI],"$"
JNE L7

MOV AH,09H
LEA DX,NEWLINE
INT 21H

MOV AH,09H
LEA DX,strpal
INT 21H

JMP L5

LL2:
MOV AH,09H
LEA DX,NEWLINE
INT 21H

MOV AH,09H
LEA DX,strnotpal
INT 21H

L5:

MOV AH,4CH
INT 21H


main endp


end main

You might also like