开发者

How do I reverse an array in place in assembly?

I am supposed to reverse an array in place. I have been working on it for a while and this is what I have. Can anyone tell me w开发者_Python百科hat I'm doing wrong?

.data
array BYTE 10h, 20h, 30h, 40h

.code
main PROC
    mov esi, 0
    mov edi, 0
    mov esi, OFFSET array
    mov edi, OFFSET array + SIZEOF array
    mov ecx, SIZEOF array/2

l1: mov al, [esi]
    mov bl, [edi]
    mov [edi], al
    mov [esi], bl
    inc esi
    dec edi
    LOOP l1

    call DumpRegs
    call DumpMem

    exit

main ENDP

END main


Try to declare two arrays, one intilized with your values and the other one could be like this using DUP operator 5 DUP (?)

And start moving values from first array to the second using a loop.

Example:

.data myArr1 DWORD 5, 4, 3, 2, 1 myArr2 DWORD 5 DUP (?)

.code main proc mov edi, offset myArr1 add edi, sizeof myArr1 mov esi, offset myArr2 mov ecx, lengthof myArr2

reverseLoop: add ebx, [edi] mov[edi], ebx sub edi, type myArr2 add esi, type myArr1 mov eax, [edi] call writeint

LOOP reverseLoop

exit main endp end main

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜