home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / MEMCMP.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  2.2 KB  |  70 lines

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