printmsg macro msg
mov ah,09h
lea dx,msg
int 21h
endm
data segment
n db 0
array db 40 dup(0)
revarray db 40 dup(0)
cr equ 0dh
msg1 db "Enter a string:$"
msg2 db 0ah,0dh,"Palindrome$"
msg3 db 0ah,0dh,"Not Palindrome$"
msg4 db 0ah,0dh,"$"
msg5 db 0ah,0dh,"Reversed string$"
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
lea si,array
mov cl,00
printmsg msg1
printmsg msg4
l1:
mov ah,01h
int 21h
cmp al,cr
je p2
sub al,30h
mov [si],al
inc si
inc cl
jmp l1
p2:
mov n,cl
mov ch,'$'
mov [si],ch
printmsg msg4
dec si
lea di,revarray
x2:
mov al,[si]
mov [di],al
inc di
dec si
dec cl
cmp cl,00
jne x2
mov cl,'$'
mov [di],cl
lea di,revarray
printmsg msg4
printmsg msg5
printmsg msg4
y2:
mov dl,[di]
add dl,30h
mov ah,02h
int 21h
inc di
mov ch,[di]
cmp ch,'$'
jne y2
printmsg msg4
mov si,offset array
mov di,offset revarray
mov cl,n
w2:
mov al,[si]
cmp al,[di]
jne w1
inc si
inc di
dec cl
cmp cl,00
jne w2
printmsg msg2
jmp w4
w1:
printmsg msg3
w4:mov ah,4ch
int 21h
code ends
end start
0 comments:
Post a Comment