-
Notifications
You must be signed in to change notification settings - Fork 0
/
p1.s
271 lines (251 loc) · 3.49 KB
/
p1.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#include <sys/syscall.h>
.globl _main
.text
_main:
pushq %rbp
movq %rsp, %rbp
movl $0, -4(%rbp)
loop1:
cmpl $200, -4(%rbp)
jge out
# load loop1 value
movl -4(%rbp), %eax
leaq 0(,%rax,4), %rdx
leaq input(%rip), %rax
movl (%rdx,%rax), %ecx
movl %ecx, -12(%rbp)
movl $0, -8(%rbp)
loop2:
cmpl $200, -8(%rbp)
jge loop1_inc
# load loop2 value
movl -8(%rbp), %eax
cltq
leaq 0(,%rax,4), %rdx
leaq input(%rip), %rax
movl (%rdx,%rax), %ecx
movl %ecx, -16(%rbp)
movl -12(%rbp), %edx
addl %edx, %ecx
cmpl $2020, %ecx
je out
addl $1, -8(%rbp)
jmp loop2
loop1_inc:
addl $1, -4(%rbp)
jmp loop1
out:
# multiply
movl -12(%rbp), %ecx
movl -16(%rbp), %edx
imulq %rcx, %rdx
# print result
lea format(%rip), %rdi
movq %rdx, %rsi
xor %eax, %eax
call _printf
nop
popq %rbp
; ret
format: .asciz "%lu\n"
input:
.long 1544
.long 1560
.long 1947
.long 1659
.long 1972
.long 1940
.long 1977
.long 1689
.long 1916
.long 1638
.long 1804
.long 1543
.long 1789
.long 545
.long 968
.long 1959
.long 1783
.long 1869
.long 1581
.long 1976
.long 1859
.long 1660
.long 1793
.long 69
.long 1653
.long 1866
.long 1541
.long 1920
.long 1751
.long 1681
.long 1829
.long 2009
.long 1752
.long 680
.long 1864
.long 1628
.long 1917
.long 1876
.long 2002
.long 1974
.long 1827
.long 1791
.long 1552
.long 1669
.long 1849
.long 1167
.long 1744
.long 1764
.long 1913
.long 1782
.long 1926
.long 1795
.long 1738
.long 1877
.long 1811
.long 1746
.long 1682
.long 1943
.long 1761
.long 1850
.long 983
.long 1617
.long 1901
.long 1750
.long 1842
.long 1588
.long 1679
.long 1759
.long 1994
.long 1847
.long 1657
.long 1981
.long 1648
.long 1996
.long 1572
.long 1953
.long 1555
.long 1665
.long 1680
.long 1872
.long 1826
.long 1316
.long 1962
.long 1893
.long 1545
.long 1535
.long 1895
.long 1819
.long 1891
.long 1919
.long 1853
.long 1831
.long 704
.long 1978
.long 1780
.long 1722
.long 1652
.long 1625
.long 478
.long 1030
.long 1985
.long 1720
.long 1817
.long 264
.long 1988
.long 1892
.long 1712
.long 1222
.long 1840
.long 1894
.long 1906
.long 1890
.long 1846
.long 1939
.long 1991
.long 1835
.long 1799
.long 1865
.long 1663
.long 1908
.long 1575
.long 1970
.long 1956
.long 1556
.long 1688
.long 1558
.long 1698
.long 1771
.long 1807
.long 1878
.long 1707
.long 1770
.long 1823
.long 1802
.long 1930
.long 1703
.long 1136
.long 1910
.long 1998
.long 1973
.long 1611
.long 1979
.long 1612
.long 1838
.long 1715
.long 1885
.long 1879
.long 1904
.long 1941
.long 1734
.long 1900
.long 1809
.long 1691
.long 1848
.long 1683
.long 1754
.long 1874
.long 1975
.long 1896
.long 1567
.long 1785
.long 1644
.long 1922
.long 1651
.long 1046
.long 1971
.long 1600
.long 1933
.long 1857
.long 1960
.long 1948
.long 1675
.long 1828
.long 1633
.long 1868
.long 1615
.long 1884
.long 1674
.long 1860
.long 1775
.long 995
.long 1596
.long 2006
.long 1737
.long 1649
.long 1997
.long 1767
.long 1784
.long 1705
.long 1664
.long 1766
.long 1839
.long 1533
.long 1935
.long 1796
.long 1781
.long 1589
.long 1594
.long 1987
.long 1769