
Министерство образования и науки Российской Федерации
Курский Государственный Технический Университет
Кафедра ПО ВТ
ЛАБОРАТОРНАЯ РАБОТА №5
ВВОД/ВЫВОД ДАННЫХ
выполнил: студент гр. ПО-42
Эсауленко Д.В.
проверил: Родионов Д. И.
Курск 2007 Цель лабораторной работы
Изучение возможностей операционной системы для ввода/вывода данных. Изучение работы с функциями прерывания DOS на примере функций прерывания INT 21h.
Задание
Написать процедуры ввода/вывода для 4 лабораторной работы.
Пример выполнения работы
Листинг программы
Turbo Assembler Version 3.1 27/04/07 20:12:07 Page 1
5.asm
1 .286
2
3 0000 .model small
4
5 0000 .stack 512
6
7 0000 .data
8
9 0000 64*(??) s1 db 100 dup(?)
10 0064 08*(??) s db 8 dup (?)
11 006C 0000 lenS dw 0
12 006E 0000 posS dw 0
13 0070 0000 curPos dw 0
14 0072 0000 count dw 0
15 0074 ???? mn dw ?
16 0076 ???? del dw ?
17 0078 ???? num dw ?
18
19 007A 04*(????) mas dw 4 dup(?)
20 0082 04*(????) dw 4 dup(?)
21 008A 04*(????) dw 4 dup(?)
22 0092 04*(????) dw 4 dup(?)
23
24 009A 0004 rowCount dw 4
25 009C 0004 colCount dw 4
26 009E ???? max dw ?
27 00A0 04*(????) maxRow dw 4 dup(?)
28 00A8 04*(????) maxCol dw 4 dup(?)
29 00B0 56 76 65 64 69 74 65+ vvod_mas db 'Vvedite massiv : $'
30 20 6D 61 73 73 69 76+
31 20 3A 20 24
32 00C2 6D 61 78 20 65 6C 65+ vivod_mas1 db 'max elements in rows : $'
33 6D 65 6E 74 73 20 69+
34 6E 20 72 6F 77 73 20+
35 3A 20 24
36 00DA 6D 61 78 20 65 6C 65+ vivod_mas2 db 'max elements in columns : $'
37 6D 65 6E 74 73 20 69+
38 6E 20 63 6F 6C 75 6D+
39 6E 73 20 3A 20 24
40
41 00F5 .code
42 0000 B8 0000s mov AX,@data
43 0003 8E D8 mov DS,AX
44
45 0005 E8 0029 call VVod
46 0008 E8 0124 call RowMax
47
48 000B B4 09 mov AH,9
49 000D BA 00C2r lea DX,vivod_mas1
50 0010 CD 21 int 21h
51
52 0012 BB 00A0r mov BX,offset maxRow
53 0015 E8 0252 call Vivod
54
55 0018 E8 0165 call ColMax
56
57 001B B4 09 mov AH,9
58 001D BA 00DAr lea DX,vivod_mas2
59 0020 CD 21 int 21h
60
61 0022 BB 00A8r mov BX,offset maxCol
62 0025 E8 0242 call Vivod
63
64 0028 B4 01 mov AH,1
65 002A CD 21 int 21h
66
67 002C B8 4C00 mov AX,4c00h
68 002F CD 21 int 21h
69
70 ;***********************************************************************************
71
72 0031 Vvod proc near
73 0031 B4 09 mov AH,9
74 0033 BA 00B0r lea DX,vvod_mas
75 0036 CD 21 int 21h
76
77 0038 B9 0064 mov CX,100
78 003B BA 0000r lea DX,s1
79 003E B4 3F mov AH,3Fh
80 0040 B3 00 mov BL,0
81 0042 CD 21 int 21h
82
83 0044 E8 0092 call SetMas
84 0047 C3 ret
85 0048 Vvod endp
86
87 ;***********************************************************************************
88
89 ; в переменную lenS заносит длину строки, смещение которой в регистре BX
90
91 0048 LengthStr proc near
92 0048 BE 0000 mov SI,0
93 004B C7 06 006Cr 0000 mov lenS,0
94
95 0051 C1:
96 0051 8A 00 mov AL,[BX][SI]
97 0053 3C 0D cmp AL,0Dh
98 0055 74 0A je endC1
99 0057 83 06 006Cr 01 add lenS,1
100 005C 83 C6 01 add SI,1
101 005F EB F0 jmp C1
102
103 0061 endC1:
104 0061 C3 ret
105 0062 LengthStr endp
106
107 ;***********************************************************************************
108
109 ; переводит строку s в число num
110
111 0062 StrToInt proc near
112 0062 C7 06 0078r 0000 mov num,0
113 0068 8B 0E 0072r mov CX,count
114 006C C7 06 0074r 0001 mov mn,1
115 0072 8B F1 mov SI,CX
116 0074 83 EE 01 sub SI,1
117
118 0077 C2:
119 0077 51 push CX
120 0078 B4 00 mov AH,0
121 007A 8A 84 0064r mov AL,s[SI]
122 007E 2C 30 sub AL,30h
123 0080 8B 1E 0074r mov BX,mn
124 0084 F7 E3 mul BX
125 0086 01 06 0078r add num,AX
126 008A B8 000A mov AX,10
127 008D F7 E3 mul BX
128 008F A3 0074r mov mn,AX
129 0092 83 EE 01 sub SI,1
130 0095 59 pop CX
131 0096 E2 DF loop C2
132
133 0098 C3 ret
134 0099 StrToInt endp
135
136 ;***********************************************************************************
137
138 ;заносит в переменную posS смещение первого после curPos пробела, '|' или
139 ;символа окончания строки относительно начала строки
140
141 0099 PosSpace proc near
142 0099 8B 36 0070r mov SI,curPos
143
144 009D C3:
145 009D 8A 84 0000r mov AL,s1[SI]
146 00A1 3C 20 cmp AL,' '
147 00A3 74 0D je endC3
148 00A5 3C 0D cmp AL,0Dh
149 00A7 74 09 je endC3
150 00A9 3C 7C cmp AL,'|'
151 00AB 74 05 je endC3
152 00AD 83 C6 01 add SI,1
153 00B0 EB EB jmp C3
154
155 00B2 endC3:
156 00B2 89 36 006Er mov posS,SI
157 00B6 C3 ret
158 00B7 PosSpace endp
159
160 ;***********************************************************************************
161
162 ; копирует в s из s1 count символов, начиная с curPos
163
164 00B7 CopyStr proc near
165 00B7 BE 0000 mov SI,0
166 00BA 8B 0E 0072r mov CX,count
167 00BE 8B 3E 0070r mov DI,CurPos
168
169 00C2 copy:
170 00C2 51 push CX
171 00C3 8A 85 0000r mov AL,S1[DI]
172 00C7 88 84 0064r mov s[SI],AL
173 00CB 83 C6 01 add SI,1
174 00CE 83 C7 01 add DI,1
175 00D1 59 pop CX
176 00D2 E2 EE loop copy
177
178 00D4 89 3E 0070r mov curPos,DI
179 00D8 C3 ret
180 00D9 CopyStr endp
181
182 ;***********************************************************************************
183
184 ;заполняет массив с клавиатуры
185
186 00D9 SetMas proc near
187 00D9 C7 06 0070r 0000 mov curPos,0
188 00DF BB 0000r mov BX,offset s1
189 00E2 E8 FF63 call LengthStr
190 00E5 BB 0000 mov BX,0
191 00E8 Col:
192 00E8 BE 0000 mov SI,0
193 00EB 8B 0E 009Ar mov CX,rowCount
194 00EF Row:
195 00EF 51 push CX
196 00F0 53 push BX
197 00F1 56 push SI
198 00F2 E8 FFA4 call PosSpace
199 00F5 A1 006Er mov AX,posS
200 00F8 2B 06 0070r sub AX,curPos
201 00FC A3 0072r mov count,AX
202 00FF E8 FFB5 call CopyStr
203 0102 E8 FF5D call StrToInt
204 0105 5E pop SI
205 0106 5B pop BX
206 0107 A1 0078r mov AX,num
207 010A 89 80 007Ar mov mas[BX][SI],AX
208 010E 83 C6 02 add SI,2
209 0111 83 06 0070r 01 add curPos,1
210 0116 59 pop CX
211 0117 E2 D6 loop Row
212
213 0119 A1 009Cr mov AX,colCount
214 011C BA 0002 mov DX,2
215 011F F7 E2 mul DX
216 0121 03 D8 add BX,AX
217 0123 8B 3E 006Er mov DI,posS
218 0127 80 BD 0000r 7C cmp s1[DI],'|'
219 012C 74 BA je Col
220 012E C3 ret
221 012F SetMas endp
222
223 ;***********************************************************************************
224
225 012F RowMax proc near
226 012F BB 0000 mov BX,0
227 0132 BF 0000 mov DI,0
228 0135 B9 0000 mov CX,0
229 0138 met1:
230 0138 3B 0E 009Ar cmp CX,RowCount
231 013C 74 41 je break1
232 013E 51 push CX
233 013F BE 0000 mov SI,0
234 0142 8B 80 007Ar mov AX,mas[BX][SI]
235 0146 A3 009Er mov max,AX
236 0149 8B 0E 009Cr mov CX,ColCount
237 014D met2:
238 014D 51 push CX
239 014E 8B 80 007Ar mov AX,mas[BX][SI]
240 0152 3B 06 009Er cmp AX,max
241 0156 73 02 jae newRowMax
242 0158 72 07 jb next1
243 015A newRowMax:
244 015A 8B 80 007Ar mov AX,mas[BX][SI]
245 015E A3 009Er mov max,AX
246 0161 next1:
247 0161 83 C6 02 add SI,2
248 0164 59 pop CX
249 0165 E2 E6 loop met2
250 0167 A1 009Er mov AX,max
251 016A 89 85 00A0r mov maxRow[DI],AX
252 016E 83 C7 02 add DI,2
253 0171 A1 009Cr mov AX,colCount
254 0174 BA 0002 mov DX,2
255 0177 F7 E2 mul DX
256 0179 03 D8 add BX,AX
257 017B 59 pop CX
258 017C 41 inc CX
259 017D EB B9 jmp met1
260
261 017F break1:
262 017F C3 ret
263 0180 RowMax endp
264
265 ;***********************************************************************************
266
267 0180 ColMax proc near
268 0180 BB 0000 mov BX,0
269 0183 BF 0000 mov DI,0
270 0186 B9 0000 mov CX,0
271 0189 met3:
272 0189 3B 0E 009Cr cmp CX,ColCount
273 018D 74 41 je break2
274 018F 51 push CX
275 0190 BE 0000 mov SI,0
276 0193 8B 80 007Ar mov AX,mas[BX][SI]
277 0197 A3 009Er mov max,AX
278 019A 8B 0E 009Ar mov CX,RowCount
279 019E met4:
280 019E 51 push CX
281 019F 8B 80 007Ar mov AX,mas[BX][SI]
282 01A3 3B 06 009Er cmp AX,max
283 01A7 73 02 jae newCountMax
284 01A9 72 07 jb next2
285 01AB newCountMax:
286 01AB 8B 80 007Ar mov AX,mas[BX][SI]
287 01AF A3 009Er mov max,AX
288 01B2 next2:
289 01B2 A1 009Cr mov AX,colCount
290 01B5 BA 0002 mov DX,2
291 01B8 F7 E2 mul DX
292 01BA 03 F0 add SI,AX
293 01BC 59 pop CX
294 01BD E2 DF loop met4
295 01BF A1 009Er mov AX,max
296 01C2 89 85 00A8r mov maxCol[DI],AX
297 01C6 83 C7 02 add DI,2
298 01C9 83 C3 02 add BX,2
299 01CC 59 pop CX
300 01CD 41 inc CX
301 01CE EB B9 jmp met3
302
303 01D0 break2:
304 01D0 C3 ret
305 01D1 ColMax endp
306
307 ;***********************************************************************************
308
309 01D1 IntToStr proc near
310 01D1 BE 0000 mov SI,0
311 01D4 C7 06 0076r 2710 mov del,10000
312 01DA B9 0005 mov CX,5
313
314 01DD M1:
315 01DD 51 push CX
316 01DE BA 0000 mov DX,0
317 01E1 A1 0078r mov AX,num
318 01E4 8B 1E 0076r mov BX,del
319 01E8 F7 F3 div BX
320 01EA 05 0030 add AX,30h
321 01ED 88 84 0064r mov s[SI],AL
322 01F1 2D 0030 sub AX,30h
323 01F4 F7 26 0076r mul del
324 01F8 29 06 0078r sub num,AX
325 01FC BA 0000 mov DX,0
326 01FF A1 0076r mov AX,del
327 0202 BB 000A mov BX,10
328 0205 F7 F3 div BX
329 0207 A3 0076r mov del,AX
330 020A 83 C6 01 add SI,1
331 020D 59 pop CX
332 020E E2 CD loop M1
333
334 0210 C6 84 0065r 0D mov s[SI+1],0Dh
335 0215 C3 ret
336 0216 IntToStr endp
337
338 ;***********************************************************************************
339
340 0216 NotZero proc near
341 0216 BE 0000 mov SI,0
342 0219 M2:
343 0219 80 BC 0064r 30 cmp s[SI],'0'
344 021E 75 05 jne endM2
345 0220 83 C6 01 add SI,1
346 0223 EB F4 jmp M2
347
348 0225 endM2:
349 0225 89 36 0070r mov curPos,SI
350 0229 C3 ret
351 022A NotZero endp
352
353 ;***********************************************************************************
354
355 022A InsertSubStr proc near
356 022A E8 FFE9 call NotZero
357 022D 8B 36 0070r mov SI,curPos
358 0231 BB 0064r mov BX,offset s
359 0234 56 push SI
360 0235 E8 FE10 call LengthStr
361 0238 83 2E 006Cr 01 sub lens,1
362 023D 5E pop SI
363 023E 29 36 006Cr sub lens,SI
364 0242 8B 0E 006Cr mov CX,lens
365 0246 BB 0000r mov BX,offset s1
366 0249 56 push SI
367 024A E8 FDFB call LengthStr
368 024D 8B 3E 006Cr mov DI,lens
369 0251 5E pop SI
370 0252 insert:
371 0252 51 push CX
372 0253 8A 84 0064r mov AL,S[SI]
373 0257 88 85 0000r mov s1[DI],AL
374 025B 83 C6 01 add SI,1
375 025E 83 C7 01 add DI,1
376 0261 59 pop CX
377 0262 E2 EE loop insert
378
379 0264 C6 85 0001r 0D mov s1[DI+1],0Dh
380 0269 C3 ret
381 026A InsertSubStr endp
382
383 ;***********************************************************************************
384
385 026A Vivod proc near
386 026A C6 06 0000r 0D mov s1[0],0Dh
387 026F 8B 0E 009Cr mov CX,colCount
388 0273 BF 0000 mov DI,0
389 0276 MasV:
390 0276 51 push CX
391 0277 8B 01 mov AX,[BX][DI]
392 0279 A3 0078r mov num,AX
393 027C 57 push DI
394 027D 53 push BX
395 027E E8 FF50 call IntToStr
396 0281 E8 FFA6 call InsertSubStr
397 0284 BB 0000r mov BX,offset s1
398 0287 E8 FDBE call LengthStr
399 028A 8B 36 006Cr mov SI,lenS
400 028E C6 84 FFFFr 20 mov s1[SI-1],' '
401 0293 5B pop BX
402 0294 5F pop DI
403 0295 83 C7 02 add DI,2
404 0298 59 pop CX
405 0299 E2 DB loop MasV
406
407 029B BB 0000r mov BX,offset s1
408 029E E8 FDA7 call LengthStr
409 02A1 8B 36 006Cr mov SI,lenS
410 02A5 C6 84 FFFFr 0D mov s1[SI-1],0Dh
411 02AA C6 84 0000r 0A mov s1[SI],0Ah
412 02AF C6 84 0001r 24 mov s1[SI+1],'$'
413
414 02B4 B4 09 mov AH,9
415 02B6 BA 0000r lea DX,s1
416 02B9 CD 21 int 21h
417 02BB C3 ret
418 02BC Vivod endp
419 ;***********************************************************************************
420
421 end
Turbo Assembler Version 3.1 27/04/07 20:12:07 Page 9
Symbol Table
Symbol Name Type Value
??DATE Text "27/04/07"
??FILENAME Text "5 "
??TIME Text "20:12:07"
??VERSION Number 030A
@32BIT Text 0
@CODE Text _TEXT
@CODESIZE Text 0
@CPU Text 0707H
@CURSEG Text _TEXT
@DATA Text DGROUP
@DATASIZE Text 0
@FILENAME Text 5
@INTERFACE Text 00H
@MODEL Text 2
@STACK Text DGROUP
@WORDSIZE Text 2
BREAK1 Near _TEXT:017F
BREAK2 Near _TEXT:01D0
C1 Near _TEXT:0051
C2 Near _TEXT:0077
C3 Near _TEXT:009D
COL Near _TEXT:00E8
COLCOUNT Word DGROUP:009C
COLMAX Near _TEXT:0180
COPY Near _TEXT:00C2
COPYSTR Near _TEXT:00B7
COUNT Word DGROUP:0072
CURPOS Word DGROUP:0070
DEL Word DGROUP:0076
ENDC1 Near _TEXT:0061
ENDC3 Near _TEXT:00B2
ENDM2 Near _TEXT:0225
INSERT Near _TEXT:0252
INSERTSUBSTR Near _TEXT:022A
INTTOSTR Near _TEXT:01D1
LENGTHSTR Near _TEXT:0048
LENS Word DGROUP:006C
M1 Near _TEXT:01DD
M2 Near _TEXT:0219
MAS Word DGROUP:007A
MASV Near _TEXT:0276
MAX Word DGROUP:009E
MAXCOL Word DGROUP:00A8
MAXROW Word DGROUP:00A0
MET1 Near _TEXT:0138
MET2 Near _TEXT:014D
MET3 Near _TEXT:0189
MET4 Near _TEXT:019E
MN Word DGROUP:0074
NEWCOUNTMAX Near _TEXT:01AB
NEWROWMAX Near _TEXT:015A
NEXT1 Near _TEXT:0161
NEXT2 Near _TEXT:01B2
NOTZERO Near _TEXT:0216
NUM Word DGROUP:0078
POSS Word DGROUP:006E
POSSPACE Near _TEXT:0099
ROW Near _TEXT:00EF
ROWCOUNT Word DGROUP:009A
ROWMAX Near _TEXT:012F
S Byte DGROUP:0064
S1 Byte DGROUP:0000
SETMAS Near _TEXT:00D9
STRTOINT Near _TEXT:0062
VIVOD Near _TEXT:026A
VIVOD_MAS1 Byte DGROUP:00C2
VIVOD_MAS2 Byte DGROUP:00DA
VVOD Near _TEXT:0031
VVOD_MAS Byte DGROUP:00B0
Groups & Segments Bit Size Align Combine Class
DGROUP Group
STACK 16 0200 Para Stack STACK
_DATA 16 00F5 Word Public DATA
_TEXT 16 02BC Word Public CODE