-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.s
More file actions
48 lines (36 loc) · 636 Bytes
/
main.s
File metadata and controls
48 lines (36 loc) · 636 Bytes
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
48
.section .text
foo:
push %rbp
movq %rsp, %rbp
sub $24, %rsp # int a;
# int b;
# int c;
movq %rdi, 0(%rsp) # a = _a;
movq %rsi, 8(%rsp) # b = _b;
add %rdi, %rsi # c = a + b;
movq %rsi, 16(%rsp)
movq %rsi, %rax # return c;
movq %rbp, %rsp
pop %rbp
ret
bar:
push %rbp
movq %rsp, %rbp
sub $24, %rsp # int a;
# int b;
# int c;
movq $1, 0(%rsp) # a = 1;
movq $2, 8(%rsp) # b = 2;
movq 0(%rsp), %rdi # foo(a, b);
movq 8(%rsp), %rsi
call foo
movq %rax, 16(%rsp) # c = foo(a, b);
leave # return c;
ret
.global main
main:
push %rbp
movq %rsp, %rbp
call bar
leave
ret