Home | History | Annotate | Download | only in Ia32
      1 ;------------------------------------------------------------------------------
      2 ;
      3 ; Copyright (c) 2006, 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 ;   CopyMem function
     19 ;
     20 ; Notes:
     21 ;
     22 ;------------------------------------------------------------------------------
     23 
     24     SECTION .text
     25 
     26 ;------------------------------------------------------------------------------
     27 ;  VOID *
     28 ;  InternalMemCopyMem (
     29 ;    IN VOID   *Destination,
     30 ;    IN VOID   *Source,
     31 ;    IN UINTN  Count
     32 ;    )
     33 ;------------------------------------------------------------------------------
     34 global ASM_PFX(InternalMemCopyMem)
     35 ASM_PFX(InternalMemCopyMem):
     36     push    esi
     37     push    edi
     38     mov     esi, [esp+16]                ; esi <- Source
     39     mov     edi, [esp+12]                ; edi <- Destination
     40     mov     edx, [esp+20]                ; edx <- Count
     41     cmp     esi, edi
     42     je      @CopyDone
     43     cmp     edx, 0
     44     je      @CopyDone
     45     lea     eax, [esi + edx - 1]         ; eax <- End of Source
     46     cmp     esi, edi
     47     jae     @CopyBytes
     48     cmp     eax, edi
     49     jb      @CopyBytes                   ; Copy backward if overlapped
     50     mov     esi, eax                     ; esi <- End of Source
     51     lea     edi, [edi + edx - 1]         ; edi <- End of Destination
     52     std
     53 @CopyBytes:
     54     mov     ecx, edx
     55     rep     movsb                        ; Copy bytes backward
     56     cld
     57 @CopyDone:
     58     mov     eax, [esp + 12]             ; eax <- Destination as return value
     59     pop     edi
     60     pop     esi
     61     ret
     62 
     63