forked from Exely/CSAPP-Labs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rsum.ys
42 lines (42 loc) · 742 Bytes
/
rsum.ys
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Execution begins at address 0
.pos 0
irmovq stack, %rsp
# Set up stack pointer
call main
# Execute main program
halt
# Terminate program
# Sample linked list
.align 8
ele1:
.quad 0x00a
.quad ele2
ele2:
.quad 0x0b0
.quad ele3
ele3:
.quad 0xc00
.quad 0
main:
irmovq ele1,%rdi
xorq %rax,%rax
call rsumlist
ret
# sum_list - Recursive version of sum_list
# start in %rdi
rsumlist:
pushq %rcx
andq %rdi , %rdi
je end
mrmovq (%rdi) , %rcx
irmovq $8 , %rbx
addq %rbx , %rdi
mrmovq (%rdi), %rdi
call rsumlist
addq %rcx , %rax
end:
popq %rcx
ret
# Stack starts here and grows to lower addresses
.pos 0x200
stack: