2016-05-01 30 views
1

我有以下CMU的架構實驗室y86-64程序,應該總結一個鏈表的值。在y86程序中獲取ADR錯誤,不知道爲什麼。堆棧似乎設置得很好

# 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: 

程序在行0x093這是行

Loop: 
     mrmovq (%rdx), %rbx 

現在,我的帶領下,一個"ADR"錯誤意味着程序試圖訪問一個地址的文檔,相信與狀態"ADR"暫停高於0xFFF,但事實並非如此。該堆棧也似乎已被初始化並正確設置。我使用了與我編寫的其他幾個程序相同的方法,工作得很好。不太確定這裏有什麼問題。

回答

0

沒關係。修復。將mrmovq 8(%rbp), %rdx更改爲mrmovq 16(%rbp), %rdx。感謝任何人認爲幫助

相關問題