This commit was manufactured by cvs2svn to create branch 'captive'.
[reactos.git] / lib / ntdll / nasm / rtl / i386_RtlMoveMemory.asm
1 ; * base on ntdll/rtl/mem.c v 1.13 2003/07/11 13:50:23 
2 ; * 
3 ; * COPYRIGHT:       See COPYING in the top level directory
4 ; * PROJECT:         ReactOS kernel
5 ; * FILE:            i386_RtlMemory.asm
6 ; * PURPOSE:         Memory functions
7 ; * PROGRAMMER:      Magnus Olsen (magnusolsen@greatlord.com)
8 ; * UPDATE HISTORY:
9 ; *                  Created 20/07-2003
10 ; * 
11   
12
13           BITS 32
14         GLOBAL _RtlMoveMemory@12   ; (no bug) (max optimze code) 
15             
16           SECTION .text
17
18 ; * 
19 ; * [1] VOID STDCALL RtlMoveMemory (PVOID Destination, CONST VOID *Source,ULONG Length);
20 ; * 
21
22
23
24 _RtlMoveMemory@12:
25       mov ecx,dword [esp + 12 ]              ; ecx = Length                                       
26         cmp ecx,0                              ; if (Length==0) goto .zero
27         je  .zero               
28       
29       pushad
30       mov edi, dword [esp + (4 + 32)]        ; eax = Destination                       
31       mov esi, dword [esp + (8 + 32)]        ; edx = Source                                     
32
33 ; calc how many bytes it should handle same time
34       mov ebx,ecx                            ; temp_Length = Length                  
35       shr ecx,2                              ; Length = Length / sizeof(ULONG)      
36       jz .1byte                              ; if (Length==0) goto .1byte
37        
38       shl ecx,2                              ; Length = Length * sizeof(ULONG)      
39       sub ebx,ecx                            ; temp_Length = temp_Length - Length
40       jz .4bytes                             ; if (temp_Length==0) goto .4byte
41
42 ; move 4byte and 1byte
43       shr ecx,2                              ; Length = Length  / sizeof(ULONG)        
44       cld                                    ; clear d flag
45       rep movsd                              ; while (Length!=0) { (ULONG *) Destination[Length-1] = (ULONG *) Source[Length-1]; Legnth = Legnth - 1 }
46       mov ecx,ebx                            ; Length = temp_Length  
47       rep movsb                              ; while (Length!=0) { (UCHAR *) Destination[Length-1] = (UCHAR *) Source[Length-1]; Legnth = Legnth - 1 }
48       popad                                  ; restore regiester
49       ret 12                                 ; return  
50       
51 ; move 1byte            
52 .1byte:   
53        mov ecx,dword [esp + (12 +32) ]       ; ecx = Length                                               
54        cld                                   ; clear d flag
55        rep movsb                             ; while (Length!=0) { (UCHAR *) Destination[Length-1] = (UCHAR *) Source[Length-1]; Legnth = Legnth - 1 }
56
57        popad                                 ; restore regiester
58        ret 12                                ; return
59
60 ; move 4bytes     
61 .4bytes:
62        shr ecx,2                             ; Length = Length  / sizeof(ULONG)         
63        cld                                   ; clear d flag
64        rep movsd                             ; while (Length!=0) { (ULONG *) Destination[Length-1] = (ULONG *) Source[Length-1]; Legnth = Legnth - 1 }
65        popad                                 ; restore regiester
66 .zero:                  
67        ret 12                                ; return
68
69