SE Comp Sem-II MIL Prac-7 (String Operation-FAR-B)

;string 8b


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


.model small
.stack
     GLOBAL str1:byte,len1:byte
     PUBLIC compare,substring,concatenate
.data
    

     str2   db 25,?,25 dup('$')
     len2   db 00h
     count  db 00h
     msg1   db 10,13,'ENTER STRING 2: $'
     msg2   db 10,13,'LENGTH STRING 2: $'
     msg3   db 10,13,'STRINGS ARE EQUAL $'
     msg4   db 10,13,'STRINGS ARE NOT EQUAL $'
     msg5   db 10,13,'CONCATENATED STRING IS: $'
     msg6   db 10,13,'SECOND STRING IS NOT SUB STRING OF STRING 1$'
     msg7   db 10,13,'SECOND STRING IS SUB STRING AND OCCURED $'
     msg8   db ' TIMES $' 

.code
     mov ax,@data
     mov ds,ax
     mov es,ax

;compare
compare proc near
     call input
     lea si,str1+2
     lea di,str2+2
     mov cl,str1+1
     mov ch,str2+1
     cmp cl,ch
     jnz l1
     mov ch,00h
     cld
     rep cmpsb
     jne l1
     disp msg3
     ret

l1:
     disp msg4
     ret

endp


;substring
substring proc near
         call input
         mov count,00h
         lea si,str1+2
         lea di,str2+2
         mov bl,len1
         mov ch,00h
         mov al,[si]
loop1:   cmp al,[di]
         jne c
         push si
         push di
         mov cl,len2
loop2:
         rep cmpsb
         cmp cl,00h
         jne d
         inc count

      d: pop di
         pop si

      c: inc si
         mov al,[si]
         dec bl
         jnz loop1

         cmp count,00h
         je e
         disp msg7
         mov dl,count
         add dl,30h
         mov ah,02h
         int 21h
         disp msg8
         jmp f

     e:  disp msg6

     f:  ret
endp

;concatenate
concatenate proc near
         call input
         disp msg5
         lea si,str1+2
         lea di,str2+2
         mov al,str1+1
         mov ah,00h
         mov cl,str2+1
         mov ch,00h
         add si,ax

   c1:   mov bl,[di]
         mov [si],bl
         inc si
         inc di
         dec cl
         jnz c1

         disp str1+2

ret
endp


;input
input proc near
    disp msg1
    mov ah,0ah
    lea dx,str2
    int 21h


    mov al,str2+1
    mov len2,al
   
ret
endp

  mov ax,4c00h
  int 21h

end

No comments:

Post a Comment