Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TITLE Value Swap
- ; This program adds and subtracts 32-bit integers
- ; and stores the sum in a variable.
- INCLUDE Irvine32.inc
- .data
- array DWORD 2,4,6,8
- halfsize DWORD ? ; Half the size of our array, will be calculated later
- .code
- main PROC
- MOV edi, OFFSET array ; Address of array
- MOV ecx, LENGTHOF array / 2 ; Loop counter -- Swapping 2 values takes 1/2 the size of the array (0.5 * n) iterations.
- L1:
- MOV ebx, [edi] ; Grab element, put it into a register
- XCHG ebx, [edi+4] ; Exchange ebx element with next element in the array
- mov [edi], ebx ; Move ebx back into the array
- ADD edi, 8 ; Move to the next pair -- we need to increment twice here. Adding 8 because that = 8 bytes = 2 DWORDS
- loop L1 ; Loop
- exit
- main ENDP
- END main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement