Home > OS >  array is printed 0 in assembly intel 32 bit
array is printed 0 in assembly intel 32 bit

Time:10-10

I made a program and initialized array like var WORD 50 DUP(?) when i try a loop and printed the value of var it printed zeros

.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
loop top
  • Related