Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
4.5 KiB

  1. page ,132
  2. title stricmp
  3. ;***
  4. ;stricmp.asm - contains ASCII only, case-insensitive, string comparision routine
  5. ; __ascii_stricmp
  6. ;
  7. ; Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  8. ;
  9. ;Purpose:
  10. ; contains __ascii_stricmp()
  11. ;
  12. ;Revision History:
  13. ; 05-18-88 SJM Add model-independent (large model) ifdef
  14. ; 08-04-88 SJM convert to cruntime/ add 32-bit support
  15. ; 08-23-88 JCR Minor 386 cleanup
  16. ; 10-10-88 JCR Added strcmpi() entry for compatiblity with early revs
  17. ; 10-25-88 JCR General cleanup for 386-only code
  18. ; 10-27-88 JCR Shuffled regs so no need to save/restore ebx
  19. ; 03-23-90 GJF Changed to _stdcall. Also, fixed the copyright.
  20. ; 01-18-91 GJF ANSI naming.
  21. ; 05-10-91 GJF Back to _cdecl, sigh...
  22. ; 10-20-94 GJF Made locale sensitive (i.e., now works for all
  23. ; single-byte character locales). Made multi-thread
  24. ; safe. Also, deleted obsolete _STDCALL_ code.
  25. ; 10-27-94 GJF Adapted above change for Win32S.
  26. ; 11-12-94 GJF Must avoid volatile regs or save them across function
  27. ; calls. Also, fixed bug in reg operand size.
  28. ; 07-03-95 CFW Changed offset of _lc_handle[LC_CTYPE], added sanity check
  29. ; to crtlib.c to catch changes to win32s.h that modify offset.
  30. ; 10-03-95 GJF New locale locking scheme.
  31. ; 11-13-95 GJF Made _strcmpi a proc instead of a label.
  32. ; 07-17-96 GJF Added lock prefix to increment and decrement of
  33. ; __unguarded_readlc_active
  34. ; 07-18-96 GJF Fixed race condition.
  35. ; 08-26-98 GJF All locale and multithread support moved up to
  36. ; stricmp.c. Renamed this file to _stricmp.asm.
  37. ; 06-12-01 PML inc->add 1, dec->sub 1 for Pentium 4 perf (vs7#267015)
  38. ;
  39. ;*******************************************************************************
  40. .xlist
  41. include cruntime.inc
  42. .list
  43. page
  44. ;***
  45. ;int __ascii_stricmp(dst, src) - compare strings, ignore case
  46. ;
  47. ;Purpose:
  48. ; _stricmp/_strcmpi perform a case-insensitive string comparision.
  49. ; For differences, upper case letters are mapped to lower case.
  50. ; Thus, "abc_" < "ABCD" since "_" < "d".
  51. ;
  52. ; Algorithm:
  53. ;
  54. ; int _strcmpi (char * dst, char * src)
  55. ; {
  56. ; int f,l;
  57. ;
  58. ; do {
  59. ; f = tolower(*dst);
  60. ; l = tolower(*src);
  61. ; dst++;
  62. ; src++;
  63. ; } while (f && f == l);
  64. ;
  65. ; return(f - l);
  66. ; }
  67. ;
  68. ;Entry:
  69. ; char *dst, *src - strings to compare
  70. ;
  71. ;Exit:
  72. ; AX = -1 if dst < src
  73. ; AX = 0 if dst = src
  74. ; AX = +1 if dst > src
  75. ;
  76. ;Uses:
  77. ; CX, DX
  78. ;
  79. ;Exceptions:
  80. ;
  81. ;*******************************************************************************
  82. CODESEG
  83. public __ascii_stricmp
  84. __ascii_stricmp proc \
  85. uses edi esi ebx, \
  86. dst:ptr, \
  87. src:ptr
  88. ; load up args
  89. mov esi,[src] ; esi = src
  90. mov edi,[dst] ; edi = dst
  91. mov al,-1 ; fall into loop
  92. align 4
  93. chk_null:
  94. or al,al
  95. jz short done
  96. mov al,[esi] ; al = next source byte
  97. add esi,1
  98. mov ah,[edi] ; ah = next dest byte
  99. add edi,1
  100. cmp ah,al ; first try case-sensitive comparision
  101. je short chk_null ; match
  102. sub al,'A'
  103. cmp al,'Z'-'A'+1
  104. sbb cl,cl
  105. and cl,'a'-'A'
  106. add al,cl
  107. add al,'A' ; tolower(*dst)
  108. xchg ah,al ; operations on AL are shorter than AH
  109. sub al,'A'
  110. cmp al,'Z'-'A'+1
  111. sbb cl,cl
  112. and cl,'a'-'A'
  113. add al,cl
  114. add al,'A' ; tolower(*src)
  115. cmp al,ah ; inverse of above comparison -- AL & AH are swapped
  116. je short chk_null
  117. ; dst < src dst > src
  118. sbb al,al ; AL=-1, CY=1 AL=0, CY=0
  119. sbb al,-1 ; AL=-1 AL=1
  120. done:
  121. movsx eax,al ; extend al to eax
  122. ret
  123. __ascii_stricmp endp
  124. end