0
.data
j SDWORD ?
k SDWORD ?
array1 SDWORD 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 
19, 20
sum SDWORD ?


.code
_main PROC
mov j, 3 ; Setting J into the Array
mov k, 6 ; Setting K into the Array
mov edx, 2 ; Setting the index number for the starting position (J)

sumArray1:
mov eax, [array1+edx*4]
cmp eax, k 
jg array2
add sum, eax
inc edx
jmp SumArray1

array2:
INVOKE ExitProcess, 0
_main ENDP
END

&sum is at a value of 12 when the program terms, meaning that for some reason it is not adding the value of K before jumping out of the loop. Any idea why?

2
  • 1
    Sorry, I forgot the value are in hex xD Commented Apr 3, 2018 at 5:20
  • If you want to sum up array[2] to array[6], you need to compare edx (which is i), not eax (which is (array[i]) ) Commented Apr 3, 2018 at 12:58

1 Answer 1

0

There are no issues with your code that I can see. Here is what I'm seeing after stepping over your loop:

no issues here

Have you stepped through your code line by line to see what might be happening?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.