-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrixprint.asm
130 lines (130 loc) · 1.54 KB
/
matrixprint.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
section .data
space:db ' '
newline:db 10
section .bss
nod: resb 1
num: resw 1
temp: resb 1
m: resw 1
n: resw 1
i: resw 1
j: resw 1
matrix: resw 1
section .text
global _start
_start:
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
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 eax,0
mov ebx,matrix
mov word[i],0
mov word[j],0
i_loop1:
mov word[j],0
j_loop1:
mov dx,word[ebx+2*eax]
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
pusha
mov eax, 4
mov ebx, 1
mov ecx, newline
mov edx, 1
int 80h
popa
inc word[i]
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