.global calculate_sum calculate_sum: # %rdi is the address of the first item in the list # This moves the first item to eax # movl (%rdi), %eax # 8 because of structure padding # This finds the second item # add $8, %rdi # mov (%rdi), %rdi # movl (%rdi), %eax xor %rax, %rax loop_top: cmp $0, %rdi je end # Add the item we're on into eax, which is our sum movl (%rdi), %edx addl %edx, %eax # traverse one item of the list add $4, %rdi mov (%rdi), %rdi jmp loop_top end: # Sum needs to be in rax ret .global calculate_sum_and_count calculate_sum_and_count: # %rdi is the address of the first item in the list # %rsi holds a pointer to the place our sum should go xor %rcx, %rcx xor %rax, %rax loop_top_csac: cmp $0, %rdi je end_csac # Add the item we're on into eax, which is our sum movl (%rdi), %edx addl %edx, %ecx inc %rax # traverse one item of the list add $4, %rdi mov (%rdi), %rdi jmp loop_top_csac end_csac: cmp $0, %rsi je not_set_sum movl %ecx, (%rsi) not_set_sum: # Sum needs to be in rax ret