Separated math and memory functions into their own files to limit the amount of objec...
[reactos.git] / reactos / lib / rtl / i386 / zeromemory_asm.s
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: zeromemory_asm.S
5 * PURPOSE: Memory functions
6 * PROGRAMMERS: Patrick Baggett (baggett.patrick@gmail.com)
7 * Alex Ionescu (alex@relsoft.net)
8 * Magnus Olsen (magnusolsen@greatlord.com)
9 */
10
11 .intel_syntax noprefix
12
13 /* GLOBALS ****************************************************************/
14
15 .globl _RtlZeroMemory@8 // (no bug) (max optimze code)
16
17 /* FUNCTIONS ***************************************************************/
18
19 _RtlZeroMemory@8:
20 mov ecx,dword [esp + 8 ] // Length
21 cmp ecx,0// if (Length==0) goto .zero
22 je 3f
23
24 pushad // Save all register on the stack
25 mov edi, dword [esp + (4 + 32)] // Destination
26 xor eax,eax // ZeroFillByte = 0
27
28 // code for take four byte each time it loop
29 mov ebx,ecx // temp_Length = Length
30 shr ecx,2// Length = Length / sizeof(ULONG)
31 jz 1f // if (Length==0) goto .1byte
32
33 shl ecx,2// Length = Length * sizeof(ULONG)
34 sub ebx,ecx // temp_Length = temp_Length - Length//
35 jz 2f // if (temp_Length==0) goto .4byte
36
37 // move 4byte and 1byte
38 shr ecx,2// Length = Length / sizeof(ULONG)
39 cld // clear d flag
40 rep stosd// while (Length!=0) { (ULONG *) Destination[Length-1]=ZeroFillByte// Legnth = Legnth - 1 }
41 mov ecx,ebx // Length = temp_Length
42 rep stosb// while (Length!=0) { (UCHAR *) Destination[Length-1]=ZeroFillByte// Legnth = Legnth - 1 }
43 popad // restore register
44 ret 8 // return
45
46 // move 1byte
47 1:
48 mov ecx,dword [esp + (12 +32) ] // Length
49 cld // clear d flag
50 rep stosb// while (Length!=0) { (UCHAR *) Destination[Length-1]=ZeroFillByte// Legnth = Legnth - 1 }
51 popad // restore register
52 ret 8 // return
53
54 // move 4bytes
55 2:
56 shr ecx,2// Length = Length / sizeof(ULONG)
57 cld // clear d flag
58 rep stosd// while (Length!=0) { (ULONG *) Destination[Length-1]=ZeroFillByte// Legnth = Legnth - 1 }
59 popad // restore register
60 3:
61 ret 8 // return