Clear Array using indexing |
||||||||||
void ClearUsingIndex(int[], int); static int Array[10] ={1,2,3,4,5,6,7,8,9,-1}; int main() { int size = 10; ClearUsingIndex( Array, size); // or you can use this ClearUsingIndex( &Array[0], size); // call function that Clears static Array } // Clears array using indexing. void ClearUsingIndex(int Array[], int size) { int i; for (i = 0; i < size; i +=1) Array[i] = 0; } |
||||||||||
Before Calling Clear Array | ||||||||||
Clear Array Using Pointers |
||||||||||
#define SIZE 10 /* number of integers in an Array */ void ClearUsingPointers(int *, int); static int Array[10] ={1,2,3,4,5,6,7,8,9,-1}; int main() {
ClearUsingPointers( &Array[0], SIZE); // call function that Clears static Array } // Clears array using pointers. void ClearUsingPointers(int *Array, int size) { int *p; for (p = &Array[0]; p < &Array[size]; p = p+1) *p= 0; }; |
||||||||||
After two iteration s inFunction that uses pointers | ||||||||||
Clear Array Function in ASM as generatedBy MS Compiler from C-code (using indexing); Copyright (C) 2000 Microsoft Corporation. All rights reserved. .386 .model flat, c ; Custom Build Step, including a listing file placed in intermediate directory ; but without Source Browser information ; debug: ; ml -c -Zi "-Fl$(IntDir)\$(InputName).lst" "-Fo$(IntDir)\$(InputName).obj" "$(InputPath)" ; release: ; ml -c "-Fl$(IntDir)\$(InputName).lst" "-Fo$(IntDir)\$(InputName).obj" "$(InputPath)" ; outputs: ; $(IntDir)\$(InputName).obj ; Custom Build Step, including a listing file placed in intermediate directory ; and Source Browser information also placed in intermediate directory ; debug: ; ml -c -Zi "-Fl$(IntDir)\$(InputName).lst" "-FR$(IntDir)\$(InputName).sbr" "-Fo$(IntDir)\$(InputName).obj" "$(InputPath)" ; release: ; ml -c "-Fl$(IntDir)\$(InputName).lst" "-FR$(IntDir)\$(InputName).sbr" "-Fo$(IntDir)\$(InputName).obj" "$(InputPath)" ; outputs: ; $(IntDir)\$(InputName).obj ; $(IntDir)\$(InputName).sbr .code ; Clear array using index as compiler generated. ; ; x:SDWORD - signed double word ( 4 bytes) _TEXT SEGMENT _i$ = -8 _Array$ = 8 _size$ = 12 ClearUsingIndex PROC NEAR ; ClearUsingIndex, COMDAT ; Line 14 00000 55 push ebp 00001 8b ec mov ebp, esp 00003 81 ec cc 00 00 00 sub esp, 204 ; 000000ccH 00009 53 push ebx 0000a 56 push esi 0000b 57 push edi 0000c 8d bd 34 ff ff ff lea edi, DWORD PTR [ebp-204] 00012 b9 33 00 00 00 mov ecx, 51 ; 00000033H 00017 b8 cc cc cc cc mov eax, -858993460 ; ccccccccH 0001c f3 ab rep stosd ; Line 16 0001e c7 45 f8 00 00 00 00 mov DWORD PTR _i$[ebp], 0 00025 eb 09 jmp SHORT $L281 $L282: 00027 8b 45 f8 mov eax, DWORD PTR _i$[ebp] 0002a 83 c0 01 add eax, 1 0002d 89 45 f8 mov DWORD PTR _i$[ebp], eax $L281: 00030 8b 45 f8 mov eax, DWORD PTR _i$[ebp] 00033 3b 45 0c cmp eax, DWORD PTR _size$[ebp] 00036 7d 0f jge SHORT $L279 ; Line 17 00038 8b 45 f8 mov eax, DWORD PTR _i$[ebp] 0003b 8b 4d 08 mov ecx, DWORD PTR _Array$[ebp] 0003e c7 04 81 00 00 00 00 mov DWORD PTR [ecx+eax*4], 0 00045 eb e0 jmp SHORT $L282 $L279: ; Line 18 00047 5f pop edi 00048 5e pop esi 00049 5b pop ebx 0004a 8b e5 mov esp, ebp 0004c 5d pop ebp 0004d c3 ret 0 ClearUsingIndex ENDP ; ClearUsingIndex _TEXT ENDS END end |
||||||||||
Clear Array using Pointers asgenerated By MS Compiler.386
|
||||||||||