Search code examples
assemblymasmirvine32

Adding elements of DWORD array


I am working on an assignment to add elements of a DWORD array and print them on the screen. For some reason it is outputting the wrong number. Am I missing something?

TITLE Assignment 2



INCLUDE Irvine32.inc
.data
array1  DWORD   10h,20h,30h,40h,11h,12h,16h,14h,18h,22h,96h,44h,89h,17h,94h,27h,16h,82h, 33h
N = ($ - array1)/4
.STACK 4096
ExitProcess PROTO, dwExitCode:DWORD 
DumpRegs PROTO
.code
   main PROC
    mov esi, OFFSET array1
    mov ecx, N
    mov eax, array1
    loop_start:
    add eax,[esi]
    add esi,1
    dec ecx
    jnz loop_start
    call DumpRegs
    INVOKE ExitProcess, 0   

main ENDP
END main

Solution

  • Look at how big your datasize is DWORD and how much you increase your index register.

    add esi, 4

    Using sizeof can help in such cases.