home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / EMXLIB8F.ZIP / EMX / LIB / STR / MEMMOVE.S < prev    next >
Encoding:
Text File  |  1993-01-02  |  1.4 KB  |  63 lines

  1. / memmove.s (emx+gcc) -- Copyright (c) 1990-1993 by Eberhard Mattes
  2.  
  3.         .globl _memmove
  4.  
  5. / void *memmove (void *s1, const void *s2, size_t n)
  6. / {
  7. /   size_t i;
  8. /   
  9. /   if ((size_t)s1 < (size_t)s2)
  10. /     for (i = 0; i < n; ++i)
  11. /       ((char *)s1)[i] = ((char *)s2)[i];
  12. /   else
  13. /     for (i = n; i > 0; --i)                          /* i is unsigned! */
  14. /       ((char *)s1)[i-1] = ((char *)s2)[i-1];
  15. /   return (s1);
  16. / }
  17.  
  18. / assumes ds=es!
  19.  
  20.         .text
  21.  
  22.         .align  2, 0x90
  23.  
  24. _memmove:
  25.         pushl   %esi
  26.         pushl   %edi
  27.         movl    3*4(%esp), %edi         / s1
  28.         movl    4*4(%esp), %esi         / s2
  29.         movl    5*4(%esp), %ecx         / n
  30.         jecxz   9f
  31.         cmpl    %edi, %esi
  32.         jb      2f
  33.         shrl    $2, %ecx
  34.         rep
  35.         movsl
  36.         movl    5*4(%esp), %ecx         / n
  37.         andl    $3, %ecx
  38.         rep
  39.         movsb
  40.         jmp     9f
  41.  
  42.         .align  2, 0x90
  43.  
  44. 2:      addl    %ecx, %esi
  45.         addl    %ecx, %edi
  46.         subl    $4, %esi
  47.         subl    $4, %edi
  48.         std
  49.         shrl    $2, %ecx
  50.         rep
  51.         movsl
  52.         addl    $3, %esi
  53.         addl    $3, %edi
  54.         movl    5*4(%esp), %ecx         / n
  55.         andl    $3, %ecx
  56.         rep
  57.         movsb
  58.         cld
  59. 9:      movl    3*4(%esp), %eax         / s1
  60.         popl    %edi
  61.         popl    %esi
  62.         ret
  63.