0% found this document useful (0 votes)
359 views

Program For Summing The Gaps Between Array Values in Assembly Language Using Visual Studio PDF

The document describes a program written in assembly language that calculates the sum of the gaps between elements in an array. The program uses a loop and indexed addressing to subtract successive elements in the array and add the differences to a running total stored in the result variable. For the sample array {0, 2, 5, 9, 10}, the program calculates gaps of 2, 3, 4, 1, summing to a total of 10 stored in result. The program is implemented using Visual Studio to demonstrate summing gaps between array values in assembly language.

Uploaded by

Dilawar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
359 views

Program For Summing The Gaps Between Array Values in Assembly Language Using Visual Studio PDF

The document describes a program written in assembly language that calculates the sum of the gaps between elements in an array. The program uses a loop and indexed addressing to subtract successive elements in the array and add the differences to a running total stored in the result variable. For the sample array {0, 2, 5, 9, 10}, the program calculates gaps of 2, 3, 4, 1, summing to a total of 10 stored in result. The program is implemented using Visual Studio to demonstrate summing gaps between array values in assembly language.

Uploaded by

Dilawar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

12/9/2018 3.

Program for Summing the Gaps between Array Values in Assembly Language using Visual Studio

Programming Tutorials
SUBSCRIBE

3. Program for Summing the Gaps between


Array Values in Assembly Language using
Visual Studio
December 13, 2017

Chapter 4

Data Transfers, Addressing, and Arithmetic

Assembly Language Programming Exercise

Problem # 3:

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 non decreasing order.
So, for example, the array {0, 2, 5, 9, 10} has gaps of 2, 3, 4, and 1,
whose sum equals 10.

Solution:

.386

.model flat,stdcall
.stack 4096

ExitProcess PROTO, dwExitCode:DWORD

.data

array DWORD 0,2,5,9,10

result DWORD 0

.code

main PROC

mov ecx, LENGTHOF array

mov ESI, OFFSET array


http://csprogrammingtutorial.blogspot.com/2017/12/summing-gaps-between-array-values.html 1/3
12/9/2018 3. Program for Summing the Gaps between Array Values in Assembly Language using Visual Studio

Programming Tutorials
L1:
SUBSCRIBE
MOV EAX,[ESI]

MOV EBX,[ESI+4]

SUB EBX,EAX
ADD result,EBX

ADD ESI, TYPE array

Loop L1

INVOKE ExitProcess,0

main ENDP

END main

Let me know in the comment sec on if you have any ques on.

Previous Post:

Exchanging Pairs of Array Values


Next Post:

Copying a Word Array to a DoubleWord array

ASSEMBLY BASICS ASSEMBLY LANGUAGE FOR X86 PROCESSORS CHAPTER 4

COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE COMPUTER SCIENCE

DATA TRANSFERS ADDRESSING AND ARITHMETIC EXERCISE SOLUTION VISUAL STUDIO

Reactions: funny (0) interesting (0) cool (0)

http://csprogrammingtutorial.blogspot.com/2017/12/summing-gaps-between-array-values.html 2/3

You might also like