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     lea     eax, [esi + edx - 1]        ; eax <- End of Source
     42     cmp     esi, edi
     43     jae     .0
     44     cmp     eax, edi
     45     jae     @CopyBackward               ; Copy backward if overlapped
     46 .0:
     47     mov     ecx, edx
     48     and     edx, 3
     49     shr     ecx, 2
     50     rep     movsd                       ; Copy as many Dwords as possible
     51     jmp     @CopyBytes
     52 @CopyBackward:
     53     mov     esi, eax                    ; esi <- End of Source
     54     lea     edi, [edi + edx - 1]        ; edi <- End of Destination
     55     std
     56 @CopyBytes:
     57     mov     ecx, edx
     58     rep     movsb                       ; Copy bytes backward
     59     cld
     60     mov     eax, [esp + 12]             ; eax <- Destination as return value
     61     pop     edi
     62     pop     esi
     63     ret
     64 
     65