我正在尝试编写一个反转数组的简单程序。它几乎可以工作,无论如何它适用于阵列的前半部分。中间的术语始终为“0”,然后返回到模式。例如,如果我输入:1,2,3,4,5,6,7,8,9,10,输出将是10,9,8,7,6,0,6,5,4,3 。该计划的顺序基本上是这样的:
致电ReverseArray:
ReverseArray PROC,
len:DWORD, s:DWORD, increment:DWORD,address:DWORD
mov edx, OFFSET revArray
call WriteString
mov edi, address
mov esi, address
add esi, s
sub esi, TYPE array
mov ecx, len
shr ecx, 1
L2:
mSwap32 edi, esi
add edi, increment
sub esi, increment
loop L2
ret
ReverseArray endp
ReverseArray过程(遍历数组并调用mSwap32):
mSwap32 MACRO address1:REQ, address2:REQ
mov edi, address1
mov esi, address2
mov eax, [esi]
push eax
mov eax, [edi]
mov [esi], eax
pop eax
mov [edi], eax
ENDM
mSwap32宏(给两个地址交换):
$('#LoginShow').click(function(e){
$('.Black-Background-A').fadeIn(1000, 'swing');
$("#Login").animate({marginTop:'25px'}).fadeIn(500, 'swing');
});
$('.Black-Background-A').click(function(){
$('.Black-Background-A').fadeOut(1000, 'swing');
$("#Login").animate({marginTop:'+=50px'}).fadeOut(500, 'swing');
});
我很确定错误是在mSwap32中...我确定这是一个小错误的逻辑错误,但无论我玩多少玩具,我都无法理解。 ??
答案 0 :(得分:1)
这是一个WORD数组
通过这一重要信息,我们可以解决问题。 LENGTHOF将为10(如前所述),SIZEOF现在为20,TYPE现为2。
ReverseArray PROC,
len:DWORD, s:DWORD, increment:DWORD,address:DWORD
mov edx, OFFSET revArray
call WriteString
mov edi, address
mov esi, address
add esi, s
sub esi, increment ;Better not refer to the actual array here!
mov ecx, len
shr ecx, 1
L2:
mSwap32 edi, esi
add edi, increment
sub esi, increment
loop L2
ret
ReverseArray endp
和宏:
mSwap32 MACRO address1:REQ, address2:REQ
mov edi, address1
mov esi, address2
mov ax, [esi]
push eax
mov ax, [edi]
mov [esi], ax
pop eax
mov [edi], ax
ENDM
更短并且仍在使用宏:
mSwap32 MACRO address1:REQ, address2:REQ
mov edi, address1
mov esi, address2
mov ax, [esi]
xchg ax, [edi]
mov [esi], ax
ENDM