update for HEAD-2003091401
[reactos.git] / lib / ntdll / nasm / rtl / i386_RtlZeroMemory.asm
1 ; * 
2 ; * COPYRIGHT:       See COPYING in the top level directory
3 ; * PROJECT:         ReactOS kernel
4 ; * FILE:            i386_RtlZeroMemory.asm
5 ; * PURPOSE:         Memory functions
6 ; * PROGRAMMER:      Magnus Olsen (magnusolsen@greatlord.com)
7 ; * UPDATE HISTORY:
8 ; *                  Created 20/07-2003
9 ; * 
10
11
12           BITS 32
13         GLOBAL _RtlZeroMemory@8         ; (no bug) (max optimze code)       
14           SECTION .text
15
16 ; * 
17 ; * [1] VOID STDCALL RtlZeroMemory (PVOID Destination, ULONG Length); 
18 ; * 
19                    
20 _RtlZeroMemory@8:           
21          
22         mov ecx,dword [esp + 8 ]               ; Length                                             
23         cmp ecx,0                              ; if (Length==0) goto .zero  
24           je  .zero             
25
26         pushad                                 ; Save all register on the stack      
27         mov edi, dword [esp + (4 + 32)]        ; Destination           
28         xor eax,eax                            ; ZeroFillByte = 0
29         
30        
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 .1byte                                ; 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 .4bytes                               ; 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 .1byte:   
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 .4bytes:
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 .zero:
65        ret 8                                  ; return