I was wondering if anyone could help me better understand both why this code that I have written does not work, and help me also to fix it. The following is the Y86 I've written which should sum the array which I've defined within it, however, all I can get my program to return is d4a instead of the expected 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:
Thank you ahead of time guys! Assembly is really hard to get a grasp on and it really helps when people take the time to explain these things to me!