First of all, you can simplify your code
reverseLoop:
mov eax, [esi] ;move the element in esi to eax
mov ebx, [edi] ;move the element in edi to ebx
xchg eax, ebx ;exchange the two elements
mov [esi], eax ;move the element in eax, to the address in esi
mov [edi], ebx ;move the element in ebx, to the address in edi
add esi, TYPE array ;increase esi to take the next element in the array (from the left)
sub edi, TYPE array ;decrease edi to take the next element in the array (from the right)
loop reverseLoop
by
reverseLoop:
mov eax, [esi] ;move the element in esi to eax
mov ebx, [edi] ;move the element in edi to ebx
xchg eax, ebx ;exchange the two elements
mov [esi], ebx ;move the element in ebx, to the address in esi
mov [edi], eax ;move the element in eax, to the address in edi
add esi, TYPE array ;increase esi to take the next element in the array (from the left)
sub edi, TYPE array ;decrease edi to take the next element in the array (from the right)
loop reverseLoop
Second, why don't you use byte sized registers to move bytes ?
Like
AL
or
AH
and
BL
or
BH
?
I know, it is old fashioned, but it look the most straight forward to me.
[Update]
To handle all possibilities as fast as possible, you need some code like:
if (TYPE is DWORD)
optimized code for DWORD (mostly your sample code)
else if (TYPE is WORD)
optimized code for WORD
else if (TYPE is BYTE)
optimized code for BYTE
end if
To handle all possibilities with a single piece of code, you must operate at smallest possible data size. It is possible but will be slow.
array DWORD 1,2,3,4,5,6,7,8,9,10,11,12
will give
array DWORD 9,10,11,12,5,6,7,8,1,2,3,4
array WORD 1,2,3,4,5,6,7,8,9,10,11,12
will give
array WORD 11,12,9,10,7,8,5,6,3,4,1,2
array BYTE 1,2,3,4,5,6,7,8,9,10,11,12
will give
array BYTE 12,11,10,9,8,7,6,5,4,3,2,1
in your main loop, you need another loop to handle the different data sizes.
reverseLoop:
for dx=1 to (TYPE array)
mov ah, [esi] ;move the element in esi to ah
mov bh, [edi] ;move the element in edi to bh
mov [esi], bh ;move the element in bh, to the address in esi
mov [edi], ah ;move the element in ah, to the address in edi
add esi, 1
add esi, 1
next
sub edi, TYPE array
sub edi, TYPE array ;decrease edi to take the next element in the array (from the right)
loop reverseLoop
Pseudo code, I let you deal with details