I have the following y86-64 program from CMU's Architecture lab that's supposed to sum up the values of a linked list.
# 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:
The program halts with status "ADR"
at line 0x093
which is the line
Loop:
mrmovq (%rdx), %rbx
Now, I was led to believe by the documentation that an "ADR"
error meant the program was trying to access an address higher that 0xFFF
, but it's not. The stack also appears to have been initialized and set up correctly. I used the same method as several other programs I've written that worked fine. Not really sure what's going wrong here.
Never mind. Fixed it. Changed mrmovq 8(%rbp), %rdx
to mrmovq 16(%rbp), %rdx
. Thanks to anybody who considered helping