Tuesday, February 15, 2011

Insert a string in another string

Share Orkut
.model small .stack 100h .data msg1 db 'Enter 1st string $' msg2 db 'Enter 2nd string $' msg3 db 'Enter the position $' msg4 db 'Result string is-> $' s1 db 50 dup('$') s2 db 50 dup('$') s3 db 50 dup('$') len1 db ? len2 db ? pos db 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,cl ;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,cl ;jump to nextline call newline ;display 'enter the position' lea dx,msg3 call display ;enter the position mov cx,000ah inppos: mov ah,01h int 21h cmp al,0dh je endpos and al,0fh mov bl,al mov ah,00 mov al,pos mul cx add al,bl mov pos,al jmp inppos ;insert a string into another string endpos: xor ch,ch lea si,s1 lea di,s3 cld mov cl,pos rep movsb mov dx,si lea si,s2 mov cl,len2 rep movsb mov cl,len1 sub cl,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 cl,cl cld loop1: mov ah,01 int 21h cmp al,0dh je endread stosb inc cl jmp loop1 endread:ret readstr endp end

No comments:

Post a Comment