Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. TITLE Value Swap
  2.  
  3. ; This program adds and subtracts 32-bit integers
  4. ; and stores the sum in a variable.
  5.  
  6. INCLUDE Irvine32.inc
  7.  
  8. .data
  9. array DWORD 2,4,6,8
  10. halfsize DWORD ? ; Half the size of our array, will be calculated later
  11.  
  12. .code
  13. main PROC
  14.  
  15. MOV edi, OFFSET array ; Address of array
  16. MOV ecx, LENGTHOF array / 2 ; Loop counter -- Swapping 2 values takes 1/2 the size of the array (0.5 * n) iterations.
  17.  
  18.  
  19. L1:
  20. MOV ebx, [edi] ; Grab element, put it into a register
  21.  
  22. XCHG ebx, [edi+4] ; Exchange ebx element with next element in the array
  23.  
  24. mov [edi], ebx ; Move ebx back into the array
  25. ADD edi, 8 ; Move to the next pair -- we need to increment twice here. Adding 8 because that = 8 bytes = 2 DWORDS
  26.  
  27.  
  28. loop L1 ; Loop
  29.  
  30. exit
  31. main ENDP
  32. END main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement