.model small
.stack 100h
.data
msg1 db 'Enter 1st string $'
msg2 db 'Enter 2nd string $'
msg4 db 'Result string is-> $'
s1 db 50 dup('$')
s2 db 50 dup('$')
s3 db 50 dup('$')
len1 dw ?
len2 dw ?
pos dw 0
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
;display 'enter 1st string'
lea dx,msg1
call display
;read the 1st string
lea di,s1
call readstr
endinpt:mov len1,cx
;jump to nextline
call newline
;display 'enter 2nd string'
lea dx,msg2
call display
;read the 2nd string
lea di,s2
call readstr
endinp1:mov len2,cx
;find the position
xor dx,dx
mov ax,len1
mov bx,02h
div bx
mov pos,ax
;insert a string into another string
endpos: xor cx,cx
lea si,s1
lea di,s3
cld
mov cx,pos
rep movsb
mov dx,si
lea si,s2
mov cx,len2
rep movsb
mov cx,len1
sub cx,pos
mov si,dx
rep movsb
;jump to nextline
call newline
;display 'Result string is-> '
lea dx,msg4
call display
;print result string
lea dx,s3
call display
mov ah,4ch
int 21h
main endp
display proc
mov ah,09h
int 21h
ret
display endp
newline proc
mov dl,0ah
mov ah,02h
int 21h
ret
newline endp
readstr proc
xor cx,cx
cld
loop1: mov ah,01
int 21h
cmp al,0dh
je endread
stosb
inc cx
jmp loop1
endread:ret
readstr endp
end
No comments:
Post a Comment