【发布时间】:2012-11-13 19:14:56
【问题描述】:
我正在编写一个数字操作程序,其中一个步骤是反转数组。到目前为止我有
reverseArray proc
mov eax, arraySize
mov temp, eax
Imul eax, 4
mov esi, eax
mov eax, 0
mov number, 0
jne L1
L1:
cmp temp, 0
je L3
mov eax, numbers[esi]
mov tempnumbers[ecx], eax
mov eax, tempnumbers[ecx]
call writeDec
call crlf
sub esi,4
add ecx, 4
sub temp, 1
loop L1
L2:
ret
L3:
.If(number >= 0)
mov esi, 0
.ENDIF
mov eax, number
cmp eax, arraySize
je L2
mov eax, tempnumbers[esi]
mov numbers[esi], eax
add esi, 4
add number, 1
loop L3
但是,这只反转了我的数组的大约一半。我对 esi 或 ecx 计数器做错了吗?任何帮助将不胜感激。
【问题讨论】:
-
不清楚你是如何使用
ecx的。它在哪里初始化?为什么你先add ecx, 4然后loop?从上到下再想一想。首先编写 cmets 可能会有所帮助。 -
我的想法是 ecx 从 0 开始,并将临时数组中的位置分配给 numbers 数组的最终位置。就在循环之前,ecx 将向前移动一位,而 esi 将向下移动一位。但由于某种原因,它只适用于前五个位置,然后开始给我大量不相关的数字
-
ecx 从 0 开始可能是真的 - 但我不会指望它!
loop指令会减少 ecx,因此您只会移动“四分之三点”。不知道是不是你的问题……
标签: arrays loops assembly masm irvine32