如何在汇编中就地反转数组?
我应该就地反转数组。我已经为此工作了一段时间,这就是我所拥有的。谁能告诉我我做错了什么?
.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
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 what 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试声明两个数组,一个数组包含您的值,另一个数组可能像这样使用 DUP 运算符 5 DUP (?)
并开始使用循环将值从第一个数组移动到第二个数组。
示例:
.data
myArr1 双字 5, 4, 3, 2, 1
myArr2 DWORD 5 DUP (?)
.code 主过程
mov edi,偏移 myArr1
添加 edi, myArr1 的大小
mov esi,偏移 myArr2
mov ecx, myArr2
反向循环的长度:
添加 ebx, [edi] mov[edi], ebx
子 edi,输入 myArr2
添加esi,输入myArr1
mov eax,[编辑]
调用 writeint
LOOP reverseLoop
退出
主要终点
结束主要
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