-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_1.Asm
175 lines (138 loc) · 3.25 KB
/
2_1.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
.486
.model flat, stdcall
option casemap :none
include windows.inc ; always first
include masm32.inc
include gdi32.inc
include user32.inc
include kernel32.inc
includelib masm32.lib
includelib gdi32.lib
includelib user32.lib
includelib kernel32.lib
.data
szPrompt db "Enter matrix size: ", 0
szEndLine db 13, 10, 0
szOutput db "Max element in negative columns: ", 0
neg_count db 0
max_elem db -128
szGoodBye db "Press ENTER to continue...", 13, 10, 0
.data?
buf db 100 dup(?)
n db ?
matrix db 10000 dup (?)
neg_columns db 100 dup (?)
.code
MainProc proc
;;;;;;;;;;;;;;;;;;;;;;;;;;; input n
invoke StdOut, addr szPrompt
invoke StdIn, addr buf, 100
invoke atol, addr buf
mov n, al
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;; reading matrix
xor ecx, ecx
_lines_loop:
lea ebx, matrix
mov eax, ecx
mul n
add ebx, eax
call readArray
inc ecx
cmp cl, n
jne _lines_loop
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;; searching negative-only columns
xor ecx, ecx
_columns_loop:
xor edx, edx
_lines_loop2:
lea ebx, matrix ; |
mov eax, edx ; |
mul n ; | ebx = matrix + n*edx + ecx
add eax, ecx ; |
add ebx, eax ; |
xor eax, eax
mov al, byte ptr [ebx]
cmp al, 0
jl _less
jmp _has_positive
_less:
inc edx
cmp dl, n
jne _lines_loop2
lea ebx, neg_columns
add bl, neg_count
mov byte ptr [ebx], cl
inc neg_count
_has_positive:
inc ecx
cmp cl, n
jne _columns_loop
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;; searching max element in negative-only columns
xor ecx, ecx ; ch - col num
; cl - loop var
_columns_loop2:
xor edx, edx
lea ebx, neg_columns ;
add bl, cl ; ch = neg_columns[cl]
mov ch, byte ptr [ebx] ;
_lines_loop3:
lea ebx, matrix ; |
mov eax, edx ; |
mul n ; | ebx = matrix + n*edx + ch
add al, ch ; |
add ebx, eax ; |
xor eax, eax
mov al, byte ptr [ebx]
cmp al, max_elem
jle _not_new_max
mov max_elem, al
_not_new_max:
inc edx
cmp dl, n
jne _lines_loop3
inc cl
cmp cl, neg_count
jne _columns_loop2
;;;;;;;;;;;;;;;;;;;;;;;;;;;
xor eax, eax
mov al, max_elem
neg al
neg eax
invoke ltoa, eax, addr buf
invoke StdOut, addr szOutput
invoke StdOut, addr buf
invoke StdOut, addr szEndLine
invoke StdOut, addr szGoodBye
invoke StdIn, addr buf, 100
invoke ExitProcess, 0
MainProc endp
readArray proc ; reads n bytes separated by ' ' into [ebx]. By Maxim Teryokhin
pushad
invoke StdIn, addr buf, 100
cld
lea edi, buf
lea esi, buf
mov byte ptr [esi+eax-2],' '
xor edx, edx
mov dl, n
_loop:
mov ecx, 100
mov al, ' '
repne scasb
mov byte ptr [edi-1], 0
push edx
Invoke atol, esi
pop edx
mov byte ptr [ebx], al
inc ebx
mov esi, edi
dec edx
cmp edx, 0
jne _loop
popad
ret
readArray endp
end MainProc