-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.asm
280 lines (229 loc) · 3.83 KB
/
test.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
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
include "emu8086.inc"
.model small
.stack
.data
a dw 30, 60, 20, 50, 25
n dw 5
bs dw ?
max dw ?
.code
main proc
mov ax, @data
mov ds, ax
push n
mov ax, offset a
push ax
call sapxep
push n
mov ax, offset a
push ax
call xuatmang
;call bscnnmang
;call xuatmang
;call tinhtong
;call demchan
;mov bs, ax
;mov ax, bs
;call timmax
;mov max, ax
;call print_num_uns
mov ah, 4ch
int 21h
main endp
sapxep proc
push bp
mov bp, sp
push bx
push cx
push dx
mov cx, [bp+6]
dec cx
mov dx, cx
for6:
or dx, dx
jz endfor6
mov cx, dx
mov bx, [bp+4]
for5:
mov ax, [bx]
cmp ax, [bx+2]
jbe kodoicho
xchg ax, [bx+2]
xchg ax, [bx]
kodoicho:
add bx, 2
loop for5
dec dx
jmp for6
endfor6:
pop dx
pop cx
pop bx
pop bp
ret 4
sapxep endp
demchan proc
push bp
mov bp, sp
push bx
push cx
xor cx, cx
xor ax ,ax
for4:
cmp cx, [bp+6]
jae endfor4
test word ptr [bx],1
jnz sole4
inc ax
sole4:
inc cx
add bx, 2
jmp for4
endfor4:
pop cx
pop bx
pop bp
ret 4
demchan endp
tinhtong proc
push bp
mov bp, sp
push bx
push cx
xor cx, cx
xor ax, ax
for3:
cmp cx, [bp+6]
jae endfor3
add ax, [bx]
inc cx
add bx, 2
jmp for3
endfor3:
pop cx
pop bx
pop bp
ret 4
tinhtong endp
timmax proc
push bp
mov bp, sp
push bx
push cx
mov cx, 1
mov bx, [bp+4]
mov ax, [bx]
add bx, 2
for2:
cmp cx, [bp+6]
jae endfor2
cmp ax, [bx]
jae ifsai2
mov ax, [bx]
ifsai2:
inc cx
add bx, 2
jmp for2
endfor2:
pop cx
pop bx
pop bp
ret 4
timmax endp
xuatmang proc
push bp
mov bp, sp
push bx
push cx
push dx
xor cx, cx
mov bx, [bp + 4]
for1:
cmp cx, [bp + 6]
jae endfor1
mov ax, [bx]
call print_num_uns
mov ah, 2
mov dl, ' '
int 21h
inc cx
add bx, 2
jmp for1:
endfor1:
pop dx
pop cx
pop bx
pop bp
ret 4
xuatmang endp
bscnnmang proc
push bp
mov bp, sp
push bx
push cx
mov cx, 1
mov bx, [bp + 4]
mov ax, [bx]
add bx, 2
for:
cmp cx, [bp+6]
jae endfor
push ax
push [bx]
call bscnn
inc cx
add bx, 2
jmp for
endfor:
;bs = a[0] ; for(int i =1; i < n; i++) bs = bsnnn(bs, a[i])
pop cx
pop bx
pop bp
ret 4
bscnnmang endp
bscnn proc
push bp
mov bp, sp ; bs = a*b/us
push bx
push dx
push [bp+6]
push [bp+4]
call uscln
mov bx, ax
mov ax, [bp+4]
mul word ptr [bp+6]
div bx
pop dx
pop bx
pop bp
ret 4
bscnn endp
uscln proc
push sp
mov bp, sp
push bx
mov ax, [bp+4]
mov bx, [bp+6]
while:
cmp ax, bx
je endw
cmp ax, bx
jbe ifsai
sub ax, bx
jmp endif
ifsai:
sub bx, ax
endif:
jmp while
endw:
pop bx
pop sp
ret 4
uscln endp
define_print_num_uns
end
; while(a != b>
; if(a > b)
; a -=b
; else
; b -=a;