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

Time:10-11

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

CodePudding user response:

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
  • Related