Question

In: Computer Science

Write a procedure to reverse an array. Assume staring address has been passed in ESI, the...

Write a procedure to reverse an array. Assume staring address has been passed in ESI, the number of units in ECX, the unit size in EBX

Solutions

Expert Solution

first lets initialize with zero and then move first (starting) element address to esi and with similar procedur last element address to edi and then number of units in ecx (I am representing it in small letters.I hope you would be adjusted ).

Once look at the code and if you require something more please mention in comment,will be glad to help you.

mov esi, 0
mov edi, 0
mov eax, 0
mov ebx, 0

mov esi, OFFSET array ;move first element address to esi
mov edi, OFFSET array ;move last element address to edi

mov ecx, LENGTHOF array ;sets the counter in the reverseLoop

reverseLoop:
mov eax, [esi] ;move the element in esi to eax
mov ebx, [edi]   ;move the element in edi to ebx
add esi, TYPE array ;increase esi to take the next element in the array (from the left)
sub edi, TYPE array ;decrease edi to take the next element in the array (from the right)
call writehex
call crlf
loop reverseLoop


Related Solutions

Write a procedure to calculate Average of numbers(integers) using Arrays. Send base address of array in...
Write a procedure to calculate Average of numbers(integers) using Arrays. Send base address of array in register $a1 and Array length in register $a2 to the procedure and return Average in register $v0 to main program.
ASSIGNMENT: Write a program to reverse an array and then find the average of array elements....
ASSIGNMENT: Write a program to reverse an array and then find the average of array elements. Start by creating 2 arrays that can each hold 10 integer values. Then, get values from the user and populate the 1st array. Next, populate the 2nd array with the values from the 1st array in reverse order. Then, average the corresponding elements in the 1st and 2nd arrays to populate a 3rd array (average the 1st element of the 1st array with the...
Assume an MxN array has been filled, write a function to calculate the sum of each...
Assume an MxN array has been filled, write a function to calculate the sum of each column which should be stored into a third 1D array of size N. code in C++
write a program in C Write a function that is passed an array of characters containing...
write a program in C Write a function that is passed an array of characters containing letter grades of A, B, C, D, and F, and returns the total number of occurrences of each letter grade. Your function should accept both lower and upper case grades, for example, both 'b' and 'B' should be bucketed into your running total for B grades. Any grade that is invalid should be bucketed as a grade of 'I' for Incomplete. You must use...
C++ 9.10: Reverse Array Write a function that accepts an int array and the array’s size...
C++ 9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in a main program that reads an integer N (that is not more than 50) from standard input and then reads N integers from a file...
Write a method which is passed A[], which is an array of int, and an int...
Write a method which is passed A[], which is an array of int, and an int passingScore. The method returns the number of items in A[] which are greater than or equal to passingScore. Write a method which is passed an array of int A[]. The method returns true if A[] is the same backwards and forwards. Write a method same( ), which is passed two arrays of int. The method returns true if the two arrays contain exactly the...
Write a function void reverse(char * s) that reverses the string passed as an argument. Your...
Write a function void reverse(char * s) that reverses the string passed as an argument. Your code should use pointer arithmetic (it may increment and decrement pointers, but it may not use array indexing). Here is a piece of code that shows the behavior of reverse: char buf[100]; strcpy(buf, “hello”); reverse(buf); printf(“%s\n”, buf); // output should be olleh
Q1. Write an algorithm to do the following operation on an array passed as parameter: If...
Q1. Write an algorithm to do the following operation on an array passed as parameter: If an element of the array is having more than one occurrence, then keep the first occurrence and remove all other occurrences of the element.
In Java: Write a method called copy, which is passed A[], which is an array of...
In Java: Write a method called copy, which is passed A[], which is an array of int, and an integer n. The method returns a new array consisting of the first n items in A[]. Write a method called slice, which is passed A[], which is an array of int, an integer i and an integer j. The method returns a new array consisting of all of the items in A from A[i] to A[j] inclusive.
Assume that a highly controversial and publicly polarizing bill has been passed by the US House...
Assume that a highly controversial and publicly polarizing bill has been passed by the US House of Representatives and is currently up for vote in the US Senate. If the bill passes through the Senate, outline and describe the process by which the bill will become law, or not become law. If the bill becomes law, will it remain law forever? Identify the three branches of government and describe how the separation of powers created by the three different branches...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT