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

Need help in assembly. Show results. Thank you Use a loop with indirect addressi

ID: 3803772 • Letter: N

Question

Need help in assembly. Show results. Thank you 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.

Explanation / Answer

TITLE Reverse an array
INCLUDE Irvine32.inc

.data
    array2 DWORD 1d,2d,3d,4d,5d,6d,7d,8d,9d,10d,11d,12d
.code
main PROC
        mov ESI, OFFSET array2 ;ESI now points to the first item of array1
        mov EDI, SIZEOF array2
        add EDI, OFFSET array2
        sub EDI, TYPE array2   ;EDI now points to the last item of array2

        mov ECX, LENGTHOF array2
        shr ECX, 1          ;now ecx is half the length of the array2
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 array2
        sub EDI, TYPE array2
        LOOP L1

        mov ECX, LENGTHOF array2;here we just print the array
        mov ESI, OFFSET array2
L2:     MOV EAX, [ESI]
        call WriteInt
        call Crlf
        add ESI, TYPE array2
        LOOP L2
        exit       
main ENDP
END main

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote