Checking for palindrome in 8086 ALP
Palindrome check for a given string in 8086 Assembly language.
The program prompts the user for a string and checks whether the given string is a palindrome and displays the appropriate message.

; Checking for palindrome in 8086 ALP

;macro for printing a string
print macro m
mov ah,09h
mov dx,offset m
int 21h

.model small

;******  Data Segment ******

empty db 10,13, "   $"
str1 db 25,?,25 dup('$')
str2 db 25,?,25 dup('$')
len db ?
mstring db 10,13, "Enter the string: $"
notpalin db 10,13, "String is not a palindrome. $"
palin db 10,13, "String is a palindrome. $"

;********** Code Segment ************


mov ax,@data
mov ds,ax


		print mstring
        call accept_string

        mov si,offset str1
		mov cl,str1+1        ;store the length
		mov ch,00h
		mov len,cl
		inc si
		add si,cx            ;si points to last
		mov di,offset str1   ;di to start of string
		add di,0002h         ;di to actual start of string;
		;in string 0th byte->size
		;          1st byte->length of string
        ;          from 2nd byte->actual string 		
		mov cl,len ;load counter
 cmpagain: mov al,[si]
           mov ah,[di]
		   inc di
		   dec si
           cmp al,ah
           jne nopalin
		   dec cl
		   jnz cmpagain
		print palin
		jmp exit
nopalin: print notpalin

mov ah,4ch       ;exit the program
int 21h

;accept procedure

accept proc near

mov ah,01
int 21h
accept endp

display1 proc near

   mov al,bl
   mov bl,al
   and al,0f0h
   mov cl,04
   rol al,cl

   cmp al,09
   jbe number
   add al,07
number:  add al,30h
         mov dl,al
         mov ah,02
         int 21h

         mov al,bl
         and al,00fh
         cmp al,09
         jbe number2
         add al,07
number2:  add al,30h
          mov dl,al
          mov ah,02
          int 21h
display1 endp

accept_string proc near

mov ah,0ah          ;accept string from user function
mov dx,offset str1  ; store the string in memory pointed by "DX"
int 21h
accept_string endp

end start

comments powered by Disqus