内联汇编实现 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; }
如无特别说明, 文章为本人原创, 转载请注明出处, 也欢迎批评指正
-------------------------------------------------------------------
如有问题, 欢迎邮箱讨论: lyogogo@outlook.com
-------------------------------------------------------------------
如有问题, 欢迎邮箱讨论: lyogogo@outlook.com