-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfisier4.asm
More file actions
333 lines (269 loc) · 4.02 KB
/
fisier4.asm
File metadata and controls
333 lines (269 loc) · 4.02 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
.data
v: .space 1650
vrotate: .space 1650
lin: .space 4
col: .space 4
aux: .space 4
str: .space 300
delim: .asciz " "
res: .space 4
index: .space 4
index2: .space 4
indexlin: .space 4
indexcol: .space 4
indexmat: .space 4
x: .space 4
formatPrintf: .asciz "%d "
formatScanf: .asciz "%[^\n]"
NULL: .asciz "\n"
formatPrintf0: .asciz "%s"
.text
.global main
main:
pushl $str
pushl $formatScanf
call scanf
popl %ebx
popl %ebx
pushl $delim
pushl $str
call strtok
popl %ebx
popl %ebx
lea v, %edi
xorl %ecx, %ecx
movl %ecx, index
et_for:
pushl $delim
pushl $0
call strtok
popl %ebx
popl %ebx
cmp $0, %eax
je exit
movl %eax, %esi
xorl %ecx, %ecx
movb (%esi, %ecx, 1), %dl
cmp $48, %dl
je numarzero
movl %eax, res
pushl res
call atoi
popl %ebx
cmp $0, %eax
je op_let
jne numar
numarzero:
movl index, %ecx
movl $0, (%edi, %ecx, 4)
incl %ecx
movl %ecx, index
jmp et_for
numar:
movl lin, %edx
cmp $0, %edx
je linii
movl col, %edx
cmp $0, %edx
je coloane
movl index, %ecx
movl %eax, (%edi, %ecx, 4)
incl %ecx
movl %ecx, index
jmp et_for
linii:
movl %eax, lin
jmp et_for
coloane:
movl %eax, col
jmp et_for
op_let:
pushl $delim
pushl $0
call strtok
popl %ebx
popl %ebx
cmp $0, %eax
je exit
movl %eax, %esi
xorl %ecx, %ecx
movb (%esi, %ecx, 1), %dl
cmp $48, %dl
je numarzero2
movl %eax, res
pushl res
call atoi
popl %ebx
cmp $0, %eax
je operatie
movl %eax, x
jmp op_let
numarzero2:
movl $0, x
jmp op_let
operatie:
movl res, %esi
xorl %ecx, %ecx
movb (%esi, %ecx, 1), %al
cmp $97, %eax
je op_add
cmp $100, %eax
je op_div
cmp $109, %eax
je op_mul
cmp $114, %eax
je op_rot
cmp $115, %eax
je op_sub
xorl %ecx, %ecx
jmp et_for
op_add:
movl x, %ebx
movl (%edi, %ecx, 4), %eax
add %ebx, %eax
movl %eax, (%edi, %ecx, 4)
incl %ecx
cmp index, %ecx
je afisare
jmp op_add
op_div:
xorl %edx, %edx
movl x, %ebx
movl (%edi, %ecx, 4), %eax
cdq
idivl %ebx
movl %eax, (%edi, %ecx, 4)
incl %ecx
cmp index, %ecx
je afisare
jmp op_div
op_mul:
xorl %edx, %edx
movl x, %ebx
movl (%edi, %ecx, 4), %eax
mull %ebx
movl %eax, (%edi, %ecx, 4)
incl %ecx
cmp index, %ecx
je afisare
jmp op_mul
op_sub:
movl x, %ebx
movl (%edi, %ecx, 4), %eax
sub %ebx, %eax
movl %eax, (%edi, %ecx, 4)
incl %ecx
cmp index, %ecx
je afisare
jmp op_sub
op_rot:
movl lin, %eax
movl col, %ebx
movl %ebx, lin
movl %eax, col
lea vrotate, %esi
xorl %ecx, %ecx
xorl %edx, %edx
movl $0, indexlin
movl $0, indexcol
movl $0, indexmat
jmp for_lin
for_lin:
movl indexlin, %ecx
movl indexcol, %eax
xorl %eax, %eax
movl %eax, indexcol
cmp lin, %ecx
je afisarerot
for_col:
movl col, %eax
subl indexcol, %eax
subl $1, %eax
xorl %edx, %edx
mull lin
addl indexlin, %eax
movl (%edi, %eax, 4), %ebx
movl indexmat, %edx
movl %ebx, (%esi, %edx, 4)
incl %edx
movl %edx, indexmat
incl indexcol
movl indexcol, %ecx
cmp col, %ecx
je for_linincl
jmp for_col
for_linincl:
incl indexlin
jmp for_lin
afisare:
movl lin, %eax
movl col, %ebx
mull %ebx
movl %eax, index
xorl %ecx, %ecx
pushl lin
pushl $formatPrintf
call printf
popl %ebx
popl %ebx
pushl col
pushl $formatPrintf
call printf
popl %ebx
popl %ebx
jmp afisare2
afisare2:
movl %ecx, index2
movl (%edi, %ecx, 4), %eax
pushl %eax
pushl $formatPrintf
call printf
popl %ebx
popl %ebx
movl index2, %ecx
incl %ecx
cmp index, %ecx
je exit
jmp afisare2
afisarerot:
movl lin, %eax
movl col, %ebx
mull %ebx
movl %eax, index
xorl %ecx, %ecx
pushl lin
pushl $formatPrintf
call printf
popl %ebx
popl %ebx
pushl col
pushl $formatPrintf
call printf
popl %ebx
popl %ebx
jmp afisarerot2
afisarerot2:
movl %ecx, index2
movl (%esi, %ecx, 4), %eax
pushl %eax
pushl $formatPrintf
call printf
popl %ebx
popl %ebx
movl index2, %ecx
incl %ecx
cmp index, %ecx
je exit
jmp afisarerot2
exit:
pushl $0
call fflush
popl %ebx
pushl $NULL
pushl $formatPrintf0
call printf
popl %ebx
popl %ebx
movl $1, %eax
xorl %ebx, %ebx
int $0x80