-
Notifications
You must be signed in to change notification settings - Fork 0
/
printzmatrix.asm
227 lines (227 loc) · 2.67 KB
/
printzmatrix.asm
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
section .data
space:db ' '
newline:db 10
section .bss
nod: resb 1
counter: resw 1
counter1: resd 1
counter2: resb 1
num: resw 1
temp: resb 1
m: resw 1
n: resw 1
i: resw 1
j: resw 1
matrix: resw 100
section .text
global _start
_start:
mov word[counter],0
mov ecx,0
call read_num
mov cx,word[num]
mov word[m],cx
mov ecx,0
call read_num
mov cx,word[num]
mov word[n],cx
movzx eax,cx
mov dword[counter1],eax
mov eax,0
mov ebx,matrix
mov word[i],0
mov word[j],0
i_loop:
mov word[j],0
j_loop:
call read_num
mov dx,word[num]
mov word[ebx+2*eax],dx
inc eax
inc word[j]
mov cx,word[n]
cmp word[j],cx
jb j_loop
inc word[i]
mov cx,word[m]
cmp word[i],cx
jb i_loop
mov ebx,matrix
mov word[i],0
mov word[j],0
mov eax,0
jmp j_loop1
i_loop1:
mov edx,dword[counter1]
add eax,edx
mov word[j],0
pusha
mov ax,word[i]
mov bl,2
div bl
mov byte[counter2],ah
popa
cmp byte[counter2],0
jne j_loop2
jmp j_loop1
j_loop1:
mov ebx,matrix
mov dx,word[ebx+2*eax]
cmp dx,0
je print1
mov word[num],dx
call print_num
pusha
mov eax, 4
mov ebx, 1
mov ecx, space
mov edx, 1
int 80h
popa
inc eax
inc word[j]
mov cx,word[n]
cmp word[j],cx
jb j_loop1
inc word[i]
dec eax
mov cx,word[m]
cmp word[i],cx
jb i_loop1
mov eax,1
mov ebx,0
int 80h
j_loop2:
mov ebx,matrix
mov dx,word[ebx+2*eax]
mov word[num],dx
cmp word[num],0
je print2
call print_num
pusha
mov eax, 4
mov ebx, 1
mov ecx, space
mov edx, 1
int 80h
popa
dec eax
inc word[j]
mov cx,word[n]
cmp word[j],cx
jb j_loop2
inc word[i]
inc eax
mov cx,word[m]
cmp word[i],cx
jb i_loop1
mov eax,1
mov ebx,0
int 80h
read_num:
pusha
mov word[num], 0
loop_read:
mov eax, 3
mov ebx, 0
mov ecx, temp
mov edx, 1
int 80h
cmp byte[temp], 10
je end_read
mov ax, word[num]
mov bx, 10
mul bx
mov bl, byte[temp]
sub bl, 30h
mov bh, 0
add ax, bx
mov word[num], ax
jmp loop_read
end_read:
popa
ret
print_num:
pusha
extract_no:
cmp word[num], 0
je print_no
inc byte[nod]
mov dx, 0
mov ax, word[num]
mov bx, 10
div bx
push dx
mov word[num], ax
jmp extract_no
print_no:
cmp byte[nod], 0
je end_print
dec byte[nod]
pop dx
mov byte[temp], dl
add byte[temp], 30h
mov eax, 4
mov ebx, 1
mov ecx, temp
mov edx, 1
int 80h
jmp print_no
end_print:
popa
ret
print1:
mov word[num],0
add word[num],30h
pusha
mov eax,4
mov ebx,1
mov ecx,num
mov edx,1
int 80h
mov eax, 4
mov ebx, 1
mov ecx, space
mov edx, 1
int 80h
popa
inc eax
inc word[j]
mov cx,word[n]
cmp word[j],cx
jb j_loop1
inc word[i]
dec eax
mov cx,word[m]
cmp word[i],cx
jb i_loop1
mov eax,1
mov ebx,0
int 80h
print2:
add word[num],30h
pusha
mov eax,4
mov ebx,1
mov ecx,num
mov edx,1
int 80h
mov eax, 4
mov ebx, 1
mov ecx, space
mov edx, 1
int 80h
popa
dec eax
inc word[j]
mov cx,word[n]
cmp word[j],cx
jb j_loop2
inc word[i]
inc eax
mov cx,word[m]
cmp word[i],cx
jb i_loop1
mov eax,1
mov ebx,0
int 80h