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.

163 lines
3.3 KiB

  1. page ,132
  2. title strcmp.asm - compare two strings
  3. ;***
  4. ;strcmp.asm - routine to compare two strings (for equal, less, or greater)
  5. ;
  6. ; Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  7. ;
  8. ;Purpose:
  9. ; STRCMP compares two strings and returns an integer
  10. ; to indicate whether the first is less than the second, the two are
  11. ; equal, or whether the first is greater than the second, respectively.
  12. ; Comparison is done byte by byte on an UNSIGNED basis, which is to
  13. ; say that Null (0) is less than any other character (1-255).
  14. ;
  15. ;Revision History:
  16. ; 04-21-87 SKS Module rewritten to be fast and small
  17. ; 05-17-88 SJM Add model-independent (large model) ifdef
  18. ; 08-04-88 SJM convert to cruntime/ add 32-bit support
  19. ; 08-23-88 JCR Minor 386 cleanup
  20. ; 10-25-88 JCR General cleanup for 386-only code
  21. ; 03-23-90 GJF Changed to _stdcall. Also, fixed the copyright.
  22. ; 05-10-91 GJF Back to _cdecl, sigh...
  23. ; 05-26-93 GJF Tuned for the 486.
  24. ; 06-14-93 GJF Testing wrong byte of ax against 0 in one case.
  25. ; 06-16-93 GJF Added .FPO directive.
  26. ; 06-12-01 PML inc->add 1, dec->sub 1 for Pentium 4 perf (vs7#267015)
  27. ;
  28. ;*******************************************************************************
  29. .xlist
  30. include cruntime.inc
  31. .list
  32. page
  33. ;***
  34. ;strcmp - compare two strings, returning less than, equal to, or greater than
  35. ;
  36. ;Purpose:
  37. ; Compares two string, determining their lexical order. Unsigned
  38. ; comparison is used.
  39. ;
  40. ; Algorithm:
  41. ; int strcmp ( src , dst )
  42. ; unsigned char *src;
  43. ; unsigned char *dst;
  44. ; {
  45. ; int ret = 0 ;
  46. ;
  47. ; while( ! (ret = *src - *dst) && *dst)
  48. ; ++src, ++dst;
  49. ;
  50. ; if ( ret < 0 )
  51. ; ret = -1 ;
  52. ; else if ( ret > 0 )
  53. ; ret = 1 ;
  54. ;
  55. ; return( ret );
  56. ; }
  57. ;
  58. ;Entry:
  59. ; const char * src - string for left-hand side of comparison
  60. ; const char * dst - string for right-hand side of comparison
  61. ;
  62. ;Exit:
  63. ; AX < 0, 0, or >0, indicating whether the first string is
  64. ; Less than, Equal to, or Greater than the second string.
  65. ;
  66. ;Uses:
  67. ; CX, DX
  68. ;
  69. ;Exceptions:
  70. ;
  71. ;*******************************************************************************
  72. CODESEG
  73. public strcmp
  74. strcmp proc
  75. .FPO ( 0, 2, 0, 0, 0, 0 )
  76. mov edx,[esp + 4] ; edx = src
  77. mov ecx,[esp + 8] ; ecx = dst
  78. test edx,3
  79. jnz short dopartial
  80. align 4
  81. dodwords:
  82. mov eax,[edx]
  83. cmp al,[ecx]
  84. jne short donene
  85. or al,al
  86. jz short doneeq
  87. cmp ah,[ecx + 1]
  88. jne short donene
  89. or ah,ah
  90. jz short doneeq
  91. shr eax,16
  92. cmp al,[ecx + 2]
  93. jne short donene
  94. or al,al
  95. jz short doneeq
  96. cmp ah,[ecx + 3]
  97. jne short donene
  98. add ecx,4
  99. add edx,4
  100. or ah,ah
  101. jnz short dodwords
  102. align 4
  103. doneeq:
  104. xor eax,eax
  105. ret
  106. align 4
  107. donene:
  108. ; The instructions below should place -1 in eax if src < dst,
  109. ; and 1 in eax if src > dst.
  110. sbb eax,eax
  111. sal eax,1
  112. add eax,1
  113. ret
  114. align 4
  115. dopartial:
  116. test edx,1
  117. jz short doword
  118. mov al,[edx]
  119. add edx,1
  120. cmp al,[ecx]
  121. jne short donene
  122. add ecx,1
  123. or al,al
  124. jz short doneeq
  125. test edx,2
  126. jz short dodwords
  127. align 4
  128. doword:
  129. mov ax,[edx]
  130. add edx,2
  131. cmp al,[ecx]
  132. jne short donene
  133. or al,al
  134. jz short doneeq
  135. cmp ah,[ecx + 1]
  136. jne short donene
  137. or ah,ah
  138. jz short doneeq
  139. add ecx,2
  140. jmp short dodwords
  141. strcmp endp
  142. end