In: Computer Science
Write a procedure to reverse an array. Assume staring address has been passed in ESI, the number of units in ECX, the unit size in EBX
first lets initialize with zero and then move first (starting) element address to esi and with similar procedur last element address to edi and then number of units in ecx (I am representing it in small letters.I hope you would be adjusted ).
Once look at the code and if you require something more please mention in comment,will be glad to help you.
mov esi, 0
mov edi, 0
mov eax, 0
mov ebx, 0
mov esi, OFFSET array ;move first element address to esi
mov edi, OFFSET array ;move last element address to edi
mov ecx, LENGTHOF array ;sets the counter in the reverseLoop
reverseLoop:
mov eax, [esi] ;move the element in esi to eax
mov ebx, [edi] ;move the element in edi to ebx
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)
call writehex
call crlf
loop reverseLoop