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
[Link] 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)
[Link] 2/3