Question
This is Assembly Language...please i want you to give proper documentation or comment of every code you write, so i can understand your code. Thank you!
** 2. Exchanging Pairs of Array Values Write a program with a loop and indexed addressing that exchanges every pair of values
0 0
Add a comment Improve this question Transcribed image text
Answer #1

.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
.data
array dword 1,2,3,4,5,6,7,8 #array of elements
.code
main proc
mov esi, OFFSET array #move the all index values to the esi register
mov ecx, LENGTHOF array -1 #move the lenght of the array to the ecx register

myLoop: #loop start

MOV eax,[esi] #move the index of array value to the eax
XCHG eax,[esi+4]   #exchanging the two value pairs by adding bytes 4 then the address will be change
MOV [esi],eax #swap the value pairs

add esi, TYPE array #first swapped value add to the array
add esi, TYPE array # second swapped value add to the array

loop myLoop # iterate loop

invoke ExitProcess,0 # exit process
main endp
end main #end of the program

another method simply understands:

dwarray dword 0,2,5,9,10,12
.code
main proc
mov ebx, OFFSET dwarray
mov ecx, 3                    # THE ARRAY CONTAINS 6 ELEMENTS, BUT THEY ARE PROCESSED
                                   IN PAIRS, SO THE LOOP SHOULD REPEAT HALF 6 (3).
L1: ;cmp ebx, ecx            #UNNECESSARY?
mov eax, [ebx]
mov edx, [ebx+4]              #THE NEXT ELEMENT IS 4 BYTES AWAY.
mov [ebx+4], eax              #AGAIN, THE NEXT ELEMENT IS 4 BYTES.
mov [ebx], edx
add ebx, 8                    #INCREASE BY 8 (THE SIZE OF 2 ELEMENTS PROCESSED).
loop L1

Add a comment
Know the answer?
Add Answer to:
This is Assembly Language...please i want you to give proper documentation or comment of every code...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT