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

Please use Intel x86 Use a loop with indirect addressing to reverse the elements

ID: 3803473 • Letter: P

Question

Please use Intel x86

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 SIZEOF, TYPE, 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-bit 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. Submit the following: Lastname2.asm

Explanation / Answer

Ans .

%TITLE "First Program -- Lastname2.ASM"
.8086
.MODEL small
.STACK 256
.DATA
arrayBYTE dword 1,2,3,4,5,6,7,8,9,10

.CODE
MAIN PROC
   mov esi ,0
   mov edi, 0
   mov ebx 1   ;exchange has take place as an indicator
   mov esi,OFFSET array+SIZEOF array-1
   mov edi, OFFSET array + SIZEOF array - 1
   mov ecx, SIZEOF array

L1:
   mov eax,array[esi*type array] ;get number
   dec esi ;inc pointer
   xchg [esi],eax ;exchange with above
   dec esi
   mov edi ,type array
   loop L1


call dumpregs