-
Notifications
You must be signed in to change notification settings - Fork 438
/
copy_block.ys
47 lines (47 loc) · 885 Bytes
/
copy_block.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
43
44
45
46
47
# 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
# Source block
src:
.quad 0x00a
.quad 0x0b0
.quad 0xc00
# Destination block
dest:
.quad 0x111
.quad 0x222
.quad 0x333
main:
irmovq src , %rdi
irmovq dest , %rsi
irmovq $3 , %rdx
call copyblock
ret
# sum_list - Recursive version of sum_list
# start in %rdi
copyblock:
xorq %rax , %rax
loop:
andq %rdx , %rdx
jle end
mrmovq (%rdi) , %rcx
irmovq $8 , %rbx
addq %rbx , %rdi
rmmovq %rcx , (%rsi)
addq %rbx , %rsi
xorq %rcx , %rax
irmovq $1 , %rbx
subq %rbx , %rdx
jmp loop
end:
ret
# Stack starts here and grows to lower addresses
.pos 0x200
stack: