Getting and setting an address pointer from memory in Y86-64 assembly

177 views Asked by At

I am trying to implement a linked list in Y86-64 assembly. I am so far able to start at the first element in the list and grab/store the value stored in the linked list (and then add it to a running sum in a different register) however, my problem is that I can't then grab the address of the pointer to the next item in the link list and then set the address of the item I want to go to to the appropriate register.

Here is the code I have so far:

irmovq list, %rax # Get the address of the first item in the list
irmovq $8, %rdx # Bytes to shift 
irmovq $0, %rbx # Starting integer for running sum

loop:
 # intialize comparison
 irmovq $0, %rcx # comparison 0
 
 #grab value from list element
 mrmovq (%rax), %rsp
 
 #add value
 addq %rsp, %rbx
 
 #get address of next element


 
 #Test whether or not to break the loop by seeing if the address is equal to 0
 subq %rax, %rcx
 je endState
 jmp loop

endState:
    rrmovq %rcx, %rax 
    halt


.align 8
list:
ele1:
    .quad 0x100
    .quad ele4
ele2:
    .quad 0x10
    .quad ele3
ele3:
    .quad 0x100
    .quad ele5
ele4:
    .quad 0x1000
    .quad ele2
ele5:
    .quad 0x10000
    .quad 0
    

To explain ele5, .quad 0 represents the end of the linked list. I test for this value to get out of the loop I defined above.

0

There are 0 answers