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

Assembly Language Use a loop with indirect addressing to reverse the elements of

ID: 3802634 • Letter: A

Question

Assembly Language

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
num DWORD 20d,40d,60d,80d

.code
main PROC
mov ESI, OFFSET num
mov EDI, SIZEOF num ; use of SIZEOF
add EDI, OFFSET num
sub EDI, TYPE num ;use of TYPE

mov ECX, LENGTHOF num ; use of LENGTHOF
shr ECX, 1

L1: mov EAX, [ESI]
mov EBX, [EDI]
mov [EDI],EAX
mov [ESI],EBX
add ESI, TYPE num
sub EDI, TYPE num
LOOP L1

mov ECX, LENGTHOF num

mov ESI, OFFSET num
L2: MOV EAX, [ESI]
call WriteInt
call Crlf
add ESI, TYPE num
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