-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path134_Florete_FabianAndrei_1.s
More file actions
494 lines (409 loc) · 7.16 KB
/
134_Florete_FabianAndrei_1.s
File metadata and controls
494 lines (409 loc) · 7.16 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
.data
x: .space 4
nr_cerinta: .space 4
n: .space 4
m1: .space 4
m2: .space 4
mres: .space 4
frecv_leg: .space 404
read_format: .asciz "%ld"
print_format: .asciz "%ld "
flush_format: .asciz "\n"
.text
#matrix_mult(m1, m2, mres, n)
matrix_mult:
pushl %ebp
movl %esp, %ebp
subl $12, %esp
#adresa de inceput a m1 in %esi, adresa de inceput a m2 in %edi
#adresa mres este in 16(%ebp)
movl $0, -4(%ebp)
#20(%ebp) are n-ul
#-4(%ebp) are cnt_for1
#-8(%ebp) are cnt_for2
#-12(%ebp) are cnt_for3
for1_matrix:
movl 20(%ebp), %eax
cmpl %eax, -4(%ebp)
je return
#for(int i = 0; i < n; i++)
movl $0, -8(%ebp)
movl -4(%ebp), %eax
movl 20(%ebp), %ecx
mull %ecx
shl $2, %eax
addl %eax, 8(%ebp)
addl %eax, 16(%ebp)
#in 8(%ebp) ar trb acum sa fie pozitionata linia de inceput pt a[i][k]. Adica am a[i][] pana acum. pushl %eax ca sa stiu cat sa scad dupa
#calculez intre timp si c[i][j]
pushl %eax
for2_matrix:
movl 20(%ebp), %eax
cmpl %eax, -8(%ebp)
je after_for2_matrix
#for(int j = 0; j < n; j++)
movl $0, -12(%ebp)
movl -8(%ebp), %eax
shl $2, %eax
addl %eax, 12(%ebp)
addl %eax, 16(%ebp)
pushl %eax
for3_matrix:
movl 20(%ebp), %eax
cmpl %eax, -12(%ebp)
je after_for3_matrix
#for(int k = 0; k < n; k++)
#c[i][j] += a[i][k] * b[k][j]
#momentan am a[i][] si b[][j]
#=> la a[i][] mai adun k si la b[][j] mai adun k*len << 2
#=> 8(%ebp) += k
#=> 12(%ebp) += k * len << 2
movl -12(%ebp), %eax
shl $2, %eax
pushl %eax
addl %eax, 8(%ebp)
movl 20(%ebp), %ecx
movl -12(%ebp), %eax
mull %ecx
shl $2, %eax
pushl %eax
addl %eax, 12(%ebp)
#fac c[i][j] = 8(%ebp) * 12(%ebp)
movl 8(%ebp), %eax
movl 0(%eax), %eax
movl 12(%ebp), %ecx
movl 0(%ecx), %ecx
mull %ecx
pushl %edi
movl 16(%ebp), %edi
movl 16(%ebp), %ecx
movl 0(%ecx), %ecx
addl %eax, %ecx
xorl %eax, %eax
movl %ecx, (%edi, %eax, 4)
popl %edi
popl %eax
subl %eax, 12(%ebp)
popl %eax
subl %eax, 8(%ebp)
incl -12(%ebp)
jmp for3_matrix
after_for3_matrix:
popl %eax
subl %eax, 12(%ebp)
subl %eax, 16(%ebp)
incl -8(%ebp)
jmp for2_matrix
after_for2_matrix:
popl %eax
subl %eax, 8(%ebp)
subl %eax, 16(%ebp)
incl -4(%ebp)
jmp for1_matrix
return:
addl $12, %esp
popl %ebp
ret
init:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
movl $0, -4(%ebp)
for1_init:
movl 12(%ebp), %eax
cmpl %eax, -4(%ebp)
je return_init
movl -4(%ebp), %eax
movl 12(%ebp), %ecx
mull %ecx
shl $2, %eax
movl $0, -8(%ebp)
addl %eax, 8(%ebp)
pushl %eax
for2_init:
movl 12(%ebp), %eax
cmpl %eax, -8(%ebp)
je after_for2_init
movl -8(%ebp), %eax
shl $2, %eax
addl %eax, 8(%ebp)
movl 8(%ebp), %ecx
movl $0, 0(%ecx)
subl %eax, 8(%ebp)
incl -8(%ebp)
jmp for2_init
after_for2_init:
popl %eax
subl %eax, 8(%ebp)
incl -4(%ebp)
jmp for1_init
return_init:
addl $8, %esp
popl %ebp
ret
copy:
#copy (m1, m2) => m2 se copiaza in m1
pushl %ebp
movl %esp, %ebp
subl $8, %esp
movl $0, -4(%ebp)
for1_copy:
movl -4(%ebp), %eax
cmpl %eax, 16(%ebp)
je return_copy
movl 16(%ebp), %ecx
mull %ecx
shl $2, %eax
addl %eax, 8(%ebp)
addl %eax, 12(%ebp)
pushl %eax
movl $0, -8(%ebp)
for2_copy:
movl -8(%ebp), %eax
cmpl %eax, 16(%ebp)
je after_for2_copy
shl $2, %eax
addl %eax, 8(%ebp)
addl %eax, 12(%ebp)
pushl %eax
movl 12(%ebp), %eax
movl 0(%eax), %eax
movl 8(%ebp), %ecx
movl %eax, 0(%ecx)
popl %eax
subl %eax, 8(%ebp)
subl %eax, 12(%ebp)
incl -8(%ebp)
jmp for2_copy
after_for2_copy:
popl %eax
subl %eax, 8(%ebp)
subl %eax, 12(%ebp)
incl -4(%ebp)
jmp for1_copy
return_copy:
addl $8, %esp
popl %ebp
ret
.globl main
main:
movl $192, %eax
movl $0, %ebx
movl $40000, %ecx
movl $3, %edx
movl $33, %esi
movl $-1, %edi
movl $0, %ebp
int $0x80
movl %eax, m1
movl $192, %eax
movl $0, %ebx
movl $40000, %ecx
movl $3, %edx
movl $33, %esi
movl $-1, %edi
movl $0, %ebp
int $0x80
movl %eax, m2
movl $192, %eax
movl $0, %ebx
movl $40000, %ecx
movl $3, %edx
movl $33, %esi
movl $-1, %edi
movl $0, %ebp
int $0x80
movl %eax, mres
citire_numar_cerinta:
pushl $nr_cerinta
pushl $read_format
call scanf
addl $8, %esp
citire_numar_noduri:
pushl $n
pushl $read_format
call scanf
addl $8, %esp
creare_matrice:
#ebx = i-> i*4*nr_col = %eax. #ecx = j
#eax = i, #ecx = j in v[i][j]
initializre_legaturi:
xorl %ecx, %ecx
lea frecv_leg, %esi
#citesc frecventa nodurilor
for1:
cmpl n, %ecx
je after_for1
pushl %ecx
lea (%esi, %ecx, 4), %eax
pushl %eax
pushl $read_format
call scanf
addl $8, %esp
popl %ecx
incl %ecx
jmp for1
after_for1:
#creez graficul, citesc legaturile fiecarui nod
#ecx parcurge vectorul de noduri
#ebx parcurge detinatia nodurilor
#v[i][[j] = 1
xorl %ecx, %ecx
movl m1, %esi
lea frecv_leg, %edi
for2:
cmpl n, %ecx
je select_cerinta
#pregatesc indicele liniei in %eax care va fi salvat pe stiva
movl n, %eax
mull %ecx
shl $2, %eax
movl (%edi, %ecx, 4), %ebx
addl %eax, %esi
pushl %eax
for3:
cmpl $0, %ebx
je after_for3
pushl %ecx
pushl $x
pushl $read_format
call scanf
addl $4, %esp
movl x, %eax
addl $4, %esp
popl %ecx
movl $1, (%esi, %eax, 4)
decl %ebx
jmp for3
after_for3:
popl %eax
subl %eax, %esi
incl %ecx
jmp for2
select_cerinta:
cmpl $1, nr_cerinta
je cerinta1
cmpl $3, nr_cerinta
je cerinta2
jmp exit
cerinta1:
xorl %ecx, %ecx
movl m1, %esi
for1_cerinta1:
cmpl n, %ecx
je exit
movl n, %eax
mull %ecx
shl $2, %eax
addl %eax, %esi
xorl %ebx, %ebx
pushl %eax
pushl %ecx
for2_cerinta1:
cmpl n, %ebx
je after_for2_cerinta1
pushl (%esi, %ebx, 4)
pushl $print_format
call printf
addl $8, %esp
incl %ebx
jmp for2_cerinta1
after_for2_cerinta1:
pushl $flush_format
call printf
addl $4, %esp
popl %ecx
popl %eax
subl %eax, %esi
incl %ecx
jmp for1_cerinta1
cerinta2:
pushl n
pushl m1
pushl m2
call copy
addl $12, %esp
pushl %ebp
movl %esp, %ebp
subl $12, %esp
subl $4, %ebp
pushl %ebp
addl $4, %ebp
pushl $read_format
call scanf
addl $8, %esp
subl $8, %ebp
pushl %ebp
addl $8, %ebp
pushl $read_format
call scanf
addl $8, %esp
subl $12, %ebp
pushl %ebp
addl $12, %ebp
pushl $read_format
call scanf
addl $8, %esp
pushl n
pushl m1
pushl mres
call copy
addl $12, %esp
movl -4(%ebp), %eax
decl -4(%ebp)
for1_cerinta2:
#matricea trb ridicata la lung_drumului adica -4(%ebp)
movl -4(%ebp), %eax
cmpl $0, %eax
je afisare_cerinta2
pushl n
pushl mres
pushl m2
call copy
addl $12, %esp
pushl n
pushl mres
call init
addl $8, %esp
pushl n
pushl mres
pushl m2
pushl m1
call matrix_mult
addl $16, %esp
decl -4(%ebp)
jmp for1_cerinta2
afisare_cerinta2:
movl mres, %esi
movl -8(%ebp), %eax
movl -12(%ebp), %ecx
mull n
shl $2, %eax
addl %eax, %esi
pushl (%esi, %ecx, 4)
pushl $print_format
call printf
addl $8, %esp
pushl $flush_format
call printf
addl $4, %esp
golire_stiva_cerinta2:
addl $12, %esp
popl %ebp
exit:
dealocare_matrici:
movl $91, %eax
movl mres, %ebx
movl $40000, %ecx
int $0x80
movl $91, %eax
movl m2, %ebx
movl $40000, %ecx
int $0x80
movl $91, %eax
movl m1, %ebx
movl $40000, %ecx
int $0x80
movl $1, %eax
xorl %ebx, %ebx
int $0x80