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

Write an assembly language program to copy the contents of one array to another

ID: 3573186 • Letter: W

Question

Write an assembly language program to copy the contents of one array to another array. Below are some declarations to help you get started. Use indirect addressing to reference the elements of the arrays. ARY1 is delimited by the HEX value 0000. Continue copying values from ARY1 to ARY2 until you reach a value of 0000. Count the number of elements in ARY1 as you copy them and store the result. (No, you shouldn't just assign the count operand CTR a value of 5. Its value should be computed as your program executes.) Your program should work for any size array. (12 pt)

PTR1, HEX 'ARY1 /Pointer to ARY1

PTR2, HEX 'ARY2 /Pointer to ARY2

CTR, HEX 0000 /Number of elements copied from ARY1 to ARY2

ARY1, HEX 0015

HEX 0003

HEX 002C

HEX 0008

HEX 000E

HEX 0000

ARY2, HEX 0000

END COPY

Explanation / Answer

section.text
global _start

_start:
   mov eax,PTR2       ;EAX will store the sum
   mov ebx,PTR1       ;EBX will point to the current element
  
sum1:
   add eax,[ebx]       ; add
   add ebx,1       ; move pointer to next element
   inc CTR           ; increment counter
   cmp eax,0       ; compare with zero
   jnz sum1       ; loop if not equal to zero
done:
   add eax,'0'
   move [sum],ebx

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