Concatenate String & Check Palindrome - Assembly Language - MASM

Program:
.model small
.data
    mes1 db 10,13,"enter the first string",10,13,"$"
    mes2 db 10,13,"enter the second string",10,13,"$"
    mes3 db 10,13,"the concatinated string is:",10,13,"$"
    mes4 db 10,13,"the string is a palindrome",10,13,"$"
    mes5 db 10,13,"the string is not a palindrome",10,13,"$"
    arr db 100  

.code
.startup

    lea dx,mes1
    mov ah,09h
    int 21h
    lea dx,arr
    mov ah,0ah
    int 21h

    mov si,2
    mov bl,arr[1]
    mov bh,00h
    mov di,bx
    inc di
    inc di

    lea dx,mes2
    mov ah,09h
    int 21h

l1:
   mov ah,01h
   int 21h
   cmp al,13
   je l2
   mov arr[di],al
   inc di
   jmp l1

l2:
   lea dx,mes3
   mov ah,09h
   int 21h

l3:
   cmp si,di
   je l4
   mov dl,arr[si]
   mov ah,02h
   int 21h
   inc si
   jmp l3

l4:
    mov si,2
    dec di
    
l5:
     mov bl,arr[si]
     mov bh,00h
     mov cl,arr[di]
     mov ch,00h

     cmp bl,cl
     jne l6
     cmp di,si
     je l7
     inc si
     dec di
     jmp l5

l6:
     lea dx,mes5
     mov ah,09h
     int 21h
     jmp exit1

l7:
     lea dx,mes4
     mov ah,09h
     int 21h
     jmp exit1

exit1:
   .exit
   end

  

2 comments:

Related Posts Plugin for WordPress, Blogger...