-
Notifications
You must be signed in to change notification settings - Fork 0
/
MatrixMul.s
354 lines (292 loc) · 4.68 KB
/
MatrixMul.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
.data
cerinta: .space 4
n: .space 4
v: .space 400
elem: .space 4
index: .space 4
index2: .space 4
x: .space 4
lungime: .space 4
nod1: .space 4
nod2: .space 4
cnt: .space 4
m1: .space 40000
m2: .space 40000
mres: .space 40000
formatScanf: .asciz "%ld"
formatPrintf: .asciz "%ld "
formatP2: .asciz "\n"
.text
.global main
main:
citire_cerinta:
pushl $cerinta
pushl $formatScanf
call scanf
popl %ebx
popl %ebx
citire_n:
pushl $n
pushl $formatScanf
call scanf
popl %ebx
popl %ebx
//initializare:
movl $v, %edi
movl $0, index
xorl %ecx, %ecx
citire_legaturi:
movl index, %ecx
cmp %ecx, n
je citire_noduri
pushl $elem
pushl $formatScanf
call scanf
popl %ebx
popl %ebx
movl elem, %eax
movl index, %ecx
movl %eax, (%edi, %ecx, 4)
addl $1, index
jmp citire_legaturi
citire_noduri:
movl $0, index
xorl %ecx, %ecx
citire_loop:
cmp %ecx, n
je alege
movl (%edi, %ecx, 4), %eax
movl $0, %ebx
cmp %eax, %ebx
je incrementare_ecx
pushl $x
pushl $formatScanf
call scanf
popl %ebx
popl %ebx
movl index, %eax
movl $0, %edx
mull n
addl x, %eax
movl $m1, %ebx
movl $1, (%ebx, %eax, 4)
movl index, %ecx
movl (%edi, %ecx, 4), %eax
subl $1, %eax
movl %eax, (%edi, %ecx, 4)
jmp citire_loop
incrementare_ecx:
addl $1, index
movl index, %ecx
jmp citire_loop
alege:
movl cerinta, %eax
movl $1, %ebx
cmp %eax, %ebx
je afisare_matrice
movl $2, %ebx
je task2
task2:
pushl $lungime
pushl $formatScanf
call scanf
popl %ebx
popl %ebx
pushl $nod1
pushl $formatScanf
call scanf
popl %ebx
popl %ebx
pushl $nod2
pushl $formatScanf
call scanf
popl %ebx
popl %ebx
constr_matrice:
movl $0, index
xorl %ecx, %ecx
for_linii:
movl index, %ecx
cmp %ecx, n
je cont
movl $0, index2
for_coloane:
movl index2, %ecx
cmp %ecx, n
je reinit
movl index, %eax
movl $0, %edx
mull n
addl index2, %eax
movl $m1, %ebx
movl (%ebx, %eax, 4), %edx
movl $m2, %ebx
movl %edx, (%ebx, %eax, 4)
addl $1, index2
jmp for_coloane
reinit:
addl $1, index
jmp for_linii
cont:
movl $1, cnt
looop:
movl cnt, %eax
movl lungime, %ebx
cmp %eax, %ebx
je afisare
pushl n
pushl $mres
pushl $m2
pushl $m1
call matrix_mult
addl $16, %esp
addl $1, cnt
jmp copiere
copiere:
movl $0, index
xorl %ecx, %ecx
for_linii1:
movl index, %ecx
cmp %ecx, n
je looop
movl $0, index2
for_coloane1:
movl index2, %ecx
cmp %ecx, n
je reinit1
movl index, %eax
movl $0, %edx
mull n
addl index2, %eax
movl $mres, %ebx
movl (%ebx, %eax, 4), %edx
movl $m2, %ebx
movl %edx, (%ebx, %eax, 4)
addl $1, index2
jmp for_coloane1
reinit1:
addl $1, index
jmp for_linii1
matrix_mult:
push %ebp
mov %esp, %ebp
push %ebx
push %esi
push %edi
subl $12, %esp
movl $0, -16(%ebp)
for_i:
movl -16(%ebp), %eax
cmp %eax, n
je actual1
movl $0, -20(%ebp)
for_j:
movl -20(%ebp), %ebx
cmp %ebx, n
je actual2
movl $0, -24(%ebp)
for_k:
movl -16(%ebp), %eax
movl -20(%ebp), %ebx
movl -24(%ebp), %ecx
cmp %ecx, n
je actual3
movl n, %ebx
xorl %edx, %edx
mull %ebx
addl %ecx, %eax
movl 8(%ebp), %ecx
movl (%ecx, %eax, 4), %edi
movl -24(%ebp), %eax
movl n, %ebx
xorl %edx, %edx
mull %ebx
movl -20(%ebp), %ecx
addl %ecx, %eax
movl 12(%ebp), %ecx
movl (%ecx, %eax, 4), %ebx
movl %ebx, %eax
xorl %edx, %edx
mull %edi
movl %eax, %ebx
movl -16(%ebp), %eax
movl n, %ecx
xorl %edx, %edx
mull %ecx
movl -20(%ebp), %ecx
addl %ecx, %eax
movl 16(%ebp), %edi
addl %ebx, (%edi, %eax, 4)
addl $1, -24(%ebp)
jmp for_k
actual3:
addl $1, -20(%ebp)
jmp for_j
actual2:
addl $1, -16(%ebp)
jmp for_i
actual1:
add $12, %esp
pop %edi
pop %esi
pop %ebx
pop %ebp
ret
afisare:
movl nod1, %eax
movl n, %ebx
xorl %edx, %edx
mull %ebx
movl nod2, %ebx
addl %ebx, %eax
movl $mres, %edi
movl (%edi, %eax, 4), %ebx
pushl %ebx
pushl $formatPrintf
call printf
popl %ebx
popl %ebx
pushl $0
call fflush
popl %ebx
jmp et_exit
afisare_matrice:
movl $0, index
xorl %ecx, %ecx
for_linii2:
movl index, %ecx
cmp %ecx, n
je et_exit
movl $0, index2
for_coloane2:
movl index2, %ecx
cmp %ecx, n
je reinit2
movl index, %eax
movl $0, %edx
mull n
addl index2, %eax
movl $m1, %ebx
movl (%ebx, %eax, 4), %edx
pushl %edx
pushl $formatPrintf
call printf
popl %ebx
popl %ebx
pushl $0
call fflush
popl %ebx
addl $1, index2
jmp for_coloane2
reinit2:
movl $4, %eax
movl $1, %ebx
movl $formatP2, %ecx
movl $2, %edx
int $0x80
addl $1, index
jmp for_linii2
et_exit:
movl $1, %eax
xorl %ebx, %ebx
int $0x80