-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask00.s
More file actions
416 lines (339 loc) · 5.69 KB
/
task00.s
File metadata and controls
416 lines (339 loc) · 5.69 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
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
.data
v: .space 1024
nrop: .space 4
op: .space 4
nradd: .space 4
desc: .space 4
dim: .space 4
formatPrint: .asciz "%ld "
str1: .asciz "\n"
formatPrint1: .asciz "(%d, %d)\n"
formatPrint2: .asciz "%d: (%d, %d)\n"
formatScan: .asciz "%d"
.text
.global main
PRINT:
push %ebp
mov %esp, %ebp
push %ebx
push %esi
movl $1, %ecx
movl $1, %esi
PRINT_for:
cmp $1024, %ecx
je PRINT_iffinal
movl %ecx, %edx
subl $1, %edx
movb (%edi,%ecx,1), %al
movb (%edi,%edx,1), %bl
cmp %al, %bl
jne PRINT_nrnou
jmp PRINT_cont
PRINT_nrnou:
cmp $0, %bl
jne PRINT_nrnou_cont
jmp PRINT_zero
PRINT_nrnou_cont:
movl %ecx, %eax
subl %esi, %eax
push %ecx
push %edx
push %eax
movb %bl, %al
xor %ebx, %ebx
movb %al, %bl
push %ebx
push $formatPrint2
call printf
addl $16, %esp
push $0
call fflush
addl $4, %esp
pop %ecx
PRINT_zero:
xor %esi, %esi
PRINT_cont:
addl $1, %esi
inc %ecx
jmp PRINT_for
PRINT_iffinal:
cmp $0, %al
je PRINT_exit
movl %ecx, %edx
subl $1, %edx
movl %ecx, %ebx
subl %esi, %ebx
push %edx
push %ebx
movb %al, %bl
xor %eax, %eax
movb %bl, %al
push %eax
push $formatPrint2
call printf
addl $16, %esp
PRINT_exit:
pop %esi
pop %ebx
pop %ebp
ret
ADD:
push %ebp
mov %esp, %ebp
push %ebx
movb 8(%ebp), %bl
movl 12(%ebp), %eax
movl $8, %ecx
xor %edx, %edx
div %ecx
cmp $0, %edx
je ADD_else1
inc %eax
ADD_else1:
xor %edx, %edx
xor %ecx, %ecx
cmp $1, %eax
je ADD_exit
ADD_for1:
cmp $1024, %ecx
je ADD_nuintra
movb (%edi,%ecx,1), %bh
cmp $0, %bh
jne ADD_else2
inc %edx
jmp ADD_for1_cont
ADD_else2:
xor %edx, %edx
ADD_for1_cont:
cmp %edx, %eax
je ADD_cont
inc %ecx
jmp ADD_for1
ADD_cont:
inc %ecx
push %ecx
sub %eax, %ecx
mov %ecx, %edx
pop %ecx
push %edx
ADD_for2:
cmp %edx, %ecx
je ADD_afisare
movb %bl, (%edi, %edx, 1)
inc %edx
jmp ADD_for2
ADD_nuintra:
xor %eax, %eax
movl $1, %edx
push %eax
ADD_afisare:
subl $1, %edx
pop %eax
movb %bl, %cl
xor %ebx, %ebx
movb %cl, %bl
push %edx
push %eax
push %ebx
push $formatPrint2
call printf
addl $16, %esp
ADD_exit:
pop %ebx
pop %ebp
ret
GET:
push %ebp
movl %esp, %ebp
push %ebx
movb 8(%ebp), %bl
xor %ecx, %ecx
movl $-1, %eax
movl $-1, %edx
GET_for:
cmp $1024, %ecx
je GET_cont
movb (%edi, %ecx, 1), %bh
cmp %bh, %bl
je GET_if1
jne GET_else1
GET_if1:
cmp $-1, %eax
je GET_if2
jmp GET_for_cont
GET_if2:
movl %ecx, %eax
jmp GET_for_cont
GET_else1:
cmp $-1, %eax
jne GET_else2
jmp GET_for_cont
GET_else2:
sub $1, %ecx
movl %ecx, %edx
jmp GET_cont
GET_for_cont:
inc %ecx
jmp GET_for
GET_cont:
cmp $-1, %eax
je GET_nuexista
cmp $-1, %edx
je GET_if3
jmp GET_afisare
GET_nuexista:
xor %eax, %eax
xor %edx, %edx
jmp GET_afisare
GET_if3:
movl $1023, %edx
GET_afisare:
push %edx
push %eax
push $formatPrint1
call printf
addl $12, %esp
GET_exit:
pop %ebx
pop %ebp
ret
DELETE:
push %ebp
movl %esp, %ebp
push %ebx
movb 8(%ebp), %bl
xor %ecx, %ecx
DELETE_for:
cmp $1024, %ecx
je DELETE_exit
movb (%edi, %ecx, 1), %al
cmp %al, %bl
je DELETE_elem
jmp DELETE_for_cont
DELETE_elem:
movb $0, (%edi, %ecx, 1)
DELETE_for_cont:
inc %ecx
jmp DELETE_for
DELETE_exit:
call PRINT
pop %ebx
pop %ebp
ret
DEFRAG:
push %ebp
movl %esp, %ebp
push %ebx
xor %ecx, %ecx
xor %edx, %edx
DEFRAG_for:
cmp $1024, %ecx
je DEFRAG_cont
movb (%edi, %ecx, 1), %bl
cmp $0, %bl
jne DEFRAG_for_if
jmp DEFRAG_for_cont
DEFRAG_for_if:
movb (%edi, %ecx, 1), %bl
movb %bl, (%edi, %edx, 1)
inc %edx
DEFRAG_for_cont:
inc %ecx
jmp DEFRAG_for
DEFRAG_cont:
movl %edx, %ecx
DEFRAG_forzero:
cmp $1024, %ecx
je DEFRAG_exit
movb $0, (%edi, %ecx, 1)
inc %ecx
jmp DEFRAG_forzero
DEFRAG_exit:
call PRINT
pop %ebx
pop %ebp
ret
main:
lea v, %edi
push $nrop
push $formatScan
call scanf
addl $8, %esp
xor %ecx, %ecx
for:
cmp %ecx, nrop
je exit
push %ecx
push $op
push $formatScan
call scanf
addl $8, %esp
cmpl $1, op
je if_add
cmpl $2, op
je if_get
cmpl $3, op
je if_delete
cmpl $4, op
je if_defrag
// jmp caz op invalid?
if_add:
push $nradd
push $formatScan
call scanf
addl $8, %esp
xor %ebx, %ebx
if_add_for:
cmp %ebx, nradd
je for_cont
push $desc
push $formatScan
call scanf
addl $8, %esp
push $dim
push $formatScan
call scanf
addl $8, %esp
push dim
push desc
call ADD
addl $8, %esp
inc %ebx
jmp if_add_for
if_get:
push $desc
push $formatScan
call scanf
addl $8, %esp
push desc
call GET
addl $4, %esp
jmp for_cont
if_delete:
push $desc
push $formatScan
call scanf
addl $8, %esp
push desc
call DELETE
addl $4, %esp
jmp for_cont
if_defrag:
call DEFRAG
for_cont:
// push $str1
// call printf
// addl $4, %esp
pop %ecx
inc %ecx
jmp for
exit:
// push $str1
// call printf
// addl $4, %esp
push $0
call fflush
addl $4, %esp
movl $1, %eax
xor %ebx, %ebx
int $0x80