-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathout.asm
471 lines (464 loc) · 8.93 KB
/
out.asm
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
global main
extern ExitProcess
extern GetStdHandle
extern WriteFile
extern HeapAlloc
extern HeapFree
extern GetProcessHeap
section .text
__4: ; printi
push rbp
mov rbp, rsp
sub rsp, 48
; [inline asm]
sub rsp, 32
mov rcx, rbp
dec rcx
mov rax, qword [rbp+16]
mov qword [rbp-24], ""
mov qword [rbp-16], ""
mov dword [rbp-8], ""
mov dword [rbp-4], `\0\0\0\n`
cmp rax, 0
jge ._4.positive
mov dword [rbp-20], "-"
mov r8, rax
mov rax, 0
sub rax, r8
._4.positive:
mov rbx, 10
._4.loop:
xor rdx, rdx
div rbx
dec rcx
add rdx, '0'
mov [rcx], dl
test rax, rax
jnz ._4.loop
mov ecx, -11
call GetStdHandle
mov rcx, rax
mov rdx, rbp
sub rdx, 24
mov r8, 24
mov qword [rbp - 40], 0
mov r9, rbp
sub r9, 24
mov qword [rbp - 48], 0
call WriteFile
leave
ret
_2: ; add
push rbp
mov rbp, rsp
sub rsp, 160
; ' let new_node: Node = @Node {'
; [local copy] 24 , -24, 8
mov rax, qword [rbp+24]
mov qword [rbp-24], rax
; [inline asm]
mov qword [rbp-16], 0
; [inline asm]
mov rax, qword 0
mov qword [rbp-8], rax
; [inline asm]
; ' next,'
; ' true,'
; ' 0'
; ' };'
; ''
; ' if (!(*self.has_first)) {'
; [inline asm]
mov rax, qword [rbp+16]
add rax, 8
mov qword [rbp-32], rax
; [dyn from copy] -32 , -40, 8
mov r9, qword [rbp-32]
mov rax, qword [r9+0]
mov qword [rbp-40], rax
; [inline asm]
; [inline asm]
mov rax, qword [rbp-40]
cmp rax, 0
setz al
mov qword [rbp-48], rax
; [inline asm]
mov rax, qword [rbp-48]
cmp rax, 0
jnz .2.0
; ' *self.base = ^new_node;'
; [inline asm]
mov rax, qword [rbp+16]
add rax, 0
mov qword [rbp-56], rax
; [dyn from copy] -56 , -64, 8
mov r9, qword [rbp-56]
mov rax, qword [r9+0]
mov qword [rbp-64], rax
; [heap alloc] 24 , -64
sub rsp, 32
call GetProcessHeap
mov rcx, rax
mov rdx, 0
mov r8, 24
call HeapAlloc
mov qword [rbp-64], rax
add rsp, 32
; [dyn to copy] -24 , -64, 24
mov r9, qword [rbp-64]
mov rax, qword [rbp-24]
mov qword [r9+0], rax
mov rax, qword [rbp-16]
mov qword [r9+8], rax
mov rax, qword [rbp-8]
mov qword [r9+16], rax
; [dyn to copy] -64 , -56, 8
mov r9, qword [rbp-56]
mov rax, qword [rbp-64]
mov qword [r9+0], rax
; ' *self.has_first = true;'
; [inline asm]
mov rax, qword [rbp+16]
add rax, 8
mov qword [rbp-72], rax
; [dyn from copy] -72 , -80, 8
mov r9, qword [rbp-72]
mov rax, qword [r9+0]
mov qword [rbp-80], rax
; [inline asm]
mov qword [rbp-80], 0
; [dyn to copy] -80 , -72, 8
mov r9, qword [rbp-72]
mov rax, qword [rbp-80]
mov qword [r9+0], rax
; ' return;'
; [return] None
leave
ret
; [inline asm]
.2.0:
.2.1:
; ' *self.base = ^new_node;'
; ' *self.has_first = true;'
; ' return;'
; ' };'
; ''
; ' let curr: $Node = *self.base;'
; [inline asm]
mov rax, qword [rbp+16]
add rax, 0
mov qword [rbp-96], rax
; [dyn from copy] -96 , -88, 8
mov r9, qword [rbp-96]
mov rax, qword [r9+0]
mov qword [rbp-88], rax
; ' while (!(*curr.last)) {'
; [inline asm]
.2.2:
; [inline asm]
mov rax, qword [rbp-88]
add rax, 8
mov qword [rbp-104], rax
; [dyn from copy] -104 , -112, 8
mov r9, qword [rbp-104]
mov rax, qword [r9+0]
mov qword [rbp-112], rax
; [inline asm]
; [inline asm]
mov rax, qword [rbp-112]
cmp rax, 0
setz al
mov qword [rbp-120], rax
; [inline asm]
mov rax, qword [rbp-120]
cmp rax, 0
jnz .2.3
; ' curr = *curr.next;'
; [inline asm]
mov rax, qword [rbp-88]
add rax, 16
mov qword [rbp-128], rax
; [dyn from copy] -128 , -88, 8
mov r9, qword [rbp-128]
mov rax, qword [r9+0]
mov qword [rbp-88], rax
; [inline asm]
jmp .2.2
.2.3:
; ' curr = *curr.next;'
; ' };'
; ''
; ' *curr.last = false;'
; [inline asm]
mov rax, qword [rbp-88]
add rax, 8
mov qword [rbp-136], rax
; [dyn from copy] -136 , -144, 8
mov r9, qword [rbp-136]
mov rax, qword [r9+0]
mov qword [rbp-144], rax
; [inline asm]
mov qword [rbp-144], 1
; [dyn to copy] -144 , -136, 8
mov r9, qword [rbp-136]
mov rax, qword [rbp-144]
mov qword [r9+0], rax
; ' *curr.next = ^new_node;'
; [inline asm]
mov rax, qword [rbp-88]
add rax, 16
mov qword [rbp-152], rax
; [dyn from copy] -152 , -160, 8
mov r9, qword [rbp-152]
mov rax, qword [r9+0]
mov qword [rbp-160], rax
; [heap alloc] 24 , -160
sub rsp, 32
call GetProcessHeap
mov rcx, rax
mov rdx, 0
mov r8, 24
call HeapAlloc
mov qword [rbp-160], rax
add rsp, 32
; [dyn to copy] -24 , -160, 24
mov r9, qword [rbp-160]
mov rax, qword [rbp-24]
mov qword [r9+0], rax
mov rax, qword [rbp-16]
mov qword [r9+8], rax
mov rax, qword [rbp-8]
mov qword [r9+16], rax
; [dyn to copy] -160 , -152, 8
mov r9, qword [rbp-152]
mov rax, qword [rbp-160]
mov qword [r9+0], rax
leave
ret
_1: ; new
push rbp
mov rbp, rsp
sub rsp, 16
; ' return @LL {'
; [inline asm]
mov rax, qword 0
mov qword [rbp-16], rax
; [inline asm]
mov qword [rbp-8], 1
; [inline asm]
; [return] Some((-16, 16))
; [local copy] -16 , 16, 16
mov rax, qword [rbp-16]
mov qword [rbp+16], rax
mov rax, qword [rbp-8]
mov qword [rbp+24], rax
leave
ret
_4: ; test_two
push rbp
mov rbp, rsp
sub rsp, 64
; ' let ll: LL = LL#new();'
; [return call] 1 , [], -16
sub rsp, 8
sub rsp, 8
call _1
; [local copy] -80 , -16, 16
mov rax, qword [rbp-80]
mov qword [rbp-16], rax
mov rax, qword [rbp-72]
mov qword [rbp-8], rax
add rsp, 16
; ''
; ' ll.add(12);'
; [inline asm]
mov rax, rbp
add rax, -16
mov qword [rbp-24], rax
; [inline asm]
mov rax, qword 12
mov qword [rbp-32], rax
; [no return call] 2 , [(-24, 8), (-32, 8)]
sub rsp, 8
mov rax, qword [rbp-32]
mov qword [rbp-72], rax
sub rsp, 8
mov rax, qword [rbp-24]
mov qword [rbp-80], rax
call _2
add rsp, 16
; ''
; ' ll.add(18);'
; [inline asm]
mov rax, rbp
add rax, -16
mov qword [rbp-40], rax
; [inline asm]
mov rax, qword 18
mov qword [rbp-48], rax
; [no return call] 2 , [(-40, 8), (-48, 8)]
sub rsp, 8
mov rax, qword [rbp-48]
mov qword [rbp-72], rax
sub rsp, 8
mov rax, qword [rbp-40]
mov qword [rbp-80], rax
call _2
add rsp, 16
; ''
; ' ll.print();'
; [inline asm]
mov rax, rbp
add rax, -16
mov qword [rbp-56], rax
; [no return call] 3 , [(-56, 8)]
sub rsp, 8
mov rax, qword [rbp-56]
mov qword [rbp-72], rax
call _3
add rsp, 8
; ' printi(123123);'
; [inline asm]
mov rax, qword 123123
mov qword [rbp-64], rax
; [no return call] -4 , [(-64, 8)]
sub rsp, 8
mov rax, qword [rbp-64]
mov qword [rbp-72], rax
call __4
add rsp, 8
leave
ret
_3: ; print
push rbp
mov rbp, rsp
sub rsp, 112
; ' if (!(*self.has_first)) {'
; [inline asm]
mov rax, qword [rbp+16]
add rax, 8
mov qword [rbp-8], rax
; [dyn from copy] -8 , -16, 8
mov r9, qword [rbp-8]
mov rax, qword [r9+0]
mov qword [rbp-16], rax
; [inline asm]
; [inline asm]
mov rax, qword [rbp-16]
cmp rax, 0
setz al
mov qword [rbp-24], rax
; [inline asm]
mov rax, qword [rbp-24]
cmp rax, 0
jnz .3.0
; ' return;'
; [return] None
leave
ret
; [inline asm]
.3.0:
.3.1:
; ' return;'
; ' };'
; ''
; ' let curr: $Node = *self.base;'
; [inline asm]
mov rax, qword [rbp+16]
add rax, 0
mov qword [rbp-40], rax
; [dyn from copy] -40 , -32, 8
mov r9, qword [rbp-40]
mov rax, qword [r9+0]
mov qword [rbp-32], rax
; ' printi(*curr.cur);'
; [inline asm]
mov rax, qword [rbp-32]
add rax, 0
mov qword [rbp-48], rax
; [dyn from copy] -48 , -56, 8
mov r9, qword [rbp-48]
mov rax, qword [r9+0]
mov qword [rbp-56], rax
; [no return call] -4 , [(-56, 8)]
sub rsp, 8
mov rax, qword [rbp-56]
mov qword [rbp-120], rax
call __4
add rsp, 8
; ' while (!(*curr.last)) {'
; [inline asm]
.3.2:
; [inline asm]
mov rax, qword [rbp-32]
add rax, 8
mov qword [rbp-64], rax
; [dyn from copy] -64 , -72, 8
mov r9, qword [rbp-64]
mov rax, qword [r9+0]
mov qword [rbp-72], rax
; [inline asm]
; [inline asm]
mov rax, qword [rbp-72]
cmp rax, 0
setz al
mov qword [rbp-80], rax
; [inline asm]
mov rax, qword [rbp-80]
cmp rax, 0
jnz .3.3
; ' curr = *curr.next;'
; [inline asm]
mov rax, qword [rbp-32]
add rax, 16
mov qword [rbp-88], rax
; [dyn from copy] -88 , -32, 8
mov r9, qword [rbp-88]
mov rax, qword [r9+0]
mov qword [rbp-32], rax
; ' printi(*curr.cur);'
; [inline asm]
mov rax, qword [rbp-32]
add rax, 0
mov qword [rbp-96], rax
; [dyn from copy] -96 , -104, 8
mov r9, qword [rbp-96]
mov rax, qword [r9+0]
mov qword [rbp-104], rax
; [no return call] -4 , [(-104, 8)]
sub rsp, 8
mov rax, qword [rbp-104]
mov qword [rbp-120], rax
call __4
add rsp, 8
; [inline asm]
jmp .3.2
.3.3:
leave
ret
main: ; main
push rbp
mov rbp, rsp
sub rsp, 16
; ' test();'
; [no return call] 6 , []
call _6
add rsp, 0
; ''
; ' return 7;'
; [inline asm]
mov rax, qword 7
mov qword [rbp-8], rax
; [return] Some((-8, 8))
mov rcx, qword [rbp-8]
call ExitProcess
_6: ; test
push rbp
mov rbp, rsp
sub rsp, 0
; ' test_two();'
; [no return call] 4 , []
call _4
add rsp, 0
leave
ret