]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseMemoryLibRepStr/Ia32/CopyMem.nasm
MdePkg BaseMemoryLibRepStr: Convert Ia32/CopyMem.asm to NASM
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibRepStr / Ia32 / CopyMem.nasm
CommitLineData
170f7936
JJ
1;------------------------------------------------------------------------------\r
2;\r
3; Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
4; This program and the accompanying materials\r
5; are licensed and made available under the terms and conditions of the BSD License\r
6; which accompanies this distribution. The full text of the license may be found at\r
7; http://opensource.org/licenses/bsd-license.php.\r
8;\r
9; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11;\r
12; Module Name:\r
13;\r
14; CopyMem.Asm\r
15;\r
16; Abstract:\r
17;\r
18; CopyMem function\r
19;\r
20; Notes:\r
21;\r
22;------------------------------------------------------------------------------\r
23\r
24 SECTION .text\r
25\r
26;------------------------------------------------------------------------------\r
27; VOID *\r
28; InternalMemCopyMem (\r
29; IN VOID *Destination,\r
30; IN VOID *Source,\r
31; IN UINTN Count\r
32; )\r
33;------------------------------------------------------------------------------\r
34global ASM_PFX(InternalMemCopyMem)\r
35ASM_PFX(InternalMemCopyMem):\r
36 push esi\r
37 push edi\r
38 mov esi, [esp + 16] ; esi <- Source\r
39 mov edi, [esp + 12] ; edi <- Destination\r
40 mov edx, [esp + 20] ; edx <- Count\r
41 lea eax, [esi + edx - 1] ; eax <- End of Source\r
42 cmp esi, edi\r
43 jae .0\r
44 cmp eax, edi\r
45 jae @CopyBackward ; Copy backward if overlapped\r
46.0:\r
47 mov ecx, edx\r
48 and edx, 3\r
49 shr ecx, 2\r
50 rep movsd ; Copy as many Dwords as possible\r
51 jmp @CopyBytes\r
52@CopyBackward:\r
53 mov esi, eax ; esi <- End of Source\r
54 lea edi, [edi + edx - 1] ; edi <- End of Destination\r
55 std\r
56@CopyBytes:\r
57 mov ecx, edx\r
58 rep movsb ; Copy bytes backward\r
59 cld\r
60 mov eax, [esp + 12] ; eax <- Destination as return value\r
61 pop edi\r
62 pop esi\r
63 ret\r
64\r