我有来自CMU架构实验室的以下y86-64程序,该程序应该总结链表的值。
# Adam Cooper ac251190
init:
.pos 0x0
irmovq Stack, %rsp # set up stack pointer
irmovq Stack, %rbp # set up base pointer
call Main
halt
# Sample linked list
.align 8
ele1:
.quad 0x00a
.quad ele2
ele2:
.quad 0x0b0
.quad ele3
ele3:
.quad 0xc00
.quad 0
Main:
irmovq ele1, %rax
pushq %rax # Pointer to list pushed to stack
call Sum
ret
Sum:
pushq %rbp # Push %rbp onto the stack
rrmovq %rsp, %rbp
mrmovq 8(%rbp), %rdx # Move ele1 into %rdx
irmovq $0, %rax # Set up a base to add eles to
andq %rdx, %rdx # Is this the end of the list?
je End # If it is, jump to the end
irmovq $8, %rcx # Turn %rcx into a index mover
Loop:
mrmovq (%rdx), %rbx # Move ls into %rbx
addq %rbx, %rax # val += ele
addq %rcx, %rdx # Move to next value in the list
mrmovq (%rdx), %rdx
andq %rdx, %rdx # Are we at the last ele?
jne Loop # If not, go again
End:
popq %rbp # TEAR! DOWN! THE STACK!
ret # Return the original call to Main
.pos 0x400
Stack:
程序在行"ADR"
处停止,状态为0x093
,即行
Loop:
mrmovq (%rdx), %rbx
现在,我被文档认为"ADR"
错误意味着该程序试图访问高于0xFFF
的地址,但事实并非如此。堆栈似乎也已初始化并正确设置。我使用了与我编写的其他几个程序相同的方法。不确定这里出了什么问题。
答案 0 :(得分:0)
没关系。固定它。已将max-width
更改为mrmovq 8(%rbp), %rdx
。感谢任何考虑过帮助的人