-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask01.s
More file actions
713 lines (615 loc) · 10.8 KB
/
task01.s
File metadata and controls
713 lines (615 loc) · 10.8 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
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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
.data
matrix: .space 1048576
nrop: .space 4
op: .space 4
nradd: .space 4
desc: .space 4
dim: .space 4
var: .space 4
ok: .space 4
nrzero: .space 4
elem: .long 0
dimelem: .long 0
index1: .long 0
index2: .long 0
index3: .long 0
nrlinii: .long 1024
formatPrint1: .asciz "((%d, %d), (%d, %d))\n"
formatPrint2: .asciz "%d: ((%d, %d), (%d, %d))\n"
formatScan: .asciz "%d"
.text
.global main
PRINT:
push %ebp
movl %esp, %ebp
push %ebx
push %esi
xor %ecx, %ecx
PRINT_fori:
cmp $1024, %ecx
je PRINT_exit
movl $1, %edx
movl $1, %esi
PRINT_forj:
cmp $1024, %esi
je PRINT_fori_cont1
// aflam v[ecx][esi] si v[ecx][esi-1]
// lineindex*columns + columnindex
// ecx * 8 + esi
push %edx
xor %edx, %edx
movl %ecx, %eax
movl $1024, %ebx
mull %ebx
addl %esi, %eax
movb (%edi, %eax, 1), %bl
subl $1, %eax
movb (%edi, %eax, 1), %bh
pop %edx
cmp %bl, %bh
jne PRINT_nrnou
jmp PRINT_forj_cont
PRINT_nrnou:
cmp $0, %bh
jne PRINT_nrnou_cont
xor %edx, %edx
jmp PRINT_forj_cont
PRINT_nrnou_cont:
push %eax
push %ecx
subl $1, %esi
push %esi
addl $1, %esi
push %ecx
subl %edx, %esi
push %esi
addl %edx, %esi
push %ecx
xor %eax, %eax
movb %bh, %al
push %eax
push $formatPrint2
call printf
addl $24, %esp
push $0
call fflush
addl $4, %esp
pop %ecx
pop %eax
xor %edx, %edx
PRINT_forj_cont:
inc %edx
inc %esi
jmp PRINT_forj
PRINT_fori_cont1:
cmp $0, %bl
jne PRINT_nrnoufinal
jmp PRINT_fori_cont2
PRINT_nrnoufinal:
push %ecx
subl $1, %esi
push %esi
addl $1, %esi
push %ecx
subl %edx, %esi
push %esi
addl %edx, %esi
push %ecx
xor %eax, %eax
movb %bl, %al
push %eax
push $formatPrint2
call printf
addl $24, %esp
push $0
call fflush
addl $4, %esp
pop %ecx
PRINT_fori_cont2:
inc %ecx
jmp PRINT_fori
PRINT_exit:
pop %esi
pop %ebx
pop %ebx
ret
ADD_line:
push %ebp
movl %esp, %ebp
push %ebx
push %esi
movb 8(%ebp), %bl
movl 12(%ebp), %eax
movl 16(%ebp), %esi
movl $8, %ecx
xor %edx, %edx
divl %ecx
cmp $0, %edx
je ADD_line_cont1
inc %eax
ADD_line_cont1:
xor %edx, %edx
xor %ecx, %ecx
cmp $1, %eax
je ADD_line_nuexista
ADD_line_for1:
cmp $1024, %ecx
je ADD_line_nuexista
// aflam v[linie][ecx]
// lineIndex * colums + columnIndex
// linie * 8 + ecx
push %eax
push %edx
push %ebx
xor %edx, %edx
movl %esi, %eax
movl $1024, %ebx
mull %ebx
addl %ecx, %eax
pop %ebx
pop %edx
movb (%edi, %eax, 1), %bh
pop %eax
cmp $0, %bh
jne ADD_line_else
inc %edx
jmp ADD_line_for1_cont
ADD_line_else:
xor %edx, %edx
ADD_line_for1_cont:
cmp %edx, %eax
je ADD_line_cont2
inc %ecx
jmp ADD_line_for1
ADD_line_cont2:
inc %ecx
push %ecx
sub %eax, %ecx
mov %ecx, %edx
pop %ecx
push %edx
ADD_line_for2:
cmp %edx, %ecx
je ADD_line_afisare
// v[line][edx]=%bl
push %eax
push %edx
push %ebx
push %ecx
movl %edx, %ecx
xor %edx, %edx
movl %esi, %eax
movl $1024, %ebx
mull %ebx
addl %ecx, %eax
pop %ecx
pop %ebx
pop %edx
movb %bl, (%edi, %eax, 1)
pop %eax
inc %edx
jmp ADD_line_for2
ADD_line_afisare:
subl $1, %edx
pop %eax
movb %bl, %cl
xor %ebx, %ebx
movb %cl, %bl
push %edx
push %esi
push %eax
push %esi
push %ebx
push $formatPrint2
call printf
addl $24, %esp
push $0
call fflush
addl $4, %esp
jmp ADD_line_exit
ADD_line_nuexista:
movl $-1, %ecx
ADD_line_exit:
pop %esi
pop %ebx
pop %ebp
ret
ADD:
push %ebp
movl %esp, %ebp
push %ebx
push %esi
movl 8(%ebp), %esi
//descriptor possible issues
movl 12(%ebp), %eax
//dimensiune
xor %ebx, %ebx
ADD_for:
cmp $1024, %ebx
je ADD_test
push %ebx
push %eax
push %esi
call ADD_line
pop %esi
pop %eax
pop %ebx
cmp $-1, %ecx
jne ADD_exit
inc %ebx
jmp ADD_for
ADD_test:
cmp $-1, %ecx
jne ADD_exit
push $0
push $0
push $0
push $0
push %esi
push $formatPrint2
call printf
addl $24, %esp
ADD_exit:
pop %esi
pop %ebx
pop %ebp
ret
GET:
push %ebp
movl %esp, %ebp
push %ebx
push %esi
movb 8(%ebp), %bl
xor %ecx, %ecx
movl $-1, %eax
movl $-1, %edx
GET_fori:
cmp $1024, %ecx
jge GET_cont
xor %esi, %esi
GET_forj:
cmp $1024, %esi
jge GET_fori_cont
// aflam v[ecx][esi]
// lineindex*colums + columnindex
// ecx*8+esi
push %eax
push %edx
push %ebx
xor %edx, %edx
movl %ecx, %eax
movl $1024, %ebx
mull %ebx
addl %esi, %eax
pop %ebx
pop %edx
movb (%edi, %eax, 1), %bh
pop %eax
cmp %bh, %bl
je GET_if1
jne GET_if2
GET_if1:
cmp $-1, %eax
je GET_if1_true
movl %esi, %edx
jmp GET_forj_cont
GET_if1_true:
movl %esi, %eax
movl %esi, %edx
push %ecx
jmp GET_forj_cont
GET_if2:
cmp $-1, %eax
jne GET_if2_true
jmp GET_forj_cont
GET_if2_true:
movl $1024, %ecx
movl $1024, %esi
GET_forj_cont:
inc %esi
jmp GET_forj
GET_fori_cont:
inc %ecx
jmp GET_fori
GET_cont:
cmp $-1, %eax
je GET_nuexista
jne GET_exista
jmp GET_afisare
GET_nuexista:
movl $0, %eax
movl $0, %edx
movl $0, %ecx
jmp GET_afisare
GET_exista:
pop %ecx
GET_afisare:
push %edx
push %ecx
push %eax
push %ecx
push $formatPrint1
call printf
addl $20, %esp
push $0
call fflush
addl $4, %esp
GET_exit:
pop %esi
pop %ebx
pop %ebp
ret
DELETE:
push %ebp
movl %esp, %ebp
push %ebx
movb 8(%ebp), %bl
xor %ecx, %ecx
DELETE_for:
cmp $1048576, %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:
pop %ebx
pop %ebp
ret
DEFRAG_linie:
push %ebp
movl %esp, %ebp
push %ebx
push %esi
movl 8(%ebp), %esi
xor %ecx, %ecx
xor %edx, %edx
DEFRAG_linie_for:
cmp $1024, %ecx
je DEFRAG_linie_cont
# aflam eax = linie*nrlinii + ecx
push %edx
movl %esi, %eax
xor %edx, %edx
mull nrlinii
addl %ecx, %eax
pop %edx
movb (%edi, %eax, 1), %bl
cmp $0, %bl
jne DEFRAG_linie_for_if
jmp DEFRAG_linie_for_cont
DEFRAG_linie_for_if:
movb (%edi, %eax, 1), %bl
push %edx
movl %esi, %eax
xor %edx, %edx
mull nrlinii
pop %edx
addl %edx, %eax
movb %bl, (%edi, %eax, 1)
inc %edx
DEFRAG_linie_for_cont:
inc %ecx
jmp DEFRAG_linie_for
DEFRAG_linie_cont:
movl %edx, %ecx
DEFRAG_linie_forzero:
cmp $1024, %ecx
je DEFRAG_linie_exit
push %edx
movl %esi, %eax
xor %edx, %edx
mull nrlinii
addl %ecx, %eax
pop %edx
movb $0, (%edi, %eax, 1)
inc %ecx
jmp DEFRAG_linie_forzero
DEFRAG_linie_exit:
movl %edx, var
pop %esi
pop %ebx
pop %ebp
ret
DEFRAG:
push %ebp
movl %esp, %ebp
push %ebx
push %esi
xor %ecx, %ecx
DEFRAG_for:
cmp $1024, %ecx
je DEFRAG_exit
push %ecx
call DEFRAG_linie
pop %ecx
movl $1024, nrzero
movl nrzero, %eax
subl var, %eax
movl %eax, nrzero
movl $0, elem
movl $0, dimelem
movl %ecx, index1
addl $1, index1
DEFRAG_for1:
cmpl $1024, index1
je DEFRAG_for_cont
cmpl $1, nrzero
jg DEFRAG_for1_2
movl $1023, index1
jmp DEFRAG_for1_cont
DEFRAG_for1_2:
movl $0, index2
DEFRAG_for2:
cmpl $1024, index2
je DEFRAG_for1_cont
# aflam v[index1][index2]
# index1*nrlinii+index2
movl index1, %eax
xor %edx, %edx
mull nrlinii
addl index2, %eax
movb (%edi, %eax, 1), %bl
cmp elem, %bl
jne DEFRAG_for2_if1
cmpl $0, elem
jne DEFRAG_for2_inc
jmp DEFRAG_for2_cont
DEFRAG_for2_inc:
addl $1, dimelem
jmp DEFRAG_for2_cont
DEFRAG_for2_if1:
cmpl $0, elem
jne DEFRAG_for2_if2
push %ecx
movb %bl, %cl
xor %ebx, %ebx
movb %cl, %bl
pop %ecx
movl %ebx, elem
movl $1, dimelem
jmp DEFRAG_for2_cont
DEFRAG_for2_if2:
movl nrzero, %eax
cmpl dimelem, %eax
jge DEFRAG_for2_if3
movl $1023, index1
movl $1023, index2
jmp DEFRAG_for2_cont
DEFRAG_for2_if3:
push %ecx
push elem
call DELETE
pop elem
pop %ecx
movl var, %eax
movl %eax, index3
addl dimelem, %eax
DEFRAG_for3:
cmp index3, %eax
je DEFRAG_for2_if3_cont
push %eax
movl %ecx, %eax
xor %edx, %edx
mull nrlinii
addl index3, %eax
movl elem, %edx
movb %dl, (%edi, %eax, 1)
pop %eax
addl $1, index3
jmp DEFRAG_for3
DEFRAG_for2_if3_cont:
movl %eax, var
movl nrzero, %eax
subl dimelem, %eax
movl %eax, nrzero
# v[index1][index2] = index1*nrlinii + index2
movl index1, %eax
xor %edx, %edx
mull nrlinii
addl index2, %eax
xor %edx, %edx
movb (%edi, %eax, 1), %dl
movl %edx, elem
cmp $0, %edx
je DEFRAG_for2_if4
movl $1, dimelem
jmp DEFRAG_for2_cont
DEFRAG_for2_if4:
movl $0, dimelem
jmp DEFRAG_for2_cont
DEFRAG_for2_cont:
addl $1, index2
jmp DEFRAG_for2
DEFRAG_for1_cont:
addl $1, index1
jmp DEFRAG_for1
DEFRAG_for_cont:
inc %ecx
jmp DEFRAG_for
DEFRAG_exit:
call PRINT
pop %esi
pop %ebx
pop %ebp
ret
main:
lea matrix, %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
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
call PRINT
jmp for_cont
if_defrag:
call DEFRAG
for_cont:
pop %ecx
inc %ecx
jmp for
exit:
movl $1, %eax
xor %ebx, %ebx
int $0x80