-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path151_Scanteie_AlexandruIoan_1.s
1485 lines (1160 loc) · 33.8 KB
/
151_Scanteie_AlexandruIoan_1.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
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
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.data
format_scanf: .asciz "%d \n"
format_printf: .asciz "%d "
format_printfn: .asciz "%d\n"
format_memory_get: .asciz "((%d, %d), (%d, %d))\n"
format_memory_add: .asciz "%d: ((%d, %d), (%d, %d))\n"
format_newline: .asciz "\n"
dir_path: .space 512
filename: .space 256
format_dir: .asciz "%s\n"
format_colon: .asciz ": "
# format_file_info: .asciz "FD: %d, Size: %d KB\n"
format_file_info: .asciz "%d\n%d\n"
auxVar: .long 0
nrOperatii: .long 0
tipOperatie: .long 0
fileDescriptor: .long 0
numberFiles: .long 0
fileSize: .long 0
i: .long 0
j: .long 0
n: .long 1024
n1: .long 1025
# m: .long 1048576 # n*n
m: .long 1049600 # n*(n+1) 1049600
v: .space 4198400 # 1025*1024*4 , 1025 = 1024 + 1 , 1 for border with -1 on the end of row
vector: .space 4198400
# m1: .long 1049600
m1: .long 1048576
v1: .space 4194304
last_position: .long 0
.text
initialize_matrix: # void initialize_matrix()
pushl %ebp
movl %esp, %ebp
# First fill entire matrix with zeros
xorl %ecx, %ecx # i = 0
lea v, %edi # %edi = *(v[0])
fill_zeros_loop:
cmpl m, %ecx # Check if we've reached end of matrix
jge add_borders
movl $0, (%edi,%ecx,4) # Set element to 0
incl %ecx
jmp fill_zeros_loop
add_borders:
# Now add -1 borders at end of each row
xorl %ecx, %ecx # i = 0
border_loop:
cmpl n, %ecx # ecx >= n
jge initialize_matrix_exit
movl n, %eax
incl %eax
imull %ecx, %eax # i * (n+1)
addl n, %eax # i * (n+1) + n
leal (%edi,%eax,4), %eax # &v[i][j]
movl $-1, (%eax) # Add border
incl %ecx
jmp border_loop
initialize_matrix_exit:
popl %ebp
ret
initialize_matrix_defr: # void initialize_matrix_defr()
pushl %ebp
movl %esp, %ebp
movl $0, last_position
xorl %ecx, %ecx # i = 0
lea v1, %edi # %edi = *(v1[0][0])
initialize_matrix_defr_loop:
cmpl n, %ecx # ecx >= n
jge initialize_matrix_defr_exit
movl n, %eax
incl %eax
imull %ecx, %eax # i * (n+1)
addl n, %eax # i * (n+1) + n
leal (%edi,%eax,4), %eax # &v1[i][j]
movl $-1, (%eax)
incl %ecx # j++
jmp initialize_matrix_defr_loop
initialize_matrix_defr_exit:
popl %ebp
ret
sum_vectorRange: # void sum_vectorRange(a,b)
pushl %ebp
movl %esp, %ebp
# movl 8(%ebp), %eax # a
# movl 12(%ebp), %ebx # b
# sum 16(%ebp)
movl 8(%ebp), %ecx # i = a
lea v, %edi # %edi = *(v[0])
sum_vectorRange_loop:
cmp 12(%ebp), %ecx # ecx >= b
jg sum_vectorRange_exit
pushl %ecx # %ecx caller saved
pushl %eax
movl (%edi,%ecx,4),%eax
addl 16(%ebp),%eax
movl %eax, 16(%ebp)
popl %eax
popl %ecx
incl %ecx
jmp sum_vectorRange_loop
sum_vectorRange_exit:
popl %ebp
ret
remove_line: # void remove_line(linie)
pushl %ebp
movl %esp, %ebp
pushl $0 # -4(%ebp) start
pushl $0 # -8(%ebp)
movl 8(%ebp), %eax # i = linie
movl n1, %ebx # Load the global variable n1 into %ebx
imull %ebx, %eax # Multiply %eax by %ebx (n1 * 8(%ebp))
movl %eax, -4(%ebp) # Store the result in -4(%ebp)
# pushl -4(%ebp)
# pushl $format_printf
# call printf
# popl %edx
# popl %edx
movl -4(%ebp), %ecx
lea v, %edi # %edi = *(v[0])
# movl n1, %ebx
# addl -4(%ebp),%ebx
remove_line_loop:
cmpl m, %ecx # ecx >= b
jg remove_line_exit
# v[i]=v[i+n1-1] # (%edi,%ecx,4)
movl n1, %ebx
addl %ecx,%ebx
# decl %ebx
movl (%edi,%ebx,4),%eax
movl %eax,(%edi,%ecx,4)
incl %ecx
jmp remove_line_loop
remove_line_exit:
popl %edx
popl %edx
popl %ebp
ret
print_vector: # void print_vector()
pushl %ebp
movl %esp, %ebp
# for(int i=0;i<n;i++)
# { printf("%d\n", v[i]); }
movl $0, %ecx # i = 0
lea v, %edi # %edi = *(v[0])
print_vector_loop:
cmp m, %ecx # ecx >= n
jge print_vector_exit
pushl %ecx # %ecx caller saved
pushl (%edi,%ecx,4) # v[i]
pushl $format_printf
call printf
popl %edx
popl %edx
popl %ecx
incl %ecx
jmp print_vector_loop
print_vector_exit:
pushl $format_newline
call printf
popl %edx
popl %ebp
ret
print_vector_defr: # void print_vector_defr()
pushl %ebp
movl %esp, %ebp
# for(int i=0;i<n;i++)
# { printf("%d\n", v1[i]); }
movl $0, %ecx # i = 0
lea v1, %edi # %edi = *(v[0])
print_vector_defr_loop:
cmp m, %ecx # ecx >= n
jge print_vector_defr_exit
pushl %ecx # %ecx caller saved
pushl (%edi,%ecx,4) # v[i]
pushl $format_printf
call printf
popl %edx
popl %edx
popl %ecx
incl %ecx
jmp print_vector_defr_loop
print_vector_defr_exit:
pushl $format_newline
call printf
popl %edx
popl %ebp
ret
print_matrix: # void print_matrix()
pushl %ebp
movl %esp, %ebp
# for(int i=0;i<n;i++)
# for(int j=0;j<n;j++)
# { printf("%d\n", v[i][j]); }
movl i, %ecx # i = 0
lea v, %edi # %edi = *(v[0][0])
print_matrix_loop_i:
cmp n, %ecx # ecx >= n
jge print_matrix_exit
pushl %ecx # %ecx caller saved
xorl %ebx, %ebx
print_matrix_loop_j:
cmpl n, %ebx # ebx >= n
jge print_matrix_next_row
movl %ecx, %eax
pushl %ebx
movl n, %ebx
incl %ebx
imull %ebx, %eax # i * (n+1)
popl %ebx
addl %ebx, %eax # i * (n+1) + j
movl (%edi,%eax,4), %eax # v[i][j]
pushl %ecx
push %eax
push $format_printf
call printf
popl %edx
popl %edx
popl %ecx
incl %ebx # j++
jmp print_matrix_loop_j
print_matrix_next_row:
push $format_newline
call printf
popl %edx
pop %ecx # Restore i
incl %ecx # i++
jmp print_matrix_loop_i
print_matrix_exit:
pushl $format_newline
call printf
popl %edx
popl %ebp
ret
print_matrix_defr: # void print_matrix_defr()
pushl %ebp
movl %esp, %ebp
# for(int i=0;i<n;i++)
# for(int j=0;j<n;j++)
# { printf("%d\n", v[i][j]); }
movl i, %ecx # i = 0
lea v1, %edi # %edi = *(v[0][0])
print_matrix_defr_loop_i:
cmp n, %ecx # ecx >= n
jge print_matrix_defr_exit
pushl %ecx # %ecx caller saved
xorl %ebx, %ebx
print_matrix_defr_loop_j:
cmpl n, %ebx # ebx >= n
jge print_matrix_defr_next_row
movl %ecx, %eax
pushl %ebx
movl n, %ebx
incl %ebx
imull %ebx, %eax # i * (n+1)
popl %ebx
addl %ebx, %eax # i * (n+1) + j
movl (%edi,%eax,4), %eax # v[i][j]
pushl %ecx
push %eax
push $format_printf
call printf
popl %edx
popl %edx
popl %ecx
incl %ebx # j++
jmp print_matrix_defr_loop_j
print_matrix_defr_next_row:
push $format_newline
call printf
popl %edx
pop %ecx # Restore i
incl %ecx # i++
jmp print_matrix_defr_loop_i
print_matrix_defr_exit:
pushl $format_newline
call printf
popl %edx
popl %ebp
ret
memory_add: # void memory_add(int fd, int size)
pushl %ebp
movl %esp, %ebp
pushl $0 # start -4(%ebp)
pushl $0 # lenght -8(%ebp)
pushl $0 # ok -12(%ebp)
pushl $0 # blocuri -16(%ebp)
pushl $0 # starty -20(%ebp)
pushl $0 # endy -24(%ebp)
pushl $0 # ok -28(%ebp)
pushl $0 # linia -32(%ebp)
movl $0, %ecx # i = 0
lea v, %edi # %edi = *(v[0][0])
movl 12(%ebp), %eax # file size
pushl %eax # file size
xorl %edx, %edx
movl $8, %ebx
div %ebx
cmpl $0, %edx
je set_blocuri
incl %eax
set_blocuri: # eax = nr blocuri = [size(kb)/8(kb)]
movl %eax, -16(%ebp)
memory_add_loop:
# for(int i = 0; i < n; i++){
# if(v[i] == 0){
# start = i;
# length = 0;
# }
# while(v[i] == 0){
# length++;
# if(length == blocuri){
# adaugi fisierul
# }
# }
# }
cmpl m, %ecx # ecx >= (n*(n+1))
jge memory_add_not_find
cmpl $0,(%edi,%ecx,4)
jne memory_add_continue
movl %ecx, -4(%ebp) # start = i;
movl $0, -8(%ebp) # lenght = 0;
movl $1, -12(%ebp) # ok = 1;
memory_add_while:
cmpl m, %ecx # ecx >= m
jge memory_add_not_find
cmpl $0, (%edi, %ecx, 4)
jne memory_add_continue
incl -8(%ebp) # lenght ++
incl %ecx
movl -8(%ebp), %edx
cmpl %edx,-16(%ebp) # if(length == blocuri)
je find_space_for_file
jmp memory_add_while
memory_add_continue:
incl %ecx
jmp memory_add_loop
find_space_for_file: # set (start,start+blocuri) = fd
movl -4(%ebp), %ecx
movl -16(%ebp), %ebx
addl %ecx, %ebx # ebx = start + blocuri
find_space_for_file_loop:
cmp %ebx, %ecx
jge memory_add_print
movl 8(%ebp), %edx
movl %edx, (%edi,%ecx,4) # v[i] = fd;
incl %ecx
jmp find_space_for_file_loop
memory_add_not_find:
# movl $0, -4(%ebp)
# movl $1, %ebx
pushl $0
pushl $0
pushl $0
pushl $0
pushl 8(%ebp)
pushl $format_memory_add
call printf
popl %edx
popl %edx
popl %edx
popl %edx
popl %edx
popl %edx
jmp memory_add_exit
memory_add_print:
find_line:
# pushl %edx
xorl %ecx,%ecx # i = 0
lea v, %edi # %edi = *(v[0])
movl 8(%ebp), %eax # file descriptor
find_line_loop:
cmpl m, %ecx # ecx >= m
jge find_line_exit
cmpl %eax, (%edi,%ecx,4) # if (fd == v[i])
jne find_line_continue
pushl %eax # fd
xorl %edx,%edx
movl %ecx,%eax
divl n1
movl %eax,-32(%ebp)
popl %eax
cmpl $0,-28(%ebp) # if (ok == 0)
je find_line_set_start
jmp find_line_set_end
find_line_set_start:
# popl %edx
movl %edx, -20(%ebp) # start = i
movl %edx, -24(%ebp)
movl $1,-28(%ebp)
find_line_set_end:
incl -24(%ebp) # end++
find_line_continue:
incl %ecx
jmp find_line_loop
find_line_exit:
decl -24(%ebp)
pushl -24(%ebp)
pushl -32(%ebp)
pushl -20(%ebp)
pushl -32(%ebp)
pushl 8(%ebp)
pushl $format_memory_add
call printf
popl %edx
movl $0, -32(%ebp)
movl $0, -24(%ebp)
movl $0, -20(%ebp)
movl $0, -28(%ebp)
popl %edx
popl %edx
popl %edx
popl %edx
popl %edx
memory_add_exit:
popl %edx
popl %edx
popl %edx
popl %edx
# For find_line stack
popl %edx
popl %edx
popl %edx
popl %edx
popl %edx # for eax
popl %ebp
ret
memory_get: # void memory_get(int fd)
pushl %ebp
movl %esp, %ebp
pushl $0 # starty -4(%ebp)
pushl $0 # endy -8(%ebp)
pushl $0 # ok -12(%ebp)
pushl $0 # linia -16(%ebp)
movl $0, %ecx # i = 0
lea v, %edi # %edi = *(v[0])
movl 8(%ebp), %eax # file descriptor
memory_get_loop:
cmp m, %ecx # ecx >= m
jge memory_get_exit
cmp %eax, (%edi,%ecx,4) # if (fd == v[i])
jne memory_get_continue
pushl %eax # fd
xorl %edx,%edx
movl %ecx,%eax
divl n1
movl %eax,-16(%ebp)
popl %eax
cmpl $0,-12(%ebp) # if (ok == 0)
je set_start
jmp set_end
set_start:
movl %edx, -4(%ebp) # start = i
movl %edx, -8(%ebp)
movl $1,-12(%ebp)
set_end:
incl -8(%ebp) # end++
memory_get_continue:
incl %ecx
jmp memory_get_loop
memory_get_exit:
cmpl $0,-8(%ebp)
je memory_get_print
decl -8(%ebp)
memory_get_print:
pushl -8(%ebp)
pushl -16(%ebp)
pushl -4(%ebp)
pushl -16(%ebp)
pushl $format_memory_get
call printf
popl %edx
popl %edx
popl %edx
popl %edx
popl %edx
popl %edx
popl %edx
popl %edx
popl %edx
popl %ebp
ret
memory_delete: # void memory_delete(int fd)
pushl %ebp
movl %esp, %ebp
movl $0, %ecx # i = 0
lea v, %edi # %edi = *(v[0])
movl 8(%ebp), %eax # file descriptor
memory_delete_loop:
cmp m, %ecx # ecx >= n
jge memory_delete_exit
cmp %eax, (%edi,%ecx,4) # if (fd == v[i])
jne memory_delete_continue
xorl %edx, %edx
movl %edx, (%edi,%ecx,4)
memory_delete_continue:
incl %ecx
jmp memory_delete_loop
memory_delete_exit:
popl %ebp
ret
move_elements_to_vector: # void move_elements_to_vector()
pushl %ebp
movl %esp, %ebp
# First initialize vector with zeros
xorl %ecx, %ecx # Initialize counter
lea vector, %edi # Get vector address
init_loop:
cmpl m, %ecx # Check if we've reached end of vector
jge init_done
movl $0, (%edi,%ecx,4) # Set element to 0
incl %ecx
jmp init_loop
init_done:
# Original move logic starts here
xorl %ecx, %ecx # Source index (v matrix)
xorl %ebx, %ebx # Destination index (vector)
lea v, %esi # Source array
lea vector, %edi # Destination array
move_loop:
cmpl m, %ecx # Check if we've reached end of v
jge move_exit
movl (%esi,%ecx,4), %eax # Get current element
# Check if element is 0 or -1
cmpl $0, %eax
je skip_element
cmpl $-1, %eax
je skip_element
# Element is valid, copy it to vector
movl %eax, (%edi,%ebx,4)
incl %ebx
skip_element:
incl %ecx
jmp move_loop
move_exit:
popl %ebp
ret
add_elements_from_vector: # void add_elements_from_vector()
pushl %ebp
movl %esp, %ebp
pushl $0 # -4(%ebp): current row
pushl $0 # -8(%ebp): current col
pushl $0 # -12(%ebp): vector index
pushl $0 # -16(%ebp): current descriptor
pushl $0 # -20(%ebp): count of current descriptor
pushl %ebx
pushl %esi
pushl %edi
# Initialize matrix with zeros first
call initialize_matrix
xorl %ecx, %ecx
lea vector, %esi # source (vector)
lea v, %edi # destination (matrix)
movl $0, -4(%ebp)
movl $0, -8(%ebp)
add_elements_loop:
movl (%esi,%ecx,4), %eax
cmpl $0, %eax
je add_elements_done
# If this is a new descriptor
cmpl -16(%ebp), %eax
je same_descriptor
# Count how many of this descriptor we have
movl %eax, -16(%ebp) # Save current descriptor
movl %ecx, %edx # Save current position
movl $0, -20(%ebp) # Reset counter
count_descriptor:
movl (%esi,%edx,4), %eax
cmpl $0, %eax # Check if we hit end
je check_fit
cmpl -16(%ebp), %eax # Compare with current descriptor
jne check_fit
incl -20(%ebp) # Increment counter
incl %edx
jmp count_descriptor
check_fit:
# If remaining space in row < count, move to next row
movl n, %eax
subl -8(%ebp), %eax # Remaining space in current row
cmpl -20(%ebp), %eax # Compare with needed space
jge same_descriptor # If enough space, continue
# Move to next row
movl $0, -8(%ebp) # Reset column
incl -4(%ebp) # Next row
same_descriptor:
# Calculate matrix position
movl -4(%ebp), %eax # Get current row
movl n1, %ebx # Get n+1 (row width)
mull %ebx # row * (n+1)
addl -8(%ebp), %eax # Add column offset
# Store element in matrix
movl (%esi,%ecx,4), %ebx
movl %ebx, (%edi,%eax,4)
# Update column
incl -8(%ebp)
# If we hit end of row, move to next row
movl -8(%ebp), %eax
cmpl n, %eax
jl continue_same_row
# Move to next row
movl $0, -8(%ebp) # Reset column
incl -4(%ebp) # Increment row
continue_same_row:
incl %ecx # Move to next vector element
jmp add_elements_loop
add_elements_done:
# Restore registers
popl %edi
popl %esi
popl %ebx
addl $20, %esp
movl %ebp, %esp
popl %ebp
ret
memory_defragmentation: # void memory_defragmentation()
pushl %ebp
movl %esp, %ebp
# pushl $format_debug_print
# call printf
# popl %eax
# popl %eax
# call print_all_files_fd_start_end
# Move elements to vector
call move_elements_to_vector
# Initialize matrix (empty it)
call initialize_matrix
# Add elements back from vector
call add_elements_from_vector
# Debug print after operations
# call debug_print
call print_all_files_fd_start_end
popl %eax
movl %ebp, %esp
popl %ebp
ret
get_size_for_fd: # int get_size_for_fd(int fd)
pushl %ebp
movl %esp, %ebp
# Get fd parameter
movl 8(%ebp), %edx
# Setup counters
xorl %ecx, %ecx # Position counter
xorl %eax, %eax # Size counter
lea v, %edi # Matrix base
count_loop:
cmpl m, %ecx
jge count_done
# Check if current element matches FD
cmpl %edx, (%edi,%ecx,4)
jne next_count
incl %eax # Increment size counter
next_count:
incl %ecx
jmp count_loop
count_done:
# Convert blocks to KB (multiply by 8)
movl $8, %ebx
mull %ebx
movl %ebp, %esp
popl %ebp
ret
print_all_files_fd_start_end: # void print_fd_start_end()
pushl %ebp
movl %esp, %ebp
xorl %eax, %eax
xorl %ebx, %ebx
pushl $0 # -4(%ebp) startX
pushl $0 # -8(%ebp) startY
pushl $0 # -12(%ebp) endX
pushl $0 # -16(%ebp) endY
lea v, %edi
print_all_files_fd_start_end_loop:
cmpl m, %ebx
jg print_all_files_fd_start_end_exit
movl (%edi,%ebx,4), %ecx # ecx = v[b]
movl (%edi,%eax,4), %edx # edx = v[a]
cmpl %ecx, %edx
je print_all_files_fd_start_end_continue
cmpl $0, %edx # Avoid print zero's
je avoid_print_zero
cmpl $-1, %edx # Avoid print zero's
je avoid_print_zero
movl %ebx, %edx # [a,b) edx = ebx-1
decl %edx
jmp print_all_files_fd_start_end_print
avoid_print_zero:
movl %ebx,%eax
print_all_files_fd_start_end_continue:
incl %ebx
jmp print_all_files_fd_start_end_loop
print_all_files_fd_start_end_print:
pushl %eax
pushl %edx
# pushl %edx finish v
# pushl %eax start v
pushl %edx
xorl %edx,%edx
divl n1
movl %eax,-4(%ebp) # startX
movl %eax,-12(%ebp) # endX
movl %edx,-8(%ebp) # startY
popl %edx
movl %edx,%eax
xorl %edx,%edx
divl n1
movl %edx,-16(%ebp) # endY
popl %edx
popl %eax
pushl -16(%ebp)
pushl -12(%ebp)
pushl -8(%ebp)
pushl -4(%ebp)
pushl (%edi,%eax,4)
pushl $format_memory_add
call printf
popl %eax
popl %eax
popl %eax
popl %eax
popl %eax
popl %eax
movl %ebx,%eax
jmp print_all_files_fd_start_end_continue
print_all_files_fd_start_end_exit:
# For local variables
popl %edx
popl %edx
popl %edx
popl %edx
popl %ebp
ret
scanf_matrix: # void scanf_matrix() # ecx = i , ebx = j
pushl %ebp
movl %esp, %ebp
# for(int i=0;i<n;i++)
# for(int j=0;j<n;j++)
# { printf("%d\n", &v[i][j]); }
xorl %ecx, %ecx # i = 0
lea v, %edi # %edi = *(v[0][0])
scanf_matrix_loop_i:
cmp n, %ecx # ecx >= n
jge scanf_matrix_exit
pushl %ecx # %ecx caller saved
xorl %ebx, %ebx
scanf_matrix_loop_j:
cmpl n, %ebx # ebx >= n
jge scanf_matrix_next_row
movl %ecx, %eax
pushl %ebx
movl n, %ebx
incl %ebx
imull %ebx, %eax # i * (n+1)
popl %ebx
addl %ebx, %eax # i * (n+1) + j
# shll $2, %eax # (i * (n) + j) * 4 (size of int)
leal (%edi,%eax,4), %eax # &v[i][j]
pushl %ecx
pushl %eax
push $format_scanf
call scanf
popl %edx
popl %edx
popl %ecx
incl %ebx # j++
jmp scanf_matrix_loop_j
scanf_matrix_next_row:
pop %ecx # Restore i
incl %ecx # i++
jmp scanf_matrix_loop_i
scanf_matrix_exit: