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

Please provide the assembly code for the following x86 MASM (not NASM) program.

ID: 3600385 • Letter: P

Question

Please provide the assembly code for the following x86 MASM (not NASM) program. The program should be executable in Visual Studio (.asm)

*Use ONLY the XCHG function to rearrange the array elements

Thank you

2. (5 points) Use a loop instruction with indirect addressing to reverse the elements of an 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. The array's elements are: B, A, D, C, F. E, H, G o Submit the following: - Use the XCHG instruction. - The array's elements after running the program should look like: A, B, C, D, E. F, G, H. Lastname2.asm

Explanation / Answer

Code:-

INCLUDE Irvine32.inc

.data

arr DWORD B,A,D,C,F,E,H,G ; Array of integers with 8 elements
len DWORD LENGTHOF arr ; The length of the array

.code
main PROC

mov esi,OFFSET arr
mov ecx, LENGTHOF arr/2

reverseArrayOf32bit:
lea edi,[esi+4] ;edi = address of next entry
  
.next:
mov eax,0
cmp ecx,eax
je .done ; yes, it's done aleady

mov eax,[esi] ;eax = value at start
xchg ebx,[edi] ;ebx = value at end
mov [esi],eax ;Store value from start at end

add esi,8 ;esi = address of next item at start
add edi,8   
dec ecx
j .next

.done:
main ENDP

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