• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    .code
27
28;------------------------------------------------------------------------------
29;  VOID *
30;  memcpy (
31;    IN VOID   *Destination,
32;    IN VOID   *Source,
33;    IN UINTN  Count
34;    );
35;------------------------------------------------------------------------------
36memcpy  PROC    USES    esi edi
37    mov     esi, [esp + 16]             ; esi <- Source
38    mov     edi, [esp + 12]             ; edi <- Destination
39    mov     edx, [esp + 20]             ; edx <- Count
40    cmp     esi, edi
41    je      @CopyDone
42    cmp     edx, 0
43    je      @CopyDone
44    lea     eax, [esi + edx - 1]         ; eax <- End of Source
45    cmp     esi, edi
46    jae     @F
47    cmp     eax, edi
48    jb      @F                           ; Copy backward if overlapped
49    mov     esi, eax                     ; esi <- End of Source
50    lea     edi, [edi + edx - 1]         ; edi <- End of Destination
51    std
52@@:
53    mov     ecx, edx
54    rep     movsb                        ; Copy bytes backward
55    cld
56@CopyDone:
57    mov     eax, [esp + 12]
58    ret
59memcpy  ENDP
60
61    END
62