Thursday, 16 April 2009

Palindrome

This is a program in 8086 ASM to check the given string is palindrome or not.
The program is compiled in MASM compiler.

data segment
msg1 db "Enter the string: $"
msg2 db 0ah,0dh,"Reversed string is: $"
msg3 db 0dh,0ah,"Not palindrome...........$"
msg4 db 0dh,0ah," palindrome...........$"
ent db 0dh,0ah,"$"
str1 db 100 dup(?)
rev db 100 dup(?)
data ends

print macro msg
lea dx,msg
mov ah,09h
int 21h
endm

read macro
mov ah,01h
int 21h
endm

code segment
start:
mov ax,data
mov ds,ax
mov bx,0000h
lea si,str1
print msg1

L1:
read
mov [si],al
inc bx
inc si
cmp al,0dh
jnz L1


dec si
mov cx,bx
lea di,rev

L2:
mov al,[si]
mov [di],al
inc di

dec si
dec cx
jnz L2

print msg2
add si,bx

mov cx,bx
print ent

L3:
mov al,[si]
mov dl,al
mov ah,02h
int 21h
dec si
dec cx
jnz L3

sub di,bx
mov cx,bx

L4:
dec cx
jz p
inc si
inc di
mov al,[si]
cmp al,[di]
jz L4
print msg3 ;not paliandrome
jmp en

p:
print msg4 ;paliendrome
en:
mov ah,4ch
int 21h
code ends
end start

ret


querrymail@gmail.com

0 comments: