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.

155 lines
5.0 KiB

  1. page ,132
  2. title memicmp - compare blocks of memory, ignore case
  3. ;***
  4. ;memicmp.asm - compare memory, ignore case
  5. ;
  6. ; Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  7. ;
  8. ;Purpose:
  9. ; defines __ascii_memicmp() - compare two blocks of memory for lexical
  10. ; order. Case is ignored in the comparison.
  11. ;
  12. ;Revision History:
  13. ; 05-16-83 RN initial version
  14. ; 05-17-88 SJM Add model-independent (large model) ifdef
  15. ; 08-04-88 SJM convert to cruntime/ add 32-bit support
  16. ; 08-23-88 JCR Cleanup...
  17. ; 10-25-88 JCR General cleanup for 386-only code
  18. ; 03-23-90 GJF Changed to _stdcall. Also, fixed the copyright.
  19. ; 01-17-91 GJF ANSI naming.
  20. ; 05-10-91 GJF Back to _cdecl, sigh...
  21. ; 10-20-94 GJF Made locale sensitive (i.e., now works for all
  22. ; single-byte character locales). Made multi-thread
  23. ; safe. Also, deleted obsolete _STDCALL_ code.
  24. ; 10-27-94 GJF Adapted above change for Win32S.
  25. ; 11-12-94 GJF Must avoid volatile regs or save them across function
  26. ; calls. Also, fixed bug in reg operand size.
  27. ; 07-03-95 CFW Changed offset of _lc_handle[LC_CTYPE], added sanity check
  28. ; to crtlib.c to catch changes to win32s.h that modify offset.
  29. ; 10-03-95 GJF New locale locking scheme.
  30. ; 07-17-96 GJF Added lock prefix to increment and decrement of
  31. ; __unguarded_readlc_active.
  32. ; 07-18-96 GJF Fixed race condition.
  33. ; 09-08-98 GJF All locale and multithread support moved up to
  34. ; memicmp.c. Renamed this file to _memicmp.asm.
  35. ; 06-12-01 PML inc->add 1, dec->sub 1 for Pentium 4 perf (vs7#267015)
  36. ;
  37. ;*******************************************************************************
  38. .xlist
  39. include cruntime.inc
  40. .list
  41. page
  42. ;***
  43. ;int __ascii_memicmp(first, last, count) - compare two blocks of memory, ignore case
  44. ;
  45. ;Purpose:
  46. ; Compares count bytes of the two blocks of memory stored at first
  47. ; and last. The characters are converted to lowercase before
  48. ; comparing (not permanently), so case is ignored in the search.
  49. ;
  50. ; Algorithm:
  51. ; int
  52. ; _memicmp (first, last, count)
  53. ; char *first, *last;
  54. ; unsigned count;
  55. ; {
  56. ; if (!count)
  57. ; return(0);
  58. ; while (--count && tolower(*first) == tolower(*last))
  59. ; {
  60. ; first++;
  61. ; last++;
  62. ; }
  63. ; return(tolower(*first) - tolower(*last));
  64. ; }
  65. ;
  66. ;Entry:
  67. ; char *first, *last - memory buffers to compare
  68. ; unsigned count - maximum length to compare
  69. ;
  70. ;Exit:
  71. ; returns <0 if first < last
  72. ; returns 0 if first == last
  73. ; returns >0 if first > last
  74. ;
  75. ;Uses:
  76. ;
  77. ;Exceptions:
  78. ;
  79. ;*******************************************************************************
  80. CODESEG
  81. public __ascii_memicmp
  82. __ascii_memicmp proc \
  83. uses edi esi ebx, \
  84. first:ptr byte, \
  85. last:ptr byte, \
  86. count:IWORD
  87. mov ecx,[count] ; cx = count
  88. or ecx,ecx
  89. jz short toend ; if count=0, nothing to do
  90. mov esi,[first] ; si = first
  91. mov edi,[last] ; di = last
  92. ; C locale
  93. mov bh,'A'
  94. mov bl,'Z'
  95. mov dh,'a'-'A' ; add to cap to make lower
  96. align 4
  97. lupe:
  98. mov ah,[esi] ; ah = *first
  99. add esi,1 ; first++
  100. mov al,[edi] ; al = *last
  101. add edi,1 ; last++
  102. cmp ah,al ; test for equality BEFORE converting case
  103. je short dolupe
  104. cmp ah,bh ; ah < 'A' ??
  105. jb short skip1
  106. cmp ah,bl ; ah > 'Z' ??
  107. ja short skip1
  108. add ah,dh ; make lower case
  109. skip1:
  110. cmp al,bh ; al < 'A' ??
  111. jb short skip2
  112. cmp al,bl ; al > 'Z' ??
  113. ja short skip2
  114. add al,dh ; make lower case
  115. skip2:
  116. cmp ah,al ; *first == *last ??
  117. jne short differ ; nope, found mismatched chars
  118. dolupe:
  119. sub ecx,1
  120. jnz short lupe
  121. jmp short toend ; cx = 0, return 0
  122. differ:
  123. mov ecx,-1 ; assume last is bigger
  124. ; *** can't use "or ecx,-1" due to flags ***
  125. jb short toend ; last is, in fact, bigger (return -1)
  126. neg ecx ; first is bigger (return 1)
  127. toend:
  128. mov eax,ecx ; move return value to ax
  129. ret ; _cdecl return
  130. __ascii_memicmp endp
  131. end