2012-11-13 35 views
0

我正在寫一個數字操作程序,並且一步就是反轉數組。到目前爲止,我有如何在Irvine彙編語言中反轉數組?

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計數器上做錯了什麼?任何幫助,將不勝感激。

+1

不清楚你如何使用'ecx'。它在哪裏初始化?你爲什麼要添加ecx,4'然後是'loop'?從頂部再次考慮這一點。先寫評論可能會有所幫助。 –

+0

我的思考過程是,ecx從0開始,並將數組中的位置指定給數組array array final spot。在ECX循環之前,一個點和esi會向下移動一個點。但由於某種原因,它只適用於前五個地方,然後開始給我大量無關的數字 – Bill

+0

ecx可能是真的,從0開始 - 但我不會指望它! 'loop'指令減少ecx,所以你只能移動「四分之三的點」。我不知道這是你的問題還是不是... –

回答

0

使用edi代替ecx,並在開始時將其設置爲0。