Helenr
page ,132title strcmp.asm - compare two strings;***;strcmp.asm - routine to compare two strings (for equal, less, or greater);; Copyright (c) Microsoft Corporation. All rights reserved.;;Purpose:; STRCMP compares two strings and returns an integer; to indicate whether the first is less than the second, the two are; equal, or whether the first is greater than the second, respectively.; Comparison is done byte by byte on an UNSIGNED basis, which is to; say that Null (0) is less than any other character (1-255).;;*******************************************************************************.xlistinclude cruntime.inc.listpage;***;strcmp - compare two strings, returning less than, equal to, or greater than;;Purpose:; Compares two string, determining their lexical order. Unsigned; comparison is used.;; Algorithm:; int strcmp ( src , dst ); unsigned char *src;; unsigned char *dst;; {; int ret = 0 ;;; while( ! (ret = *src - *dst) && *dst); ++src, ++dst;;; if ( ret < 0 ); ret = -1 ;; else if ( ret > 0 ); ret = 1 ;;; return( ret );; };;Entry:; const char * src - string for left-hand side of comparison; const char * dst - string for right-hand side of comparison;;Exit:; AX < 0, 0, or >0, indicating whether the first string is; Less than, Equal to, or Greater than the second string.;;Uses:; CX, DX;;Exceptions:;;*******************************************************************************CODESEGpublic strcmpstrcmp proc \str1:ptr byte, \str2:ptr byteOPTION PROLOGUE:NONE, EPILOGUE:NONE.FPO ( 0, 2, 0, 0, 0, 0 )mov edx,[esp + 4] ; edx = srcmov ecx,[esp + 8] ; ecx = dsttest edx,3jnz short dopartialalign 4dodwords:mov eax,[edx]cmp al,[ecx]jne short doneneor al,aljz short doneeqcmp ah,[ecx + 1]jne short doneneor ah,ahjz short doneeqshr eax,16cmp al,[ecx + 2]jne short doneneor al,aljz short doneeqcmp ah,[ecx + 3]jne short doneneadd ecx,4add edx,4or ah,ahjnz short dodwordsalign 4doneeq:xor eax,eaxretalign 4donene:; The instructions below should place -1 in eax if src < dst,; and 1 in eax if src > dst.sbb eax,eaxsal eax,1add eax,1retalign 4dopartial:test edx,1jz short dowordmov al,[edx]add edx,1cmp al,[ecx]jne short doneneadd ecx,1or al,aljz short doneeqtest edx,2jz short dodwordsalign 4doword:mov ax,[edx]add edx,2cmp al,[ecx]jne short doneneor al,aljz short doneeqcmp ah,[ecx + 1]jne short doneneor ah,ahjz short doneeqadd ecx,2jmp short dodwordsstrcmp endp