-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.s
168 lines (168 loc) · 2.86 KB
/
main.s
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
.file "main.c"
.text
.globl k_get_file_size
.type k_get_file_size, @function
k_get_file_size:
.LFB2:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $32, %rsp
movq %rdi, -24(%rbp)
cmpq $0, -24(%rbp)
je .L2
movq -24(%rbp), %rax
movl $2, %edx
movl $0, %esi
movq %rax, %rdi
call fseek
movq -24(%rbp), %rax
movq %rax, %rdi
call ftell
movq %rax, -8(%rbp)
movq -24(%rbp), %rax
movq %rax, %rdi
call rewind
movq -8(%rbp), %rax
jmp .L3
.L2:
movl $-1, %eax
.L3:
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE2:
.size k_get_file_size, .-k_get_file_size
.globl k_read_file_to_buffer
.type k_read_file_to_buffer, @function
k_read_file_to_buffer:
.LFB3:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $48, %rsp
movq %rdi, -24(%rbp)
movq %rsi, -32(%rbp)
movq %rdx, -40(%rbp)
movl $0, -4(%rbp)
jmp .L5
.L6:
movl -4(%rbp), %eax
movslq %eax, %rdx
movq -32(%rbp), %rax
addq %rax, %rdx
movzbl -5(%rbp), %eax
movb %al, (%rdx)
addl $1, -4(%rbp)
.L5:
movq -24(%rbp), %rax
movq %rax, %rdi
call fgetc
movb %al, -5(%rbp)
cmpb $-1, -5(%rbp)
jne .L6
nop
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE3:
.size k_read_file_to_buffer, .-k_read_file_to_buffer
.section .rodata
.LC0:
.string "r"
.LC1:
.string "%d\n"
.text
.globl main
.type main, @function
main:
.LFB4:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $64, %rsp
movl %edi, -52(%rbp)
movq %rsi, -64(%rbp)
cmpl $1, -52(%rbp)
jle .L8
movq -64(%rbp), %rax
addq $8, %rax
movq (%rax), %rax
movl $.LC0, %esi
movq %rax, %rdi
call fopen
movq %rax, -32(%rbp)
movq -32(%rbp), %rax
movq %rax, %rdi
call k_get_file_size
cltq
movq %rax, -24(%rbp)
movq -24(%rbp), %rax
movq %rax, %rdi
call malloc
movq %rax, -16(%rbp)
movq -24(%rbp), %rdx
movq -16(%rbp), %rcx
movq -32(%rbp), %rax
movq %rcx, %rsi
movq %rax, %rdi
call k_read_file_to_buffer
movq -24(%rbp), %rdx
movq %rdx, %rax
addq %rax, %rax
addq %rdx, %rax
leaq 0(,%rax,8), %rdx
addq %rdx, %rax
salq $2, %rax
movq %rax, %rdi
call malloc
movq %rax, -8(%rbp)
movq -8(%rbp), %rdx
movq -24(%rbp), %rcx
movq -16(%rbp), %rax
movq %rcx, %rsi
movq %rax, %rdi
call k_tokenize
movl %eax, -40(%rbp)
movl -40(%rbp), %eax
movslq %eax, %rdx
movq -8(%rbp), %rax
movq %rdx, %rsi
movq %rax, %rdi
call k_parse
movl %eax, -36(%rbp)
movl -36(%rbp), %eax
movl %eax, %esi
movl $.LC1, %edi
movl $0, %eax
call printf
movq -8(%rbp), %rax
movq %rax, %rdi
call free
movq -16(%rbp), %rax
movq %rax, %rdi
call free
movq -32(%rbp), %rax
movq %rax, %rdi
call fclose
.L8:
movl $0, %eax
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE4:
.size main, .-main
.ident "GCC: (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010"
.section .note.GNU-stack,"",@progbits