内联汇编实现 memcpy 和 memset

#pragma check_stack( off)



LPVOID   __cdecl _memcpy(void * dst, void* src,  size_t size)

{

	int dwSize = size/4;

	int byteSize = size%4;

	__asm{

		mov edi,dst

		mov esi,src

		mov ecx,dwSize

		rep movs dword ptr es:[edi],dword ptr ds:[esi]

		mov ecx,byteSize

		rep movs byte  ptr es:[edi],byte ptr ds:[esi]

	}



	return dst;

}

#pragma check_stack( off)

LPVOID    __cdecl  __memset( void * dst,  int val,  size_t size)

{ 



	int dwSize = size/4;

	int byteSize = size%4;

	int fixVal;

	__asm{

		mov eax,val

		lea edi,  fixVal

		mov ecx,4 

		rep stos byte ptr es:[edi]

		

		mov eax, fixVal

		mov ecx, dwSize

		mov edi,dst

		rep stos dword ptr es:[edi]

		mov ecx, byteSize

		rep stos byte ptr es:[edi]

	}



	return dst;



}

  

你可能感兴趣的:(set)