我想知道是否有人可以帮助我更好地理解为什么我编写的代码不起作用,并帮助我修复它。以下是我写的Y86,它应该总结我在其中定义的数组,但是,我可以让我的程序返回的是d4a而不是预期的cba。
.pos 0
init:
irmovq Stack, %rsp
rrmovq %rsp, %rbp
xorq %rcx, %rcx #zeroing out all temp variables
xorq %rdi, %rdi
xorq %rbx, %rbx
irmovq $8, %rdi #rdi has 4
irmovq ele1, %rbx #initialize rbx as ele1
irmovq $0, %rcx #sum is initially 0
call sum_list
halt
# Sample linked list
.align 8
ele1:
.quad 0x00a
.quad ele2
ele2:
.quad 0x0b0
.quad ele3
ele3:
.quad 0xc00
.quad 0
sum_list:
mrmovq (%rbx), %rax #current rbx value into rax
addq %rax, %rcx #rcx += current rbx value
addq %rdi, %rbx #add 4 to rbx address
andq %rax, %rax #check if previous rbx value was 0
jne sum_list #if it wasn't zero, restart, except rbx+4
done:
rrmovq %rcx, %rax #if it was 0, move the sum to rax
rrmovq %rbp, %rsp #restore rsp
popq %rbp #and rbp
ret #return rax, which should be the sum of linked list
.pos 0x300
Stack:
提前谢谢你们!装配很难掌握,当人们花时间向我解释这些东西时,它确实很有帮助!