Home | History | Annotate | Download | only in Ia32
      1 ;------------------------------------------------------------------------------
      2 ;
      3 ; Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
      4 ; This program and the accompanying materials
      5 ; are licensed and made available under the terms and conditions of the BSD License
      6 ; which accompanies this distribution.  The full text of the license may be found at
      7 ; http://opensource.org/licenses/bsd-license.php
      8 ;
      9 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     10 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     11 ;
     12 ; Module Name:
     13 ;
     14 ;   CopyMem.asm
     15 ;
     16 ; Abstract:
     17 ;
     18 ;   memcpy function
     19 ;
     20 ; Notes:
     21 ;
     22 ;------------------------------------------------------------------------------
     23 
     24     .686
     25     .model  flat,C
     26     .mmx
     27     .code
     28 
     29 ;------------------------------------------------------------------------------
     30 ;  VOID *
     31 ;  memcpy (
     32 ;    IN VOID   *Destination,
     33 ;    IN VOID   *Source,
     34 ;    IN UINTN  Count
     35 ;    );
     36 ;------------------------------------------------------------------------------
     37 memcpy  PROC    USES    esi edi
     38     mov     esi, [esp + 16]             ; esi <- Source
     39     mov     edi, [esp + 12]             ; edi <- Destination
     40     mov     edx, [esp + 20]             ; edx <- Count
     41     lea     eax, [esi + edx - 1]        ; eax <- End of Source
     42     cmp     esi, edi
     43     je      @CopyMemDone
     44     cmp     edx, 0
     45     je      @CopyMemDone
     46     cmp     esi, edi
     47     jae     @F
     48     cmp     eax, edi                    ; Overlapped?
     49     jae     @CopyBackward               ; Copy backward if overlapped
     50 @@:
     51     mov     ecx, edx
     52     and     edx, 7
     53     shr     ecx, 3                      ; ecx <- # of Qwords to copy
     54     jz      @CopyBytes
     55     push    eax
     56     push    eax
     57     movq    [esp], mm0                  ; save mm0
     58 @@:
     59     movq    mm0, [esi]
     60     movq    [edi], mm0
     61     add     esi, 8
     62     add     edi, 8
     63     loop    @B
     64     movq    mm0, [esp]                  ; restore mm0
     65     pop     ecx                         ; stack cleanup
     66     pop     ecx                         ; stack cleanup
     67     jmp     @CopyBytes
     68 @CopyBackward:
     69     mov     esi, eax                    ; esi <- Last byte in Source
     70     lea     edi, [edi + edx - 1]        ; edi <- Last byte in Destination
     71     std
     72 @CopyBytes:
     73     mov     ecx, edx
     74     rep     movsb
     75     cld
     76 @CopyMemDone:    
     77     mov     eax, [esp + 12]
     78     ret
     79 memcpy  ENDP
     80 
     81     END
     82