Advertisement
Guest User

Untitled

a guest
Nov 17th, 2011
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. FILE 1 clearIndexOp.asm:
  2.  
  3. .686P
  4. .model flat, c
  5. .code
  6.  
  7. _TEXT SEGMENT
  8. _i$ = -8                                ; size = 4
  9. _A$ = 8                                    ; size = 4
  10. _size$ = 12                                ; size = 4
  11.  
  12. clearIndexOp PROC NEAR
  13. ; {
  14.     push    ebp
  15.     mov    ebp, esp
  16.     sub    esp, 204                        ; 000000ccH
  17.     push    ebx
  18.     push    esi
  19.     push    edi
  20.     lea    edi, DWORD PTR [ebp-204]
  21.     mov    ecx, 51                            ; 00000033H
  22.     mov    eax, -858993460                    ; ccccccccH
  23.     rep stosd
  24.  
  25. ; for(int i=0; i<size; i++)
  26. ; initialize the variables
  27.     mov eax, 0                            ; init i=0 to eax
  28.     mov ebx, DWORD PTR _size$[ebp]         ; size stored in ebx for faster access than memory
  29.     mov    ecx, DWORD PTR _A$[ebp]               ; get base addr of array
  30.     jmp    SHORT $LN3@clearIndex            ; jump into the loop
  31. $LN2@clearIndex:
  32.     add    eax, 1                            ; increase eax since eax=i
  33. $LN3@clearIndex:
  34.     cmp    eax, ebx                        ; check that i < size
  35.     jge    SHORT $LN4@clearIndex            ; exits if i >= size
  36.  
  37. ; A[i]=0;
  38.     mov    DWORD PTR [ecx+eax*4], 0        ; A[i]=0
  39.     jmp    SHORT $LN2@clearIndex            ; go back to loop body
  40.  
  41. ; after removing useless/repetitive codes
  42. ; we shrunk this code from 10 instructions to only 5 instructions
  43.    
  44. $LN4@clearIndex:
  45.  
  46. ; }
  47.     pop    edi
  48.     pop    esi
  49.     pop    ebx
  50.     mov    esp, ebp
  51.     pop    ebp
  52.     ret    0
  53. clearIndexOp ENDP                
  54. _TEXT ENDS
  55. END
  56.  
  57. FILE 2 clearPointerOp:
  58.  
  59. .686P
  60. .model flat, c
  61. .code
  62.  
  63. _TEXT SEGMENT
  64. _p$ = -8                                    ; size = 4
  65. _A$ = 8                                     ; size = 4
  66. _size$ = 12                                 ; size = 4
  67.  
  68. clearPointerOp PROC NEAR
  69. ; {
  70.     push ebp
  71.     mov ebp, esp
  72.     sub esp, 204                            ; 000000ccH
  73.     push ebx
  74.     push esi
  75.     push edi
  76.     lea edi, DWORD PTR [ebp-204]
  77.     mov ecx, 51                             ; 00000033H
  78.     mov eax, -858993460                     ; ccccccccH
  79.     rep stosd
  80.  
  81. ; int *p;
  82. ; for(p=&A[0]; p<&A[size]; p
  83. ; initialize the variables
  84.     mov eax, DWORD PTR _A$[ebp]             ; base addr of the array
  85.     mov DWORD PTR _p$[ebp], eax             ; init p = A[0]
  86.     mov ebx, DWORD PTR _p$[ebp]             ; move p to ebx
  87.     mov ecx, DWORD PTR _size$[ebp]          ; size stored in ecx for faster access from register
  88.     lea edx, DWORD PTR [ecx+eax*4]          ; last index of array, A[size-1]
  89.     jmp SHORT $LN3@clearPoint               ; jump into loop
  90. $LN2@clearPoint:
  91.     add eax, 4                              ; since it is pointer we increase eax by 4 to move to next element
  92. $LN3@clearPoint:
  93.     cmp ebx, edx                            ; check that p < size
  94.     jae SHORT $LN4@clearPoint               ; exit if p >= size
  95.  
  96. ; *p=0;
  97.     mov DWORD PTR [ebx], 0
  98.     jmp SHORT $LN2@clearPoint
  99.    
  100. ; after removing useless/repetitive codes
  101. ; we shrunk this code from 11 instructions to only 5 instructions
  102.  
  103. $LN4@clearPoint:
  104.  
  105. ; }
  106.     pop edi
  107.     pop esi
  108.     pop ebx
  109.     mov esp, ebp
  110.     pop ebp
  111.     ret 0
  112. clearPointerOp ENDP        
  113. _TEXT ENDS
  114. END
  115.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement