home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3518 / memmove.s next >
Text File  |  1991-06-19  |  687b  |  53 lines

  1. / $Id: memmove.s,v 1.3 1991/06/05 19:15:44 chip Exp $
  2. /
  3. / Implementation of memmove(), which is inexplicably missing
  4. / from the SCO Unix C library.
  5. /
  6.  
  7.     .globl    memmove
  8. memmove:
  9. ifdef(`PROFILE',`
  10.     .bss
  11. .L1:    .=.+4
  12.     .text
  13.     mov    $.L1,%edx
  14.     .globl    _mcount
  15.     call    _mcount
  16. ')
  17.     push    %edi
  18.     push    %esi
  19.     mov    12(%esp),%edi
  20.     mov    16(%esp),%esi
  21.     mov    20(%esp),%ecx
  22.     mov    %edi,%eax        / return value: dest
  23.     jcxz    mm_exit
  24.  
  25.     mov    %edi,%edx
  26.     sub    %esi,%edx
  27.     jb    mm_simple
  28.     cmp    %edx,%ecx
  29.     jb    mm_simple
  30.  
  31.     add    %ecx,%edi
  32.     dec    %edi
  33.     add    %ecx,%esi
  34.     dec    %esi
  35.     std
  36.     rep; movsb
  37.     cld
  38.     jmp    mm_exit
  39.  
  40. mm_simple:
  41.     cld
  42.     mov    %ecx,%edx
  43.     shr    $2,%ecx
  44.     rep; movs
  45.     mov    %edx,%ecx
  46.     and    $3,%ecx
  47.     rep; movsb
  48.  
  49. mm_exit:
  50.     pop    %esi
  51.     pop    %edi
  52.     ret
  53.