home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 1.ddi / CLIBSRC1.ZIP / MEMCMP.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  1.9 KB  |  74 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - memcmp.cas
  3.  *
  4.  * function(s)
  5.  *        memcmp - compare two memory arrays
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #pragma inline
  18. #include <asmrules.h>
  19. #include <mem.h>
  20.  
  21. /*-----------------------------------------------------------------------*
  22.  
  23. Name            memcmp - compare two memory arrays
  24.  
  25. Usage           int memcmp(const void *s1, const void *s2, size_t n);
  26.  
  27. Prototype in    mem.h & string.h
  28.  
  29. Description     memcmp compares two  memory areas, s1 and s2,  for a length
  30.                 of  exactly  n  bytes.  This  function  compares  bytes  as
  31.                 unsigned chars, so
  32.                         memcmp ("\0xFF", "\0x7F", 1)
  33.                 returns a positive value.
  34.  
  35. Return value    < 0     if s1 is less than s2
  36.                 = 0     if s1 is the same as s2
  37.                 > 0     if s1 is greater than s2
  38.  
  39. *------------------------------------------------------------------------*/
  40. #undef memcmp                  /* not an intrinsic */
  41.  
  42. #if defined(__FARFUNCS__)
  43. #include <_farfunc.h>
  44. #endif
  45.  
  46. int _FARFUNC memcmp(const void *s1, const void *s2, size_t n)
  47. {
  48.         pushDS_
  49. asm     mov     ax, n
  50. asm     mov     cx, ax
  51. asm     jcxz    mcm_end
  52. asm     LDS_    si, s1
  53. asm     LES_    di, s2
  54. #if !(LDATA)
  55. asm     mov     ax, ds
  56. asm     mov     es, ax
  57. #endif
  58. asm     cld
  59. asm     rep     cmpsb
  60.  
  61. /*      The result is the UNsigned difference of the final character pair,
  62.         be they equal or different.
  63. */
  64. asm     mov     al, [si-1]
  65. asm     xor     ah, ah
  66. asm     mov     cl, ES_ [di-1]
  67. asm     xor     ch, ch
  68.  
  69. mcm_end:
  70.         popDS_
  71.  
  72.         return( _AX - _CX );
  73. }
  74.