我正在为课堂实验室做这个,但我没有找到我要去的地方。如果我用 l 而不是 q 为我的所有指令添加后缀(例如 -andl 而不是 andq , rrmovl 而不是 rrmovq ),但不是用 q 后缀,程序就可以工作。我真的很感激一些关于我做错了什么的指针。
.pos 0
init: irmovq Stack, %rsp # Set up stack pointer
rrmovq %rsp,%rbp # Set up base pointer
irmovq ele1,%rax
pushq %rax
call sum_list # Execute main program
halt # Terminate program
# Sample linked list
.align 8
ele1: .quad 0x00a
.quad ele2
ele2: .quad 0x0b0
.quad ele3
ele3: .quad 0xc00
.quad 0
# int sum_list(list_ptr ls)
sum_list: pushq %rbp
rrmovq %rsp,%rbp
xorq %rax,%rax # val = 0
mrmovq 8(%rbp),%rdx # edx = ls
andq %rdx,%rdx # Set condition codes
je End
Loop: mrmovq (%rdx),%rcx # ecx = ls->val
addq %rcx,%rax # val += ls->val
mrmovq 4(%rdx),%rdx # ls = ls->next ------ tried +8 insetead of 4 also
andq %rdx,%rdx # Set condition codes
jne Loop
End: rrmovq %rbp,%rsp
popq %rbp
nop # makes sure stop in 31 steps
ret
# The stack starts here and grows to lower addresses
.pos 0x100
堆: