PROWAREtech

articles » current » assembly » x86 » procedures » wcscmp

x86 Assembly: wcscmp Procedure

compare two wide-char strings.

Use MASM for Visual C++ Express Edition 2005 to compile this procedure.

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);'

.386P

.model FLAT

PUBLIC	_wcscmp_asm

_TEXT	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
_TEXT	ENDS
END

This site uses cookies. Cookies are simple text files stored on the user's computer. They are used for adding features and security to this site. Read the privacy policy.
CLOSE