-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc_select.s
More file actions
202 lines (182 loc) · 3.86 KB
/
func_select.s
File metadata and controls
202 lines (182 loc) · 3.86 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
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
.section .rodata
input_err: .string "invalid option!\n" # for wrong input
func_50: .string "first pstring length: %d, second pstring length: %d\n"
func_51: .string "old char: %c, new char: %c, first string: %s, second string: %s\n"
f51_sc: .string "%c %c"
dummy: .string "%c"
func_52: .string "length: %d, string: %s\n"
f52_sc: .string "%d"
func_53: .string "length: %d, string: %s\n"
func_54: .string "compare result: %d\n"
f54_sc: .string "%d"
.align 8
.SWITCH: # jump table
.quad .L50
.quad .L51
.quad .L52
.quad .L53
.quad .L54
.text
.globl run_func
run_func:
pushq %rbp
movq %rsp, %rbp
leal -50(%edi), %ecx
cmpl $4, %ecx
ja .ERR
jmp *.SWITCH(,%ecx,8)
.L50:
pushq %r12
pushq %r13
pushq %rdx
movq %rsi, %rdi
call pstrln
movzbl %al, %r12d # first length
popq %rdi
call pstrln
movzbl %al, %r13d # second length
movq $func_50, %rdi
movl %r12d, %esi
movl %r13d, %edx
movq $0, %rax
call printf
popq %r13
popq %r12
jmp .DONE
.L51:
pushq %r12
pushq %r13
movq %rsi, %r12
movq %rdx, %r13
subq $1, %rsp
leaq (%rsp), %rsi
movq $dummy, %rdi
movq $0, %rax
call scanf # first scan new lone from previous scan
subq $2, %rsp
leaq 1(%rsp), %rsi
leaq (%rsp), %rdx
movq $f51_sc, %rdi
movq $0, %rax
call scanf # scan 2 chars
movq %r12, %rdi
movb 1(%rsp), %sil
movb (%rsp), %dl
call replaceChar
movq %rax, %r12
movq %r13, %rdi
movb 1(%rsp), %sil
movb (%rsp), %dl
call replaceChar
movq %rax, %r13
movb 1(%rsp), %sil
movb (%rsp), %dl
movq %r12, %rcx
inc %rcx # skip length byte
movq %r13, %r8
inc %r8 # skip length byte
movq $0, %rax
movq $func_51, %rdi
call printf
addq $3, %rsp
popq %r13
popq %r12
jmp .DONE
.L52:
pushq %rsi # save first ptr
pushq %rdx # save second ptr
subq $8, %rsp
leaq 4(%rsp), %rsi
movq $f52_sc, %rdi
movq $0, %rax
call scanf # scan first int
leaq (%rsp), %rsi
movq $f52_sc, %rdi
movq $0, %rax
call scanf # scan second int
movb 4(%rsp), %dl
movb (%rsp), %cl
movq 8(%rsp), %rsi # second ptr
movq 16(%rsp),%rdi # first ptr
call pstrijcpy
movq %rax, %rdx
inc %rdx # skip length byte
movzbl (%rax), %esi # get length
movq $func_52, %rdi
movq $0, %rax
call printf
movq 8(%rsp), %rax # rax will have second str ptr
movzbl (%rax), %esi # get length
movq %rax, %rdx
inc %rdx # skip length byte
movq $func_52, %rdi
movq $0, %rax
call printf
jmp .DONE
.L53:
pushq %r12
pushq %r13
pushq %r14
pushq %r15
movq %rsi, %r12 # temp for first pointer
movq %rdx, %r13 # temp for second pointer
movq %rsi, %rdi
call swapCase
pushq %rax # save first pointer
movq %r12, %rdi
call pstrln
movzbl %al, %r14d # save first length
movq %r13, %rdi
call swapCase
pushq %rax # save second pointer
movq %r13, %rdi
call pstrln
movzbl %al, %r15d # save second length
popq %r13 # second pointer
inc %r13 # skip length byte
movl %r14d, %esi # first length
popq %rdx # first pointer
inc %rdx # skip length byte
movq $0, %rax
movq $func_53, %rdi
call printf
movq $0, %rax
movq $func_53, %rdi
movl %r15d, %esi
movq %r13, %rdx
call printf
popq %r15
popq %r14
popq %r13
popq %r12
jmp .DONE
.L54:
pushq %rsi # save first ptr
pushq %rdx # save second ptr
subq $8, %rsp
leaq 4(%rsp), %rsi
movq $f54_sc, %rdi
movq $0, %rax
call scanf # scan first int
leaq (%rsp), %rsi
movq $f54_sc, %rdi
movq $0, %rax
call scanf # scan second int
movb 4(%rsp), %dl
movb (%rsp), %cl
movq 8(%rsp), %rsi
movq 16(%rsp),%rdi
call pstrijcmp
movl %eax, %esi
movq $func_54, %rdi
movq $0, %rax
call printf
jmp .DONE
.ERR: # printing error
movq $input_err, %rdi
movq $0, %rax
call printf
jmp .DONE
.DONE:
leave
ret