使用汇编实现判断字符串是否相等


#include
#include

char i1[] = {"123456789"};
char i2[] = {"123456789"};
static _declspec(naked) int repzcmpsb(char i1[],char i2[],int size) {
	__asm {
		pushad
		mov ebp,esp
		mov esi, dword ptr ds : [ebp + 0x24]
		mov edi, dword ptr ds : [ebp + 0x28]
		mov ecx, dword ptr ds : [ebp + 0x2C]
		repz cmpsb
		jnz no
		popad
		mov eax,1
		ret
		no:
		popad
		mov eax,2
		ret
	}
}

int main() {

	if (repzcmpsb(i1, i2, sizeof(i1) - 1)==1) {
		std::cout << "字符串相等" << std::endl;
	}
	else {
		std::cout << "字符串不相等" << std::endl;
	}
}

你可能感兴趣的:(c++,汇编,反汇编,字符串,c++,asm)