Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FILE 1 clearIndexOp.asm:
- .686P
- .model flat, c
- .code
- _TEXT SEGMENT
- _i$ = -8 ; size = 4
- _A$ = 8 ; size = 4
- _size$ = 12 ; size = 4
- clearIndexOp PROC NEAR
- ; {
- push ebp
- mov ebp, esp
- sub esp, 204 ; 000000ccH
- push ebx
- push esi
- push edi
- lea edi, DWORD PTR [ebp-204]
- mov ecx, 51 ; 00000033H
- mov eax, -858993460 ; ccccccccH
- rep stosd
- ; for(int i=0; i<size; i++)
- ; initialize the variables
- mov eax, 0 ; init i=0 to eax
- mov ebx, DWORD PTR _size$[ebp] ; size stored in ebx for faster access than memory
- mov ecx, DWORD PTR _A$[ebp] ; get base addr of array
- jmp SHORT $LN3@clearIndex ; jump into the loop
- $LN2@clearIndex:
- add eax, 1 ; increase eax since eax=i
- $LN3@clearIndex:
- cmp eax, ebx ; check that i < size
- jge SHORT $LN4@clearIndex ; exits if i >= size
- ; A[i]=0;
- mov DWORD PTR [ecx+eax*4], 0 ; A[i]=0
- jmp SHORT $LN2@clearIndex ; go back to loop body
- ; after removing useless/repetitive codes
- ; we shrunk this code from 10 instructions to only 5 instructions
- $LN4@clearIndex:
- ; }
- pop edi
- pop esi
- pop ebx
- mov esp, ebp
- pop ebp
- ret 0
- clearIndexOp ENDP
- _TEXT ENDS
- END
- FILE 2 clearPointerOp:
- .686P
- .model flat, c
- .code
- _TEXT SEGMENT
- _p$ = -8 ; size = 4
- _A$ = 8 ; size = 4
- _size$ = 12 ; size = 4
- clearPointerOp PROC NEAR
- ; {
- push ebp
- mov ebp, esp
- sub esp, 204 ; 000000ccH
- push ebx
- push esi
- push edi
- lea edi, DWORD PTR [ebp-204]
- mov ecx, 51 ; 00000033H
- mov eax, -858993460 ; ccccccccH
- rep stosd
- ; int *p;
- ; for(p=&A[0]; p<&A[size]; p
- ; initialize the variables
- mov eax, DWORD PTR _A$[ebp] ; base addr of the array
- mov DWORD PTR _p$[ebp], eax ; init p = A[0]
- mov ebx, DWORD PTR _p$[ebp] ; move p to ebx
- mov ecx, DWORD PTR _size$[ebp] ; size stored in ecx for faster access from register
- lea edx, DWORD PTR [ecx+eax*4] ; last index of array, A[size-1]
- jmp SHORT $LN3@clearPoint ; jump into loop
- $LN2@clearPoint:
- add eax, 4 ; since it is pointer we increase eax by 4 to move to next element
- $LN3@clearPoint:
- cmp ebx, edx ; check that p < size
- jae SHORT $LN4@clearPoint ; exit if p >= size
- ; *p=0;
- mov DWORD PTR [ebx], 0
- jmp SHORT $LN2@clearPoint
- ; after removing useless/repetitive codes
- ; we shrunk this code from 11 instructions to only 5 instructions
- $LN4@clearPoint:
- ; }
- pop edi
- pop esi
- pop ebx
- mov esp, ebp
- pop ebp
- ret 0
- clearPointerOp ENDP
- _TEXT ENDS
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement