我在MASM中访问数组时遇到了一些困难。我有一个非常大的数组和一个像这样的临时变量:
.data
array DWORD 65000 DUP (0)
temp DWORD 0
在我的主要内容中,我有这个填补它:
mov esi, offset array
mov edi, 0
mov ecx, 0
fill:
mov [esi], ecx
add esi, 4
inc ecx
cmp ecx, 65000
jl fill
mov esi, offset array ;reset the array location to the start
之后,我想用这个循环访问数组:
mark:
mov temp, 4 ;get another 4 to temp to move along the array
add esi, temp ;add temp to esi to keep moving
mov edx, [esi] ;access the current value
cmp esi, 20 ;just trying to get first few elements
jmp mark
exit
main ENDP
END main
我总是遇到访问冲突错误,在我尝试访问当前值的行中断。这也发生在第一个循环上。知道为什么会这样吗?谢谢!
答案 0 :(得分:0)
但是,您的代码将在某种程度上发挥作用:
mark:
mov temp, 4
add esi, temp ;Incrementing before first loop means you miss the first stored value
mov edx, [esi]
cmp esi, 20 ;ESI is the address your are accessing, not a count
jmp mark ;This loop will be infinite