%OUT-------------------------------------------------------------------------
%OUT- Checks whether stored string is/is not a Palindrome
%out- output: 'String' -> Palindrome or not
%out – author: Ayon and Ariyam
%OUT-------------------------------------------------------------------------
if1
include macrolib.lby
endif
.model small
.stack
.data
LF equ 0ah ;line feed
string db "malayalam","$" ;will hold the string
str1 db LF," -> ","$"
str_len db 1 dup(?)
pal db "Yes! Palindrome","$"
npal db "No! not Palindrome","$"
i_p db "String: ","$"
.code
main proc
mov ax,@data
mov ds,ax
str_length string ;get length of string in AL
mov ah,00h
mov di,ax
dec di ;point to last char
mov dl,al ;save al in dl
mov bl,02h
div bl ;half the length
mov cl,al ;work as counter
mov ch,00h
mov si,0000h
showmsg i_p
showmsg string
showmsg str1
lp1:
mov al,string[si]
cmp al,string[di]
jne np ;char mismatch, not palindrome
inc si
dec di
loop lp1
;if control reaches here, it is a palindrome
showmsg pal
jmp done
np: showmsg npal
done:
exit
main endp
end main
%OUT- Checks whether stored string is/is not a Palindrome
%out- output: 'String' -> Palindrome or not
%out – author: Ayon and Ariyam
%OUT-------------------------------------------------------------------------
if1
include macrolib.lby
endif
.model small
.stack
.data
LF equ 0ah ;line feed
string db "malayalam","$" ;will hold the string
str1 db LF," -> ","$"
str_len db 1 dup(?)
pal db "Yes! Palindrome","$"
npal db "No! not Palindrome","$"
i_p db "String: ","$"
.code
main proc
mov ax,@data
mov ds,ax
str_length string ;get length of string in AL
mov ah,00h
mov di,ax
dec di ;point to last char
mov dl,al ;save al in dl
mov bl,02h
div bl ;half the length
mov cl,al ;work as counter
mov ch,00h
mov si,0000h
showmsg i_p
showmsg string
showmsg str1
lp1:
mov al,string[si]
cmp al,string[di]
jne np ;char mismatch, not palindrome
inc si
dec di
loop lp1
;if control reaches here, it is a palindrome
showmsg pal
jmp done
np: showmsg npal
done:
exit
main endp
end main
No comments:
Post a Comment
Do you think this information useful or was not up to the mark? Comment if you have any advices or suggestions about the post.