I'm currently stuck on this MASM program I had to write for a homework assignment. I am currently getting MASM32 error A2070: invalid instruction operands on this line:
add sum, gapArr[esi]
What is causing this error, and how can I fix it?
In the comments of the code it states what the program should do. My code is:
; Chapter 4, Exercise 3: Summing the Gaps between Array Values
Comment !
Description: 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.
!
.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
INCLUDE Irvine16.inc
.data
arr1 DWORD 11, 12, 30, 40, 55, 61, 70, 84
arrSize = ($-arr1)/TYPE arr1
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, arr1[esi+1]
sub eax, arr1[esi]
mov gapArr[esi], eax
inc esi
loop L1
;Calculate the sum of gaps
mov sum, 0
mov esi, 0
mov ecx, arrSize
dec ecx
L2:
add sum, gapArr[esi]
inc esi
loop L2
INVOKE ExitProcess,0
main ENDP
END main