Search code examples
arraysassemblyx86cpu-registers

Array is printed as 0's in Intel 32-bit assembly


I made a program and initialized an array like var WORD 50 DUP(?).
When I tried a loop and printed the value of var, it printed zeroes.

.data
var WORD 50 DUP(?)
.code
main PROC
mov ecx,10
top:
movzx eax,var
call writeint
loop top

Solution

  • As @vitsoft said, the value of var is printed each time, as nothing changes between iterations.

    What you want to do is load the address of var to EBX, dereference and increment it by 2 at each iteration.

    .data
        var WORD 50 DUP(?)
    .code
        main PROC
            lea   ebx, var
            mov   ecx,10
        top:
            movzx eax, WORD PTR [ebx]
            add   ebx, 2
            call  writeint
            dec   ecx
            jnz   top