- Update to trunk
[reactos.git] / lib / sdk / crt / mem / i386 / memmove_asm.s
1 /*
2 * void *memcpy (void *to, const void *from, size_t count)
3 *
4 */
5
6 #include <asm.inc>
7 #include <ks386.inc>
8
9 PUBLIC _memcpy
10 PUBLIC _memmove
11 .code
12
13 _memcpy:
14 _memmove:
15 push ebp
16 mov ebp, esp
17
18 push esi
19 push edi
20
21 mov edi, [ebp + 8]
22 mov esi, [ebp + 12]
23 mov ecx, [ebp + 16]
24
25 cmp edi, esi
26 jbe .CopyUp
27 mov eax, ecx
28 add eax, esi
29 cmp edi, eax
30 jb .CopyDown
31
32 .CopyUp:
33 cld
34
35 cmp ecx, 16
36 jb .L1
37 mov edx, ecx
38 test edi, 3
39 je .L2
40 /*
41 * Make the destination dword aligned
42 */
43 mov ecx, edi
44 and ecx, 3
45 sub ecx, 5
46 not ecx
47 sub edx, ecx
48 rep movsb
49 mov ecx, edx
50 .L2:
51 shr ecx, 2
52 rep movsd
53 mov ecx, edx
54 and ecx, 3
55 .L1:
56 test ecx, ecx
57 je .L3
58 rep movsb
59 .L3:
60 mov eax, [ebp + 8]
61 pop edi
62 pop esi
63 leave
64 ret
65
66 .CopyDown:
67 std
68
69 add edi, ecx
70 add esi, ecx
71
72 cmp ecx, 16
73 jb .L4
74 mov edx, ecx
75 test edi, 3
76 je .L5
77
78 /*
79 * Make the destination dword aligned
80 */
81 mov ecx, edi
82 and ecx, 3
83 sub edx, ecx
84 dec esi
85 dec edi
86 rep movsb
87 mov ecx, edx
88
89 sub esi, 3
90 sub edi, 3
91 .L6:
92 shr ecx, 2
93 rep movsd
94 mov ecx, edx
95 and ecx, 3
96 je .L7
97 add esi, 3
98 add edi, 3
99 .L8:
100 rep movsb
101 .L7:
102 cld
103 mov eax, [ebp + 8]
104 pop edi
105 pop esi
106 leave
107 ret
108 .L5:
109 sub edi, 4
110 sub esi, 4
111 jmp .L6
112
113 .L4:
114 test ecx, ecx
115 je .L7
116 dec esi
117 dec edi
118 jmp .L8
119
120 END