03-Write an ALP in 8086 to perform String manipulation using FAR Procedure

Write an ALP in 8086 to perform String manipulation using FAR
   Procedure
   1) Concatenation of two strings
   2) No. of occurrences of sub-strings
        in the given string.

.model small

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


EXTRN str1:byte
EXTRN str2:byte
public concatenate
public substring

.data

cnt db 00h

msg1 db 10,13,10,13,"It is a substring.$"
msg2 db 10,13,10,13,"It is not a substring.$"
msg3 db 10,13,10,13,"The no of occurences is:$"

.code
   main:
      mov ax,@data
      mov ds,ax
     
      concatenate proc far
         mov cl,str1[1]
         mov dl,str2[1]
         lea SI,str1[2]
         lea DI,str2[2]
         mov ch,00h
         mov dh,00h
         add SI,cx
         l1:
            mov bl,[DI]
            mov [SI],bl
            inc SI
            inc DI
            dec dl
            jnz l1
         add cl,dl
         mov str1[1],cl

         retf
     concatenate endp

   
     substring proc far
         mov cnt,00h
         mov bl,str1[1]
         mov bh,str2[1]
         lea SI,str1[2]
         lea DI,str2[2]
         up:
            mov dl,[SI]
            cmp dl,[DI]
            je l2
            inc SI
            lea DI,str2[2]
            dec bl
            cmp bl,00h
            jnz up
            jmp l3
         l2:
            inc SI
            inc DI
            dec bl
            dec bh
            jnz up
            lea DI,str2[2]
            mov bh,str2[1]
            inc cnt
            cmp bl,00
            jne up      
         l3:
            cmp cnt,00
            je down
            disp msg1
            jmp exit
         down:
            disp msg2
         exit:
            disp msg3
            call print
       
             retf
     substring endp


     print proc near

         mov bl,cnt
         mov bh,00h
         shr bl,04h
         cmp bl,09h
         jle down2
         add bl,07h
         down2:
            add bl,30h
            mov dl,bl
            mov ah,02h
            int 21h

         mov bl,cnt
         mov bh,00h
         and bl,0Fh
         cmp bl,09h
         jle down5
         add bl,07h
         down5:
            add bl,30h
            mov dl,bl
            mov ah,02h
            int 21h
         ret
      print endp
   end main
end

Previous
Next Post »

Disqus Shortname

Comments system