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

  1. / memswap.s (emx+gcc) -- Copyright (c) 1992-1993 by Eberhard Mattes
  2.  
  3.         .globl __memswap
  4.  
  5. / void _memswap (void *s1, void *s2, size_t n)
  6. / {
  7. /   char *c1, *c2, c;
  8. /   int *i1, *i2, i;
  9. /   i1 = s1; i2 = s2;
  10. /   while (n >= sizeof (int))
  11. /     {
  12. /       i = *i1; *i1++ = *i2; *i2++ = i;
  13. /       n -= sizeof (int);
  14. /       }
  15. /   c1 = (char *)i1; c2 = (char *)i2;
  16. /   while (n >= 1)
  17. /     {
  18. /       c = *c1; *c1++ = *c2; *c2++ = c;
  19. /       --n;
  20. /     }
  21. / }
  22.  
  23. / assumes ds=es!
  24.  
  25.         .text
  26.  
  27.         .align  2, 0x90
  28.  
  29. __memswap:
  30.         pushl   %esi
  31.         pushl   %edi
  32.         movl    3*4(%esp), %edi         / s1
  33.         movl    4*4(%esp), %esi         / s2
  34.         movl    5*4(%esp), %ecx         / n
  35.         shrl    $2, %ecx
  36.         jz      2f
  37.         .align  2, 0x90
  38. 1:      movl    (%edi), %eax
  39.         xchgl   (%esi), %eax
  40.         stosl
  41.         addl    $4, %esi
  42.         loop    1b
  43. 2:      movl    5*4(%esp), %ecx         / n
  44.         andl    $3, %ecx
  45.         jz      4f
  46.         .align  2, 0x90
  47. 3:      movb    (%edi), %al
  48.         xchgb   (%esi), %al
  49.         stosb
  50.         incl    %esi
  51.         loop    3b
  52. 4:      popl    %edi
  53.         popl    %esi
  54.         ret
  55.