221k views
3 votes
Summing Three Arrays Write an assembly language subroutine that receives the offsets of three arrays, all of equal size. It adds the second and third arrays to the values in the first array. When it returns, the first array has all new values. Write a test program in C/C++ that creates an array, passes it to the subroutine, and prints the contents of the first array.

User Roslyn
by
5.4k points

1 Answer

4 votes

Answer:

SumThreeArrays PROC USES eax ebx esi,

array1:PTR DWORD, array2:PTR DWORD,

array3:PTR DWORD, arraySize:DWORD

LOCAL sz:BYTE ; local sz for jump

mov sz, 4 ; size of each iteration jump

mov ecx, arraySize ; set ecx to size of arrays for loop

L1:

mov eax, arraySize ; move array size into eax

sub eax, ecx ; subtract whats left

mul sz ; multiply by 4 to know how much to jump

mov esi, array1 ; set esi to start of array 1

mov ebx, [esi+eax] ; move value of esi+jump into ebx

mov esi, array2 ; set esi to start of array 2

add ebx, [esi+eax] ; add value of esi+jump to ebx

mov esi, array3 ; set esi to start of array 3

add ebx, [esi+eax] ; add value of esi+jump to ebx

mov esi, array1 ; set esi to start of array 1

mov [esi+eax], ebx ; move value of ebx into esi+jump

LOOP L1

ret

SumThreeArrays ENDP

END

Step-by-step explanation:

The subroutine "SumThreeArrays" from the assembly language gets from memory three defined arrays from a C++ source code and extend the size of the first array with the values of the second and the third arrays.

User Mohammad Zare
by
5.3k points