61a29124ed300f6174535676928f04504a0996c1
[reactos.git] / reactos / lib / rtl / i386 / mem_asm.S
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: mem.asm
5 * PURPOSE: Memory functions
6 * PROGRAMMER: Magnus Olsen (magnusolsen@greatlord.com)
7 * UPDATE HISTORY:
8 * Created 27/07/2005
9 */
10
11 .intel_syntax noprefix
12
13 /* GLOBALS ****************************************************************/
14
15 .globl _RtlZeroMemory@8 // (no bug) (max optimze code)
16 .globl _RtlFillMemoryUlong@12 // (no bug) (max optimze code)
17 .globl _RtlFillMemory@12 // [4] (no bug)
18 .globl _RtlCompareMemoryUlong@12 // [5] (no bug)
19 .globl _RtlCompareMemory@12 // [4] (no bug)
20
21 /* FUNCTIONS ***************************************************************/
22
23 _RtlZeroMemory@8:
24 mov ecx,dword [esp + 8 ] // Length
25 cmp ecx,0// if (Length==0) goto .zero
26 je 3f
27
28 pushad // Save all register on the stack
29 mov edi, dword [esp + (4 + 32)] // Destination
30 xor eax,eax // ZeroFillByte = 0
31
32 // code for take four byte each time it loop
33 mov ebx,ecx // temp_Length = Length
34 shr ecx,2// Length = Length / sizeof(ULONG)
35 jz 1f // if (Length==0) goto .1byte
36
37 shl ecx,2// Length = Length * sizeof(ULONG)
38 sub ebx,ecx // temp_Length = temp_Length - Length//
39 jz 2f // if (temp_Length==0) goto .4byte
40
41 // move 4byte and 1byte
42 shr ecx,2// Length = Length / sizeof(ULONG)
43 cld // clear d flag
44 rep stosd// while (Length!=0) { (ULONG *) Destination[Length-1]=ZeroFillByte// Legnth = Legnth - 1 }
45 mov ecx,ebx // Length = temp_Length
46 rep stosb// while (Length!=0) { (UCHAR *) Destination[Length-1]=ZeroFillByte// Legnth = Legnth - 1 }
47 popad // restore register
48 ret 8 // return
49
50 // move 1byte
51 1:
52 mov ecx,dword [esp + (12 +32) ] // Length
53 cld // clear d flag
54 rep stosb// while (Length!=0) { (UCHAR *) Destination[Length-1]=ZeroFillByte// Legnth = Legnth - 1 }
55 popad // restore register
56 ret 8 // return
57
58 // move 4bytes
59 2:
60 shr ecx,2// Length = Length / sizeof(ULONG)
61 cld // clear d flag
62 rep stosd// while (Length!=0) { (ULONG *) Destination[Length-1]=ZeroFillByte// Legnth = Legnth - 1 }
63 popad // restore register
64 3:
65 ret 8 // return
66
67 _RtlFillMemoryUlong@12:
68 mov ecx, dword [esp + 8 ] // Length
69 shr ecx,2// Length = Length / sizeof(ULONG)
70 jz 1f // if (Length==0) goto .zero
71
72 push edi
73 mov edi, dword [esp + (4 + 4)] // Destination
74 mov eax, dword [esp + (12 + 4)] // Fill
75 cld
76 rep stosd// while (Length>0) {Destination[Length-1]=Fill// Length = Length - 1}
77 pop edi
78 1:
79 ret 12
80
81 _RtlFillMemory@12:
82 mov ecx,dword [esp + 8 ] // ecx = Length
83 cmp ecx,0// if (Length==0) goto .zero
84 je 2f
85
86 mov edx, dword [esp + 4] // edx = Destination
87 mov eax, dword [esp + 12] // eax = fill
88 1:
89 mov byte [edx + ecx -1],al // src[Length - 1] = fill
90 dec ecx // Length = Length - 1
91 jnz 1b // if (Length!=0) goto .loop
92 2:
93 ret 12 // return
94
95 _RtlCompareMemoryUlong@12:
96 xor eax,eax
97 mov ecx, dword [esp + 8 ] // ecx = Length
98 shr ecx,2 // Length / sizeof(ULONG)
99 jz 1f // if (Length==0) goto .zero
100
101 push edi// register that does not to be save eax,ecx,edx to
102 push ebx// the stack for protetion
103
104 mov edi, dword [esp + (4 + 8)] // edx = Destination
105 mov eax, dword [esp + (12 + 8)] // ebx = value
106 mov ebx,ecx
107 cld
108 repe scasd
109
110 inc ecx
111 mov eax,ebx
112
113 sub eax,ecx
114 shl eax,2
115
116 pop ebx
117 pop edi
118
119 1:
120 ret 12
121
122 _RtlCompareMemory@12:
123 xor eax,eax // count = 0
124 mov ecx, dword [esp + 12 ] // ecx = Length
125 cmp ecx,0 // if (Length==0) goto .zero
126 je 3f
127
128 push edi// register that does not to be save eax,ecx,edx to
129 push ebx// the stack for protetion
130
131 mov edi, dword [esp + (4 + 8)] // edi = Destination
132 mov edx, dword [esp + (8 + 8)] // edx = Source
133
134 1:
135 mov bl,byte [edi + eax ] // if (src[count]!=des[count]) goto .pop_zero
136 cmp byte [edx + eax ],bl
137 jne 2f
138
139 inc eax // count = count + 1
140 dec ecx // Length = Length - 1
141 jnz 1b // if (Length!=0) goto .loop_1byte
142
143 2:
144 pop ebx // restore regiester
145 pop edi
146 3:
147 ret 12 // return count