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
  • Please use java language in an easy way and comment as much as you can! Thanks...

    Please use java language in an easy way and comment as much as you can! Thanks (Write a code question) Write a generic method called "findMin" that takes an array of Comparable objects as a parameter. (Use proper syntax, so that no type checking warnings are generated by the compiler.) The method should search the array and return the index of the smallest value.

  • Task is to implement the following algorithms in Assembly language for x86 processor

    Task is to implement the following algorithms in Assembly language for x86 processor1) Insertion sort Demonstrate Sorted Array of 10 elements in Watch Window for each one Running time of each algorithmsample bubble sort code:;----------------------------------------------------------BubbleSort PROC USES eax ecx esi,pArray:PTR DWORD, ; pointer to arrayCount:DWORD ; array size;; Sort an array of 32-bit signed integers in ascending; order, using the bubble sort algorithm.; Receives: pointer to array, array size; Returns: nothing;-----------------------------------------------------------mov ecx,Countdec ecx ; decrement count by 1L1: push ecx ; save outer...

  • How to write assembly language for x86 and where do I put the code under as? please give me answe...

    how to write assembly language for x86 and where do I put the code under as? please give me answer as soon as possible. ZOOMt COSC 2325.S01 Kxtra Credit l'rogram Problem: Starting wilh the following C+program #includes iostream > using cspace sld; cxlem'C" long Average (long, long LD; void main long Arrayl Г 101-1, 2, 3. 4, 5, 6, 7, 8. 9. 103; long Aray2 111」 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; coul <'': "Average...

  • Four Integer Stats Write an ARM Assembly Language (I will not accept Intel Assembly code) program...

    Four Integer Stats Write an ARM Assembly Language (I will not accept Intel Assembly code) program to prompt the user to enter four integers. Have your program output to the screen the four integers that were entered at the keyboard, along with the following: sum of the four integers, smallest value, largest value, and the average of the four values. You must utilize the scanf function for reading in the user input and the printf function for outputting the results...

  • I am still new to Java Language, so please comment out lines so I can understand...

    I am still new to Java Language, so please comment out lines so I can understand easily! thank you so much The RecursionP2 class will have only one class level variables: an ArrayList of Integers that will store a data set on which you will be performing different operations using recursive function. All these functions can also be done using iteration, however, you are restricted to only use recursion for full credit. Your program might be randomly checked and any...

  • I posted the question for this and I want to make sure that this answers the...

    I posted the question for this and I want to make sure that this answers the question 1.a) The pseudo code for the closest pair problem is as illustrated below: Closest pair (K, i, j) input: Array K is indexed from i to j. closest pair returns the indices of the closest pairs. diff = K[2] - K[1]   // This is the initial difference between the first two numbers. This is shown through the array and these differences. example: K[2]...

  • can you comment so that I may understand how it works. 3. Write a C++ program...

    can you comment so that I may understand how it works. 3. Write a C++ program that does the following: Write a function (smallestindex) that has two parameters: an array containing elements of type int and the length of the array. The function returns the index of the array's smallest element. ii. Use the main function to call the smallestindex function

  • IN JAVA…PLEASE comment the code thoroughly so I can understand the thought process. Write a GUI...

    IN JAVA…PLEASE comment the code thoroughly so I can understand the thought process. Write a GUI application that converts Celsius temperatures to Fahrenheit temperatures. The user should be able to enter a Celsius temperature, click a button, and then see the equivalent Fahrenheit temperature. Use the following formula to make the conversion: F = (9/5)C + 32 F is the Fahrenheit temperature and C is the Celsius temperature. Instead of only converting from Celsius to Fahrenheit, also convert from Fahrenheit...

  • simple PYTHON 3 language. please comment each line I want to understand. I know the picture...

    simple PYTHON 3 language. please comment each line I want to understand. I know the picture says java but please complete code in PYTHON. please use menu driven [E] The "back" button used in a web browser is a great example of how stacks may be used. When a user visits a new web page, the current page gets pushed onto the stack. When the user clicks the back button, the last page pushed onto the stack is popped off...

  • You want to design a digital watch using the private timer. Write the code with ARM assembly and C. Make your own decision on the language selection (Assembly and C). The followings are the codin...

    You want to design a digital watch using the private timer. Write the code with ARM assembly and C. Make your own decision on the language selection (Assembly and C). The followings are the coding requirements: Every second, the time information (hour minute second) should be sent to the UART terminal on PC The time starts from 00: 00: 00 Use some special ASCII characters to return back the cursor to the first column, when you display a new time....

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