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

Summing the Gaps between Array Values Write a program with a loop and indexed ad

ID: 3762209 • Letter: S

Question

Summing the Gaps between Array Values

Write a program with a loop and indexed addressing that calculates the sum of all the gaps between successive array elements. The array elements are doublewords, sequenced in nondecreasing order. So, for example, the array {0, 2, 5, 9, 10} has gaps of 2, 3, 4, and 1, whose sum equals 10.

This program needs to be written in x86 MASM assembly language as a 32 bit program

Use the following variables:

myArray DWORD 0,2,5,9,10

sum DWORD ?

(Use myArray[esi] AND myArray[esi+4] to solve this program)

The final value of sum should be 10 Use a loop to increment what part of the array the program is looking at and also to repeat the math required to find the final value of sum

Explanation / Answer

Description: Write a MASM 32bit program with a loop and indexed addressing that calculates the sum of all thegaps between successive array elements. The array elements are doublewords, sequenced in nondecreasing order. ;Include Irvine32.inc file used with link library for 32 bit applications .386 .model flat,stdcall .stack 4096 ExitProcess proto,dwExitCode:dword INCLUDE Irvine32.inc .data myArray DWORD 0,2,5,9,10 arrSize = ($-myArray)/TYPE myArray gapArr DWORD arrSize-1 DUP(?) sum DWORD ? .code main PROC ;Call the procedure call Clrscr ;Initialize ESI pointer mov esi, 0 mov ecx, arrSize dec ecx L1: mov eax, myArray[esi+4] sub eax, myArray[esi] mov gapArr[esi], eax inc esi loop L1 ;Calculate the sum of gaps between array elements mov sum, 0 mov esi, 0 mov ecx, arrSize dec ecx ; move gapArr[esi] to a temporary register and then add that register value to sum L2: mov edx, gapArr[esi] add sum, edx inc esi loop L2 INVOKE ExitProcess,0 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