-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.s
More file actions
70 lines (64 loc) · 1.26 KB
/
Copy pathmain.s
File metadata and controls
70 lines (64 loc) · 1.26 KB
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
.section .rodata
d: .string "%d"
s: .string "%s"
.text
.global main
main:
pushq %rbp
movq %rsp, %rbp
pushq %r12
pushq %r13
subq $4, %rsp
movq %rsp, %rsi
movq $d, %rdi
movq $0, %rax
call scanf # scan first int
movslq (%rsp), %rsi # get number
movb (%rsp), %r12b # first byte of length
dec %rsp # for \0
movb $0, (%rsp) # put \0
subq %rsi, %rsp # add n bytes
movq $s, %rdi
movq %rsp, %rsi
movq $0, %rax
call scanf # scan first string
dec %rsp
movb %r12b, (%rsp) # put length
movq %rsp, %r12 # points to first pstring
subq $4, %rsp
movq %rsp, %rsi
movq $d, %rdi
movq $0, %rax
call scanf # scan second int
movslq (%rsp), %rsi # get number
movb (%rsp), %r13b # first byte of length
dec %rsp # for \0
movb $0, (%rsp) # put \0
subq %rsi, %rsp # add n bytes
movq $s, %rdi
movq %rsp, %rsi
movq $0, %rax
call scanf # scan second string
dec %rsp
movb %r13b, (%rsp) # put length
movq %rsp, %r13 # points to second pstring
subq $4, %rsp
movq %rsp, %rsi
movq $d, %rdi
movq $0, %rax
call scanf # scan choice
movl (%rsp), %edi
movq %r12, %rsi
movq %r13, %rdx
call run_func
# now restore r12 and r13
movzbq (%r13), %rdx
addq $2, %rsp
addq %rdx, %rsp
movzbq (%r12), %rdx
addq $2, %rsp
addq %rdx, %rsp
popq %r13
popq %r12
leave
ret