-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix1.s
90 lines (67 loc) · 1.43 KB
/
matrix1.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
// Matrice problema 1 - Afisarea unei matrice;
.data
lines: .long 3
columns: .long 4
lineIndex: .space 4
columnIndex: .space 4
matrix: .long 10, 20, 30, 40
.long 50, 60, 70, 80
.long 90, 100, 110, 120
formatInt: .asciz "%d "
newLine: .asciz "\n"
.text
.globl main
main:
lea matrix, %edi
movl $0, lineIndex
for_lines:
movl lineIndex, %ecx
cmp %ecx, lines
je etexit
// incepe al doilea for
movl $0, columnIndex
for_columns:
movl columnIndex, %ecx
cmp %ecx, columns
je cont_for_lines
// prelucrare
// elementul curent este la: lineIndex * columns + columnIndex
// relativ la adresa de inceput a matricei, adk relativ la %edi;
// toate elementele sunt de tip .long = 4 bytes;
movl lineIndex, %eax
mull columns
// %eax = %eax * columns
addl columnIndex, %eax
movl (%edi, %eax, 4), %ebx
// %ebx este elem. curetn din matrice de la pozitia (lineIndex, columnIndex)
// vreau sa afisez %ebx
Afisare:
pusha
push %ebx
push $formatInt
call printf
pop %ebx
pop %ebx
pushl $0
call fflush
pop %ebx
popa
Next:
addl $1, columnIndex
jmp for_columns
cont_for_lines:
push $newLine
call printf
pop %ebx
pushl $0
call fflush
pop %ebx
addl $1, lineIndex
jmp for_lines
etexit:
mov $1, %eax
xor %ebx, %ebx
int $0x80
// for(int lineIndex = 0; lineIndex < lines; lineIndex++)
// for(int columnIndex = 0; columnIndex < columns; columnIndex++)
// ...