PROWARE technologies
PROWARE technologies

wcscmp in x86 Assembly

This procedure, wcscmp_asm, compares two wchar_t (16-bit) strings. See also wcsicmp_asm.

The return value is:
less than zero if wcs1 is less than wcs2
equal to zero if wcs1 is equal to wcs2
greater than zero if wcs1 is greater than wcs2

TITLE 'extern "C" int wcscmp_asm(const wchar_t *wcs1, const wchar_t *wcs2);'
.686

.model FLAT

PUBLIC	_wcscmp_asm

_WCSCMP	SEGMENT
_wcscmp_asm	PROC NEAR

	mov  edx, DWORD PTR [esp+4] ; wcs1
	push esi
	mov  esi, DWORD PTR [esp+12] ; wcs2
	xor  ecx, ecx
	mov  cx, WORD PTR [esi]
	xor  eax, eax
	mov  ax, WORD PTR [edx]
	push edi
	mov  edi, ecx
	and  edi, 0000ffffH
	sub  eax, edi
	jne  SHORT label2

label1:

	test cx, cx
	je   SHORT label2

	add  esi, 2
	xor  ecx, ecx
	mov  cx, WORD PTR [esi]
	add  edx, 2
	xor  eax, eax
	mov  ax, WORD PTR [edx]
	mov  edi, ecx
	and  edi, 0000ffffH
	sub  eax, edi
	je   SHORT label1

label2:

	test eax, eax
	pop  edi
	pop  esi
	jge  SHORT label3

	or   eax, -1

	ret  0

label3:

	jle  SHORT label4

	mov  eax, 1

label4:

	ret  0

_wcscmp_asm	ENDP
_WCSCMP	ENDS
END