Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use a loop with indirect addressing to reverse the elements of an integer array

ID: 3858154 • Letter: U

Question

Use a loop with indirect addressing to reverse the elements of an integer array in place. Do not copy the elements to any other array. Use the SIZFOF, TYPF, and LENGTHOF operators to make the program as flexible as possible if the array size and type should be changed in the future Use the XCHG instruction The array is a 32-hit variable. The array's elements are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12. The array's elements after running the program should look like: 2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11. Lastname2 asm

Explanation / Answer

TITLE Reversing an array without using oneother array INCLUDE Irvine32.inc .data array1 DWORD 10d,20d,30d,40d,50d,60d,70d,80d,90d .code main PROC mov ESI, OFFSET array1 ;ESI now points to the first item of array1 mov EDI, SIZEOF array1 add EDI, OFFSET array1 sub EDI, TYPE array1 ;EDI now points to the last item of array1 mov ECX, LENGTHOF array1 shr ECX, 1 ;now ecx is half the length of the array1 L1: mov EAX, [ESI] ;in this loop we reverse the items of the array mov EBX, [EDI] mov [EDI],EAX mov [ESI],EBX add ESI, TYPE array1 sub EDI, TYPE array1 LOOP L1 mov ECX, LENGTHOF array1;here we just print the array mov ESI, OFFSET array1 L2: MOV EAX, [ESI] call WriteInt call Crlf add ESI, TYPE array1 LOOP L2 exit main ENDP END main