Assembly code snippets
Details
Title | Insert String using MMX |
---|---|
Author | The Svin |
Submitted by: | The Svin |
Date added: | 2002-02-20 15:39:44 |
Date modified: | 2002-02-20 15:39:44 |
Comments
This proc inserts String2 into String1 in position specified by index.
Snippet
szInsertString2 proc uses ebx esi edi lpString1,lpString2,len1,len2,index
mov esi,lpString1 ; esi = lpString1
mov ebx,len1 ; ebx = len1
mov eax,index ;eax = index
mov ecx,len2 ;ecx = len2
add esi,eax
mov edi,ecx
mov edx,esi
and esi,not 7
and edx,7
lea edi,[esi][ecx]
neg eax
push ecx
lea ecx,[eax][ebx][7]
neg eax
sub ecx,edx
shr ecx,3
@@: movq mm(0),[esi][ecx*8]
movq [edi][ecx*8],mm(0)
dec ecx
jns @B
emms
mov edi,lpString1
pop ecx
mov edx,ecx
mov esi,lpString2
add edi,eax ;edi = String1+index
and ecx,not 3
je @bytes
add edi,ecx
add esi,ecx
neg ecx
@@: mov eax,[esi][ecx]
mov [edi][ecx],eax
add ecx,4
jne @B
@bytes:
and edx,3
je @exit
add esi,edx
add edi,edx
neg edx
@@: mov al,[esi][edx]
mov [edi][edx],al
inc edx
jne @B
@exit:
ret
szInsertString2 endp
mov esi,lpString1 ; esi = lpString1
mov ebx,len1 ; ebx = len1
mov eax,index ;eax = index
mov ecx,len2 ;ecx = len2
add esi,eax
mov edi,ecx
mov edx,esi
and esi,not 7
and edx,7
lea edi,[esi][ecx]
neg eax
push ecx
lea ecx,[eax][ebx][7]
neg eax
sub ecx,edx
shr ecx,3
@@: movq mm(0),[esi][ecx*8]
movq [edi][ecx*8],mm(0)
dec ecx
jns @B
emms
mov edi,lpString1
pop ecx
mov edx,ecx
mov esi,lpString2
add edi,eax ;edi = String1+index
and ecx,not 3
je @bytes
add edi,ecx
add esi,ecx
neg ecx
@@: mov eax,[esi][ecx]
mov [edi][ecx],eax
add ecx,4
jne @B
@bytes:
and edx,3
je @exit
add esi,edx
add edi,edx
neg edx
@@: mov al,[esi][edx]
mov [edi][edx],al
inc edx
jne @B
@exit:
ret
szInsertString2 endp