0

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
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
  • 1
    You can't move a memory operand to another memory operand on the x86 in one instruction. This line is a problem `add sum, gapArr[esi]` . You will have to move _gapArr[esi]_ to a temporary register, and then add that register value to _sum_ . Something like: `mov edx, gapArr[esi]` followed by `add sum, edx` . You are writing a 32 bit program on Windows, but you are including `Irvine16.inc` - that is incorrect. Maybe you mean `Irvine32.inc` – Michael Petch Nov 16 '15 at 00:49
  • Thank you Michael. I corrected those two things and the program worked correctly. – Fall3n13 Nov 16 '15 at 00:51
  • `INCLUDE Irvine16.inc`??? – rkhb Dec 21 '15 at 21:42

0 Answers0