Palindrome - Assembly Language - MASM


PALINDROME OR NOT

Program:
.model small
.stack 200H
.data
   msg1 DB 10,13,'enter the string: $'
   msg2 DB 10,13,'PALINDROME $'
   msg3 DB 10,13,'NOT PALINDROME $'
   newline DB 10,13,' $'
   count db ?
   tab db 20 dup(?)
.code
   print MACRO msg ;macro definition
   PUSH AX
   PUSH DX
   MOV AH,09H
   MOV DX,offset msg
   INT 21H
   POP DX
   POP AX
   ENDM
.startup
   print msg1
   print newline
   mov si ,offset tab
   mov di,offset tab
   mov dx,00
   mov cx,00
rdnxt:
   mov ah,01h
   int 21h
   mov [si],al
   inc si
   inc dx
   cmp al,'$'
   jne rdnxt
   dec si
   dec si
   dec dx
   mov cx,dx
   print newline
nxtchar:
   mov dl,[si]
   mov dh,[di]
   cmp dl,dh
   jne palin
   inc di
   dec si
   loop nxtchar
   print msg2
   jmp ext
palin:
   print msg3
ext:
   .exit
END

Output:
F:\>pal
enter the string:
malayalam$
PALINDROME
F:\>pal
enter the string:
computer$
NOT PALINDROME

1 comment:

  1. russian translation services Thank you for sharing this article. I love it. Keep on writing this type of great stuff.

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...