gpt4 book ai didi

arrays - 更改 edi 的偏移量与更改地址处的值?

转载 作者:行者123 更新时间:2023-12-02 09:58:37 25 4
gpt4 key购买 nike

所以,这可能是一个有点具体的问题,但我的 ASM 任务是创建一个 10 元素数组,将第一个元素添加到最后一个元素,并将结果放入数组的第一个元素,然后是第二个元素元素与第 9 个元素并将结果放入数组的第二个元素中,依此类推。

a0 + a9 ---> a0a1 + a8 ---> a1 等

同样的过程应该从第 10 个元素中减去第一个元素,并将结果放入第 10 个元素中。第 9 个元素减去第 2 个元素,并将结果放入第 9 个元素,以此类推。如下所示:

例如,如果输入 1,2,3,4,5,6,7,8,9,0,则程序输出应为 1, 11, 11, 11, 11, 1, 3 , 5, 7, -1。

我在这里完全不知所措,我不知道如何在 edi 中的 OFFSET 周围来回移动以及更改该地址处的值?

 INCLUDE c:\Irvine\Irvine32.inc

ExitProcess proto,dwExitCode:dword

.data ;// write your data in this section
intarray DWORD ?,?,?,?,?,?,?,?,?,?
msg2 BYTE "The processed array:", 0
endl BYTE 0dh, 0ah, 0
count DWORD 0
x DWORD 0
y DWORD 0


.code
main proc
mov eax, 0 ; zeros out the eax register
mov ecx, LENGTHOF intarray
mov edi, OFFSET intarray;
mov edx, OFFSET endl; moves the location of endl to edx

L1:
call ReadInt ; takes user integer input for the eax register
mov [edi], eax; moves value from the eax register to the edi
add edi, TYPE DWORD; increments the address
Loop L1; restarts first loop


mov edx, OFFSET msg2 ; moves msg2 to the edx register
call WriteString ; Writes the value in the edx register to the screen
mov edx, OFFSET endl ; moves endl (line break) to the edx register
call WriteString ; prints the value in the edx register to the screen


mov ecx, LENGTHOF intarray/2 ;
L3:

Loop L3 ; restarts the loop

mov ecx, LENGTHOF intarray ;
mov edi, OFFSET intarray;

L4:
mov eax, edi;
call WriteInt
add edi, TYPE DWORD; increments the address

loop L4

invoke ExitProcess,0
main endp
end main

最佳答案

读取寄存器中的两个数组元素,然后在数组的请求末尾执行 addsub
在 EDI 中前进指针,但以两倍的速度降低 ECX。

    mov edi, OFFSET intarray
mov ecx, 9 ;10 elements in the array
Again:
mov eax, [edi]
mov ebx, [edi+ecx*4]
add [edi], ebx
sub [edi+ecx*4], eax
add edi, 4
sub ecx, 2
jnb Again

关于arrays - 更改 edi 的偏移量与更改地址处的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35688032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com