-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc_select.s
194 lines (180 loc) · 3.95 KB
/
func_select.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
# 214289415 dan binnun
.section .rodata
str1: .string "first pstring length: %d, second pstring length: %d\n"
str2: .string " %c %c"
str3: .string "old char: %c, new char: %c, first string: %s, second string: %s\n"
str4: .string "%hhu"
str5: .string "length: %d, string: %s\n"
str6: .string "compare result: %d\n"
str7: .string "invalid option!\n"
.align 8
.L10:
.quad .L1 #case 50
.quad .L2 #case 51
.quad .L3 #case 52
.quad .L4 #case 53
.quad .L6 #case 54
.quad .L5 #case 55
.quad .L2 #case 56
.quad .L2 #case 57
.quad .L2 #case 58
.quad .L2 #case 59
.quad .L1 #case 60
.text
.globl run_func
.type run_func, @function
run_func:
leaq -50(%rdi),%rdi
cmpq $10,%rdi
ja .L2
jmp *.L10(,%rdi,8)
.L1:
pushq %rbp
movq %rsp,%rbp
movq %rsi,%rdi #set arg of pstrlen
pushq %rdx #caller saved register
call pstrlen
popq %rdx
movq %rax,%rsi #assign result to printf second arg
movq %rdx,%rdi
pushq %rsi #caller saved register
call pstrlen
popq %rsi
movq %rax,%rdx
movq $str1,%rdi
movq $0,%rax
call printf
movq %rbp,%rsp
popq %rbp
ret
.L2:
movq $0,%rax
movq $str7,%rdi
call printf
ret
.L3:
pushq %rbp
movq %rsp,%rbp
leaq -8(%rsp),%rsp
pushq %rdx #save second str
pushq %rsi #save first str
leaq -8(%rsp),%rsp #allocate space for two characters
movq $str2,%rdi
movq $0,%rax
movq %rsp,%rsi #set destination for new char
leaq 1(%rsp),%rdx
movq $0,%rax
call scanf
movzbq 1(%rsp),%rdx #set old char arg
movzbq (%rsp),%rsi #set new char arg
leaq 8(%rsp),%rsp #dealloacte chars memory
popq %rdi #set first pstring to first arg of replace char
pushq %rsi #caller saved register
pushq %rdx #caller saved register
call replaceChar
popq %rdx #restore caller saved register
popq %rsi #restore caller saved register
popq %rdi #set second pstring to first arg of replace char
pushq %rax #save result of first string
pushq %rsi #caller saved register
pushq %rdx #caller saved register
call replaceChar
leaq 1(%rax),%r8 #set fifth arg of printf to second string result
popq %rdx #restore caller saved register
popq %rsi #restore caller saved register
popq %rax
leaq 1(%rax),%rcx #set fourth arg of printf to first string result
movq $str3,%rdi
leaq -8(%rsp),%rsp #set rsp to be 16 align to call printf
movq $0,%rax
call printf
movq %rbp,%rsp
popq %rbp
ret
.L4:
pushq %rbp
movq %rsp,%rbp
pushq %rsi #save first
pushq %rdx #save second
leaq -16(%rsp),%rsp
movq $0,%rax
movq $str4,%rdi
leaq 1(%rsp),%rsi #scan i
call scanf
movq $0,%rax
movq $str4,%rdi
movq %rsp,%rsi #scan j
call scanf
movzbq 1(%rsp),%rdx #put i in third arg
movzbq (%rsp),%rcx #put j in fourth arg
leaq 16(%rsp),%rsp
popq %rsi #put src in second arg
popq %rdi #put dest in first arg
pushq %rsi #save src
leaq -8(%rsp),%rsp
call pstrijcpy
movq $str5,%rdi
movzbq (%rax),%rsi #put dest length in second arg of printf
leaq 1(%rax),%rdx #put dest string pointer in third arg of printf
movq $0,%rax
call printf
leaq 8(%rsp),%rsp
popq %rdx #get src
movq $str5,%rdi
movzbq (%rdx),%rsi #put src length in second arg of printf
leaq 1(%rdx),%rdx #put src string pointer in third arg of printf
movq $0,%rax
call printf
movq %rbp,%rsp
popq %rbp
ret
.L5:
pushq %rbp
movq %rsp,%rbp
pushq %rsi
pushq %rdx
leaq -16(%rsp),%rsp
movq $str4,%rdi
movq %rsp,%rsi
movq $0,%rax
call scanf
movq $str4,%rdi
leaq 1(%rsp),%rsi
movq $0,%rax
call scanf
movzbq (%rsp),%rdx
movzbq 1(%rsp),%rcx
leaq 16(%rsp),%rsp
popq %rsi
popq %rdi
leaq -16(%rsp),%rsp
call pstrijcmp
movq %rax,%rsi
movq $0,%rax
movq $str6,%rdi
call printf
movq %rbp,%rsp
popq %rbp
ret
.L6:
pushq %rbp
movq %rsp,%rbp
movq %rsi,%rdi
pushq %rdx
call swapCase
movq $str5,%rdi
movzbq (%rax),%rsi
leaq 1(%rax),%rdx
movq $0,%rax
call printf
popq %rdi
leaq -8(%rsp),%rsp
call swapCase
movq $str5,%rdi
movzbq (%rax),%rsi
leaq 1(%rax),%rdx
movq $0,%rax
call printf
movq %rbp,%rsp
popq %rbp
ret