-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path1B_CALLS.A
2688 lines (1506 loc) · 45.1 KB
/
1B_CALLS.A
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
_ _ | | _ _
_ ______________
Terminate Program (Function 00H)
Call:
AH = 00H
CS
Segment address of
Program Segment Prefix
Return:
None
Comments:
Function 00H performs the same function as Interrupt 20H. It terminates
the current process and returns control to its parent process. It also closes
all open file handles and clears the disk cache. When this interrupt is
issued, CS must contain the segment address of the Program Segment
Prefix.
The CS register must contain the segment address of the Program Seg-
ment Prefix before you call this interrupt.
The following exit addresses are restored from the specified offsets in the
Program Segment Prefix:
Offset
Exit Address
_ ________________________________________________________________
0AH Program terminate
0EH CONTROL-C
12H Critical error
All file buffers are flushed to disk.
1
_ _ | | _ _
_ _ | | _ _
_ ______________
_ ________________________________________________________________
Warning
Close all files that have changed in length before calling this function.
If you do not close a changed file, its length is not correctly recorded in
the directory. See Function 10H for a description of the Close File sys-
tem call.
_ ________________________________________________________________
Macro Definition:
terminate_program macro
xor ah,ah
int 21H
endm
Example:
The following program displays a message and returns to MS-DOS. It uses
only the opening portion of the sample program skeleton shown in Figure
1.2.
message db "Displayed by FUNC00H example", 0DH,0AH,"$"
;
begin: display message ;see Function 09H
terminate_program ;THIS FUNCTION
code ends
end start
2
_ _ | | _ _
_ _ | | _ _
_ ______________
Read Keyboard and Echo (Function 01H)
Call:
AH = 01H
Return:
AL
Character typed
Comments:
Function 01H waits for a character to be read from standard input, then
echoes the character to standard output and returns it in AL. If the char-
acter is CONTROL-C, it executes Interrupt 23H.
Macro Definition:
read_kbd_and_echo macro
mov ah, 01H
int 21H
endm
Example:
The following program displays and prints characters as you type them. If
you press the RETURN key, the program sends a linefeed/carriage-return
sequence to both the display and the printer.
begin: read_kbd_and_echo ;THIS FUNCTION
print_char al ;see Function 05H
cmp al,0DH ;is it a CR?
jne begin ;no, print it
print_char 0AH ;see Function 05H
display_char 0AH ;see Function 02H
3
_ _ | | _ _
_ _ | | _ _
_ ______________
jmp begin ;get another character
4
_ _ | | _ _
_ _ | | _ _
_ ______________
Display Character (Function 02H)
Call:
AH = 02H
DL
Character to be displayed
Return:
None
Comments:
Function 02H sends the character in DL to standard output. If you press
CONTROL-C, it issues Interrupt 23H.
Macro Definition:
display_char macro character
mov dl,character
mov ah,02H
int 21H
endm
Example:
The following program converts lowercase characters to uppercase before
displaying them.
begin: read_kbd ;see Function 08H
cmp al,"a"
jl uppercase ;don't convert
cmp al,"z"
jg uppercase ;don't convert
sub al,20H ;convert to ASCII code
;for uppercase
5
_ _ | | _ _
_ _ | | _ _
_ ______________
uppercase: display_char al ;THIS FUNCTION
jmp begin: ;get another character
6
_ _ | | _ _
_ _ | | _ _
_ ______________
Auxiliary Input (Function 03H)
Call:
AH = 03H
Return:
AL
Character from auxiliary device
Comments:
Function 03H waits for a character from standard auxiliary devices (AUX,
COM1, COM2, COM3, COM4), then returns the character in AL. This
system call does not return a status or error code.
If you press CONTROL-C, it issues Interrupt 23H.
Macro Definition:
aux_input macro
mov ah,03H
int 21H
endm
Example:
The following program prints characters as soon as it receives them from
the auxiliary device. It stops printing when it receives an end-of-file char-
acter (ASCII 26, or CONTROL-Z).
begin: aux_input ;THIS FUNCTION
cmp al,1AH ;end of file?
je return ;yes, all done
print_char al ;see Function 05H
7
_ _ | | _ _
_ _ | | _ _
_ ______________
jmp begin ;get another character
8
_ _ | | _ _
_ _ | | _ _
_ ______________
Auxiliary Output (Function 04H)
Call:
AH = 04H
DL
Character for auxiliary device
Return:
None
Comments:
Function 04H sends the character in DL to standard auxiliary. This sys-
tem call does not return a status or error code.
If you press CONTROL-C, it issues Interrupt 23H.
Macro Definition:
aux_output macro character
mov dl,character
mov ah,04H
int 21H
endm
Example:
The following program gets a series of strings of up to 80 bytes from the
keyboard and sends each string to the auxiliary device. It stops when you
type a null string (carriage-return only).
string db 81 dup(?) ;see Function 0AH
;
begin: get_string 80,string ;see Function 0AH
cmp string[1],0 ;null string?
9
_ _ | | _ _
_ _ | | _ _
_ ______________
je return ;yes, all done
mov cx, word ptr string[1] ;get string length
mov bx,0 ;set index to 0
send_it: aux_output string[bx+2] ;THIS FUNCTION
inc bx ;bump index
loop send_it ;send another character
jmp begin ;get another string
10
_ _ | | _ _
_ _ | | _ _
_ ______________
Print Character (Function 05H)
Call:
AH = 05H
DL
Character for printer
Return:
None
Comments:
Function 05H sends the character in DL to the standard printer. If you
press CONTROL-C, it issues Interrupt 23H. This function does not return a
status or error code.
Macro Definition:
print_char macro character
mov dl,character
mov ah,05H
int 21H
endm
Example:
The following program prints a walking test pattern on the printer. It
stops if you press CONTROL-C.
line_num db 0
;
begin: mov cx,60 ;print 60 lines
start_line: mov bl,33 ;first printable ASCII
;character (!)
add bl,line_num ;to offset one character
11
_ _ | | _ _
_ _ | | _ _
_ ______________
push cx ;save number-of-lines counter
mov cx,80 ;loop counter for line
print_it: print_char bl ;THIS FUNCTION
inc bl ;move to next ASCII character
cmp bl,126 ;last printable ASCII
;character (~)
jl no_reset ;not there yet
mov bl,33 ;start over with (!)
no_reset: loop print_it ;print another character
print_char 0DH ;carriage return
print_char 0AH ;linefeed
inc line_num ;to offset 1st char. of line
pop cx ;restore #-of-lines counter
loop start_line ;print another line
12
_ _ | | _ _
_ _ | | _ _
_ ______________
Direct Console I/O (Function 06H)
Call:
AH = 06H
DL
See text
Return:
AL
If DL = FFH before call,
then zero flag not set means AL
has character from standard input.
Zero flag set means there was not
a character to get, and AL = 0.
Comments:
The action of Function 06H depends on the value in DL when the function
is called:
Value in DL
Action
_ ________________________________________________________________
FFH If a character has been read from standard input, it is
returned in AL and the zero flag is cleared (0); if a
character has not been read, the zero flag is set (1).
Not FFH The character in DL is sent to standard output.
This function does not check for CONTROL-C.
Macro Definition:
dir_console_io macro switch
mov dl,switch
mov ah,06H
int 21H
endm
13
_ _ | | _ _
_ _ | | _ _
_ ______________
Example:
The following program sets the system clock to 0 and displays the time
continuously. When you type any character, the display freezes; when you
type any character again, the clock is reset to 0 and the display starts
again.
time db "00:00:00.00",0DH,0AH,"$" ;see Function 09H
; ;for explanation of $
;
begin: set_time 0,0,0,0 ;see Function 2DH
read_clock: get_time ;see Function 2CH
CONVERT ch,time ;see end of chapter
CONVERT cl,time[3] ;see end of chapter
CONVERT dh,time[6] ;see end of chapter
CONVERT dl,time[9] ;see end of chapter
display time ;see Function 09H
dir_console_io FFH ;THIS FUNCTION
cmp al,0 ;character typed?
jne stop ;yes, stop timer
jmp read_clock ;no, keep timer
;running
stop: read_kbd ;see Function 08H
jmp begin ;start over
14
_ _ | | _ _
_ _ | | _ _
_ ______________
Direct Console Input (Function 07H)
Call:
AH = 07H
Return:
AL
Character from keyboard
Comments:
Function 07H waits for a character to be read from standard input, then
returns it in AL. This function does not echo the character or check for
CONTROL-C. (For a keyboard input function that echoes or checks for
CONTROL-C, see Function 01H or 08H.)
Macro Definition:
dir_console_input macro
mov ah,07H
int 21H
endm
Example:
The following program prompts for a password (eight characters max-
imum) and places the characters into a string without echoing them.
password db 8 dup(?)
prompt db "Password: $" ;see Function 09H for
;explanation of $
begin: display prompt ;see Function 09H
mov cx,8 ;maximum length of password
xor bx,bx ;so BL can be used as index
15
_ _ | | _ _
_ _ | | _ _
_ ______________
get_pass: dir_console_input ;THIS FUNCTION
cmp al,0DH ;was it a carriage return?
je return ;yes, all done
mov password[bx],al ;no, put character in string
inc bx ;bump index
loop get_pass ;get another character
16
_ _ | | _ _
_ _ | | _ _
_ ______________
Read Keyboard (Function 08H)
Call:
AH = 08H
Return:
AL
Character from keyboard
Comments:
Function 08H waits for a character to be read from standard input, then
returns it in AL. If you press CONTROL-C, it issues Interrupt 23H. This
function does not echo the character. (For a keyboard input function that
echoes the character or checks for CONTROL-C, see Function 01H.)
Macro Definition:
read_kbd macro
mov ah,08H
int 21H
endm
Example:
The following program prompts for a password (eight characters max-
imum) and places the characters into a string without echoing them.
password db 8 dup(?)
prompt db "Password: $" ;see Function 09H
;for explanation of $
begin: display prompt ;see Function 09H
mov cx,8 ;maximum length of password
xor bx,bx ;BL can be an index
17
_ _ | | _ _
_ _ | | _ _
_ ______________
get_pass: read_kbd ;THIS FUNCTION
cmp al,0DH ;was it a carriage return?
je return ;yes, all done
mov password[bx],al ;no, put char. in string
inc bx ;bump index
loop get_pass ;get another character
18
_ _ | | _ _
_ _ | | _ _
_ ______________
Display String (Function 09H)
Call:
AH = 09H
DS:DX
Pointer to string to be displayed
Return:
None
Comments:
Function 09H sends to standard output a string that ends with "$" (the $
is not displayed).
The DX register must contain the offset (from the segment address in DS)
of the string.
Macro Definition:
display macro string
mov dx,offset string
mov ah,09H
int 21H
endm
Example:
The following program displays the hexadecimal code of the key that is
typed.
table db "0123456789ABCDEF"
result db " - 00H",0DH,0AH,"$" ;see text for
;explanation of $
begin: read_kbd_and_echo ;see Function 01H
19
_ _ | | _ _
_ _ | | _ _
_ ______________
xor ah,ah ;clear upper byte
convert ax,16,result[3] ;see end of chapter
display result ;THIS FUNCTION
jmp begin ;do it again
20
_ _ | | _ _
_ _ | | _ _
_ ______________
Buffered Keyboard Input (Function 0AH)
Call:
AH = 0AH
DS:DX
Pointer to input buffer
Return:
None
Comments:
Function 0AH gets a string from standard input. DX must contain the
offset (from the segment address in DS) of an input buffer of the following
form:
Byte
Contents
_ ________________________________________________________________
1 Maximum number of characters in buffer, including the carriage
return (you must set this value).
2 Actual number of characters typed, not counting the carriage
return (the function sets this value).
3-n Buffer; must be at least as long as the number in byte 1.
Characters are read from standard input and placed in the buffer begin-
ning at the third byte until a RETURN character (ASCII 0DH) is read. If the
buffer fills to one less than the maximum, additional characters read are
ignored and ASCII 07H (Bel) is sent to standard output until a RETURN
character is read. If you type the string at the console, it can be edited as
it is being entered. If you press CONTROL-C, it issues Interrupt 23H.
MS-DOS sets the second byte of the buffer to the number of characters
read (not counting the carriage return).
21
_ _ | | _ _
_ _ | | _ _
_ ______________
Macro Definition:
get_string macro limit,string
mov dx,offset string
mov string,limit
mov ah,0AH
int 21H
endm
Example:
The following program gets a 16-byte (maximum) string from the key-
board and fills a 24-line by 80-character screen with it.
buffer label byte
max_length db ? ;maximum length
chars_entered db ? ;number of chars.
string db 17 dup (?) ;16 chars + CR
strings_per_line dw 0 ;how many strings
;fit on line
crlf db 0DH,0AH
;
begin: get_string 17,buffer ;THIS FUNCTION
xor bx,bx ;so byte can be
;used as index
mov bl,chars_entered ;get string length
mov buffer[bx+2],"$" ;see Function 09H
mov al,50H ;columns per line
cbw
div chars_entered ;times string fits
;on line
xor ah,ah ;clear remainder
mov strings_per_line,ax ;save col. counter
mov cx,24 ;row counter
display_screen: push cx ;save it
mov cx,strings_per_line ;get col. counter
display_line: display string ;see Function 09H
loop display_line
display crlf ;see Function 09H
pop cx ;get line counter
loop display_screen ;display 1 more line
22
_ _ | | _ _
_ _ | | _ _
_ ______________
Check Keyboard Status (Function 0BH)
Call:
AH = 0BH
Return:
AL
00H = no characters in type-ahead buffer
FFH = characters in type-ahead buffer
Comments:
Function 0BH checks whether characters are available from standard
input (if standard input has not been redirected, it checks the type-ahead
buffer). If characters are available, AL returns FFH; if not, AL returns 0.
If CONTROL-C is in the buffer, it issues Interrupt 23H.
Macro Definition:
check_kbd_status macro
mov ah,0BH
int 21H
endm
Example:
The following program displays the time continuously until you press any
key:
time db "00:00:00.00",0DH,0AH,"$"
.
.
begin: get_time ;see Function 2CH
byte_to_dec ch,time ;see end of chapter
byte_to_dec cl,time[3] ;see end of chapter
23
_ _ | | _ _
_ _ | | _ _
_ ______________