You are on page 1of 846

..

ASSEMBLER

..
2001

004.438 ASSEMBLER
32.973.26-018.1

..
ASSEMBLER. .
- .: .., , 2001. - 848 ., .

..
03567 19 2000 .


064480 04 1996 .
ISBN 5-89251-101-4

.., 2001.
.., 2001.
, 2001.

...5

9
1.
12
2. ,
19
3.
29
4. 8088/8086
41
5.
57
6.
74
7. , ,
85
8. MS DOS
103
9.
120
10.
153
11.
181
12. TSR- ()
197
13.
226
14.
239
15.
259
16.
281
17. ""
294
18.
..;
..;....
321
19.
343
20. 8086,80186,80286,80386,80486, Pentium...
359
21.
384
22.0 , MS DOS
475
23.
492
24. WINDOWS
511
25.32- WINDOWS.
( WINDOWS 95-98.)
549
26.
570
27. VGA SVGA-
639
1.
.,.
.671
2.
,.,,,.......................................... 682
3.
..,......,)....,.., 683

ASSEMBLER.

4.0 DEBUG
5.
6.
( BIOS DOS)
7. MS DOS
8. BIOS
9. -

690
692
695
702
720
793
843
845

.
1. .
. .
2. .
IBM PC, MS DOS.
.
3. .
- , .
4. 8088/8086.
8088/8086,
.
5. .

.
6. .

DOS, BIOS .
7. , , .
.
8. .
MS DOS .
, -,
.
9. .
:
, , .
10. .
VGA .
11. .
: MS DOS , , .
12.8-.
: ,
, .
13. .
, ,
.

ASSEMBLER.

14. .
: , FAT-,
, - MS DOS Windows ..
15. .
(, , Basic)
. .
16. .
MS DOS.
17. "" .
""
.
18. .
.
19. .
, , .
20. 8088/8086... 80486...
Intel,
. .
21. .
, . Novel NetWare. IPX, SPX.
22. , MS DOS
.

MS DOS (, , ).
23. .
.
24. WINDOWS.
WINDOWS 16- .
25.32- Windows.
Windows 95,98. , .
26. .
,
.
27. VGA .
VGA-, . SVGA, VESA .

.

:
,

.
..
.
.
..
.
.
IBM PC.
.
. :
1. , .
2. . .
3. .
, ,
. ,
( ) . , . " ", -
. " ?" - - " ,
. ?".
:
- . ( 180)
, (!) . . , ,
.
" " - , . , . - ,
.
. ,
- - -
.
,
? - .
: ", , -

ASSEMBLER.

, , ". ,
, , , .. , ,
:
, . :
- . , Intel .
- OS/2, Windows, Unix MS DOS,
, .
- .
. ,
. , . , ,
.
MS DOS. . , Windows. , , Windows. . , .
. . .
, .
., ., ., ., ., ., .
. ,
.

.
, ,
.
.. .

.


. ?
1. (, , ). , . -
, , .
2. ,
.
.
, .
BASIC ( ,
DOS'OBCKOM ).
3. MS DOS Windows , .. .
,
, -
.
27 9 . , -, , -, , -
. , .
, . . 10, lOh- . , , , , VGA,
, , VGA SVGA- . 5. 80286.
, .
, Intel. ,
, 80386,80486, Pentium.
, .
. -

10

ASSEMBLER.

, , . , .
, ,
, .
: ,
. , , , ,
. - , . , .
, , .
, .
, .
, , , . ,
.

.
"", ""
"", "". , "" " ".

.
MASM.EXE 5.0 ( ) 1
LINK.EXE ( 4.0). EXE2BIN.EXE ,
LINK, , , .. LINK.EXE
. ,
(MASM 6.0, LINK 5.0), .
TASM.EXE TLINK.EXE (TASM32.EXE, TLINK32.EXE),
.

EXE2BIN.EXE, .

1.
.
.
.
( ), . ,
, , .
, , , MOV ( MOVE - ), ADD () .., .
. , .. ,
.
, .
. , , . , .. ,
, , , , . ,
: .
, ASM. : MASM.EXE
- ,
(PRIMER. ASM -> PRIMER.OBJ), LINK.EXE - ( )2, ,
, ,
, - , EXE2BIN.EXE -
- -3 , LINK.EXE, DEBUG.EXE
- - .
LINK "". " "
LINK.EXE . "" "" .
DOS 6.00 EXE2BIN.EXE . LINK.EXE
/TINY ( /), - . , TLINK.EXE
- /. .., - P.OBJ,
: LINK P/TINY; LINK P/T;. , , EXE2BIN, , 2.

1.

13

-
, , DISKEDIT.EXE Norton Utilites.
MASM.EXE LINK.EXE Microsoft
- TASM.EXE -
TLINK.EXE Borland.
MicroSoft ,
, - - 4,
.
, . , . . , .

TITLE PRIMER11
;--
CODSEG SEGMENT
ASSUME CS:CODSEG, DS:CODSEG, SS:CODSEG, ES:CODSEG
ORG 100H
BEGIN:

;
JMP BEG_CODE
;
;
TEXT
DB ' . $'
; $ -
BEG_CODE:
/
;
;-, -
MOV AX,CS
; CS
MOV DS,AX
; DS
;-- -LEA DX,TEXT
;
MOV , 9
; DOS
INT 21H '
.;
;,
MOV ,4
; DOS
INT 21H
;
CODSEG ENDS
/
END BEGIN
;
. 1.1. .
, -, -
. MASM - Ideal, MASM . - ASM.

14

ASSEMBLER.

. , , , ';' . , .
PRIMER 11 .ASM.
MASM.EXE. Source filename
[.ASM]:, , .. PRIMER 11 (
) ENTER. -
ENTER .
,
PRIMER 11 .OBJ. ( ). . LINK.EXE. : Object
Modules [.OBJ]:. , .. PRIMER11
ENTER. , MASM,
ENTER.
PRIMER 11 .EXE - -. , :
" ". .
,
MASM.EXE LINK.EXE. MASM
PRIMER 11;, (" "
). : LINKPRTMER11;.
, .
, , MS DOS,
, (-). , , , -
:
1. - 64 , - .
2. - , -
(, ).
3. , , ,
.. ,
.
.. , -. ,
- .
- -.
PRIMER11 . .
EXE2Bm.EXE.Ha6epeMOTeflyraiuyraCTpOKy:EXE2BrNPRIMERll.EXEPRIMERll.COM.
PRIMER 11 .COM. , , PRIMER 11 .. , . - . LINK.EXE 5.0 1>1, 21 . - tlNK PRIMER 11 /; - ( ), ,
, , - ( -

1.

15

), .
, .
- . , MS
DOS, - (, 1.2.).
@

OFF

:2
WD %1.ASM
ECHO
MASM %1;

IF ERRORLEVEL 1 GOTO I
ECHO
LINK %1.0BJ;
IF ERRORLEVEL I GOTO 3
ECHO
PAUSE
6ECHO ON
%1
@ECHO OFF
ECHO ,
PAUSE
GOTO 2

:1
ECHO
PAUSE
ECHO
ECHO
MASM %!,,;
WD %1.LST
PAUSE
GOTO 2
:3

ECHO
PAUSE
GOTO 2
:END
. 1.2. .
GO.BAT, ,
PRIMER! I .ASM, GO PRIMER11
ENTER. , .. CTRL-C. . MASM , , , -

16

ASSEMBLER.

, (.CRF). . , MASM PRIMER 11 , 1 ,1 ,PRI , , PRIMER 11 .ASM, 1 .OBJ - , PI .LST -


, PRI.CRF - . , ,
, , .
,
, . ,
-.

'

"

~~

~*

TITLE PRIMER13
;
DATSEG
SEGMENT
1 DB ', !',10,13, '$'
DATSEG ENDS
/
STSEG
SEGMENT STACK
DB 60 DUP(?)
STSEG
ENDS
;
CODSEG
SEGMENT
ASSUME CS:CODSEG, DS:DATSEG, SS:STSEG, ES:CODSEG
BEGIN:
/ ,
;.. STSEG
; STACK
MOV AX,STSEG
;SS '
MOV SS,AX
MOV AX,DATSEG
;DS
;
MOV DS,AX
/ (. . 1.1.)
LEA DX,TEXT1
MOV ,9
INT 21H
; DOS
MOV AH,4CH
INT
21H
';
. . - ' . . .
CODSEG
ENDS
END BEGIN
'
'
' ' : / " '
Puc. 1.3. , .

17

.
: , , . ,
, , , . : , , . , ,
LINK.EXE. , - . ,
, , .

. : () ? . . , ( ) , . , 5. , , , , -, . , ,
, , , .
, , , , , .., , , (. 15). . 1.4.
, .
6.
, , (). - .
,
, .
.
.
.
. . ( Windows, , ) .
.
, .
()
INCLUDE.

- .

18

ASSEMBLER.

( -

. .-/. , .
,{

: , .
, , , "". .., ,
- , .
" ". . ,
. , , , . , , (,
). : , , . , , . .
.
IpszClassName Name. ,
: " , - ". , . , . , .

2. ,
.
, - , ,
.
.. .
.
, .
.
, .
.
. , .
. , , . , ,
. ,
, . "
!" - " " .
. - . .
. - ( 0 ). .
IBM PC .
,
( , 8086, ) - FFFFH ( !).
(. ). , .
() SA:OA,
SA - , - .
: SA* 16+OA.
16 . 20- .
(sic!). 64 Kb.
. , -

20

ASSEMBLER.

. , , , , . , FF3AH:2367H FF38H:2387H . , - , . 80386,32-


.
- . .
, , . : DB - , DW -
( ), DD - ( ), DQ - , DT - . :
DB 78H

; ,
; 78jH
DW 1234H ; ,
;
/ 34, 12 (!)
DQ 02f503 ; ,
;
;:
;3,F5h,2,0 ( !)
DB 12,34 / : 12,
; 34
, , ASCII . :
DB '

/ ,
; , ;ASCII
;. .1.1.

.
, : LAB DW 7589.
MOV AL,BYTE PTR LAB AL 7
89. , , LAB, , .
7

;
, - . ,
, . ^ - . :
, .-

2. ,

21


- . LAB (BYTE PTR) ,
. , MOV AL,BYTE PTR LAB+1. ^
, , DX, MOV DX,LAB.
, DUP.
, .
-.
- .
. - . . . MOV ,[] , .
MOV BX,OFFSET LAB LEA BX,LAB. R
, , MOV ,[]+2 MOV
,[]2. .
.
.
DI SI. ,
MOV 01,8
MOV AX,LAB[DI]

, ,
LAB+8. - .
: MOV CX,[BX][DI]+2.
, ,
:
MOV , [] - (DS),
MOV ,[] -
(SS).
, , MOV AX,SS:[BX] -
. - MOV AX,DS:[BP] (, , DS).

, . , ADD DI,LAB[SI] ,
LAB SI, , DI. DI.
. , , . , , - ,

22

ASSEMBLER.

(. . 1.1 . 1.3). - .
-. : , , . . 1.3.
. - , , , .. .. , , - 64 ( ).
-
8088/8086 . : CS - , DS
- , SS - , ES - .
, , ,
. , DS ,
- . . 2.1
.

TITLE

PRIMER21

; 1
D1SEG SEGMENT
1 DB ' .$'
D1SEG ENDS

; 2
D2SEG SEGMENT
2 DB ' .$'
D2SEG ENDS
;
/ 30
;
STSEG SEGMENT STACK
LB 60 DUP(O)
;30
STSEG ENDS
CODSEG
SEGMENT
ASSUME CS:CODSEG, DS:D1SEG, SS:STSEG
BEGIN:
/
MOV AX,STSEG
MOV SS,AX
;DS
MOV AX,D1SEG
MOV DS,AX
LEA DX,TEXT1 ;DS:DX 1
MOV AH,9
INT 21H

2. ,

23

;
MOV ,
INT 16H
;DS
MOV AX,D2SEG
MOV DS,AX
LEA DX,TEXT2
;DS:DX 2
MOV ,9
INT 21H
;
MOV ,4
INT 21H
CODSEG
ENDS
END BEGIN
. 2.1. .
. , ,
. ,
.
CS IP.
;
DATA SEGMENT
1 DB ' I 1 ,13,10,'$'
2 DB ' 2 ', 13,10,'$'
DATA ENDS

;
STSEG SEGMENT STACK
DW 20 DUP(?)
STSEG ENDS
;
CODE1 SEGMENT
ASSUME CS:CODE1, DS:DATA
BEGIN:
MOV AX,DATA
MOV DS,AX
MOV AX,STSEG
MOV SS,AX
LEA DX,TEXT1
MOV AH,9
INT 21H
;
JMP FAR PTR BEG CODE2

... ,

24

ASSEMBLER.

_C,ODE1:
.
... MOV AH,4CH
INT 21H
CODE1 ENDS
/
CODE2 SEGMENT
ASSUME CS:CODE2, DS:DATA
BEG_CODE2:
LEA DX,TEXT2
MOV AH, 9
INT 21H
;
. JMP FAR PTR _CODE1
CODE2 ENDS
END BEGIN

. .

Puc. 2.2. .
,
-. . :
1. (,
, .. ).
2. END
. , - - , . -
. , -
, ( 100 ).
3. GROUP - , (. 3).
, , .
ASSUME .
. CS .
DS.SS ES . , , . ,
(Phase error) : MOV AL.LL, LL ( ). -
DS . , : MOV AX,DATA/MOVDS, .
-
( . 3). ,
, .
, , .
! DOS ,
. , .. -

2. ,

25

,
. (Memory Control Block -
) MS DOS, , ,
Microsoft .
, , 16 .
(. 2.3) .

0

- Z - .

, 0
.

(SIZE); S -
,
S+SIZE+1.

11

; MS DOS
.

. 2.3. .

. ,
. , , , ' . .
, , , - . . ,
. ,
.
- , ..
.
, - . , . , * . , , , , : F26778BOH. : B078H:67F2H ( ). ^
,
. , N, 0:4*N. INT 21 -

26

ASSEMBLER.

, ,
21 ( 0:84=2*4). INT 16H -
, 16. . (. 11,12
17). IBM PC (. 2.4.).
, . 2.4, .
. . , . -UTIL.COM
. (), MS DOS, , , , .

0040:

BIOS

0050:

DOS

, IO.SYS
MSDOS.SYS .
.

COMMAND.COM

, .

, .

,
COMMAND.COM. .
MS DOS .

VGA .
32 ., 800.

. 2.4. MS DOS. XXXXH


.
. 2.4. -, . MS DOS,
, . , 000:0000 , UMB - Upper Memory Block,
.. . , , . (expanded).

27

2. ,

.
AT (. ). , AT 80386 f
UMB .
. - 1 . , 8 ,
, - 640 , - (.. 7.3 ).
15 (. 5)
(. 20). . 22. , MS DOS .
Windows (. 24,25).
, , 13.
(, ) , , (. 2.5).:
:
~
1. .
2. , ,
. , , "", (", - !").
DATA SEGMENT

ASSUME CS:DATA / ,
; -
/
L1:
/
/
MOV DL,65 /
MOV , 2 / INT 2 1 . /
DATA ENDS
STAC SEGMENT STACK
DB 50 DUP(?)
STAC ENDS
CODE SEGMENT
ASSUME CS:CODE, SS:STAC, DS:DATA
BEGIN:
:

MOV AX,DATA
MOV DS,AX
LEA SI,LI
LEA DI,L2

. ', :

.:

28

ASSEMBLER.

;
MOV AX,WORD PTR [SI]
MOV WORD PTR C S : [ D I ] , A X
MOV AX,WORD PTR [SI]+2
MOV WORD PTR C S : [ D I ] + 2 , A X
MOV AX,WORD PTR [SI]+4
MOV WORD PTR C S : [ D I ] + 4 , A X
;
;

JMP L2
; ,
;
L2 : ;

NOP
NOP
NO.P
NOP
NOP
NOP

,,
...

MOV ,4

INT 21H
CODE ENDS
END BEGIN
. 2.5. .
. 2.5 -
4.

3. .
- , .
.
, . - DOS BIOS, , -, . , . , , ,
. , .
, , . 3.1,
Intel 80868. , : ()
(). , .
.
- (), () .
, . ( ,
CS), . ,

. , , . . . . , .
, ,
. . AX,BX,DX,CX -
. , AL ( ) ( ). .
- ,
: -,
, .
-, (. ). - ( ).
, ,
. , ,
(. 4,18).
s

, 80386 (. 20).

ASSEMBLER.

30

111/:

AX-AH
BH-BL
CX-0-CL

DX = DH * DL

SP
3P

Cl

'.

<.

^
30286
* 8 .

<

. 3.1. 8086/8088.

3.

31

, . (. 3.1) ,
. 09 21.
;

DSEG SEGMENT

/ ,
;
MAX
DB 255
/
LEN
DB ?
;
STROKA DB 255 DUP(?) ;
DB ?
/
ENT DB 13,10,'$' /
DSEG ENDS
'
;
STSEG SEGMENT STACK
DB 60 DUP(O)
STSEG ENDS
CODSEG
SEGMENT

ASSUME CS:CODSEG, DS:DSEG, SS:STSEG


BEGIN:
/
MOV AX,STSEG
MOV SS,AX
/DS
MOV AX,DSEG
MOV DS,AX
;
/
MOV ,
LEA DX,MAX
/
INT 21H
/ 09
MOV BL,LEN
MOV ,0
/ '$'
/ 09
MOV [BX+STROKA+1],'$'
;
LEA DX,ENT
/
MOV ,09
INT 21H
/
LEA DX,STROKA /
INT 21H

,
~ "*

32

ASSEMBLER.

/ 4 21
;
MOV ,4
INT 21H
CODSEG ENDS
END BEGIN
. 3.1. 09 21.
. -,
MOV [BX+STROKA+1],'$' - $. , ? , , , ,
DS. MOV
DS:[BX+STROKA+1],'$'. , , . MOV
ES:[BX+5],65. , BX+STROKA+1. , STROKA, , 1.
+ 1. LEA DX,STROKA. DX
, STROKA, , DS; LEA DX,DS:STROKA.
-, 09? , 21
, , - .
-, 13,10? , , .
, ,
. , DOS
. -
IF ERRORLEVEL NUMBER. ( )
4 21 (. .3.1), AL . ,
, DOS (, 0 9). ,
.. 255.
CODSEG
SEGMENT
ASSUME CS:CODSEG
ORG 10OH
BEGIN:

; 0 16

3.

33

; -MOV ,
INT 16H
;-- AL ASCII-;-- -;-- - AL,48
/ AL 48
JB BEGIN
;
CMP AL,58
/ AL 58
JA BEGIN
/
/-- ASCII -SUB AL,48
/ AL 48
/-- DOS, AL
MOV ,4
INT 21H
CODSEG
ENDS
END BEGIN
. 3.2. DOS .
, , , -. ,
-. . , .
, , .
ORG100. , , ,
1 . - . - . .
- ,
100 .
(PSP - Program Segment Prefix, .. ). PSP , , , a PSP 256 .
PSP .
. ( ASCII) . ,
. CTRL-BREAK.
CODSEG
SEGMENT
ASSUME
CS:CODSEG
ORG 100H
BEGIN:

JMP BEGINI
ENT DB 13,10,'$'
2-4072

34

ASSEMBLER.

BEGIN1:
'
; -'MOV

':
i
;

INT 16H
;:
CMP AL,
JNZ DISP
;
MOV ,02
; 2 21
; 7
MOV DL,7
INT 21H
;-- .
JMP BEGIN1
DISP:
;'
MOV ,
MOV , 1
/
MOV ,0
/ 0
i
INT
/
.
MOV ,09
MOV DX,OFFSET ENT
INT 21H
JMP BEGIN1
;
;.. CTRL-BREAK
CODSEG ENDS
END BEGIN
. 3.3. .
, :
? 2 21
. 32 : 13- , 7
- , 8 - ..
. , , 7,
CTRL-G. , CTRL-C, , .
, . . , . - : - . .

35

3.

, . SP (Stack
Pointer - ). ,
SS. : PUSH - , POP - . PUSH (, PUSH AX, PUSH DX ..) SP 2, , , ( DX). POP (, POP DS, POP ..), SP 2,
( DS ) , SP.
PUSH POP,
: CALL - , RET - , INT - , IRET - . , , CALL
RET. CALL, , CALL NET, NET - ( ),
. RET
, ,
CALL. , :
" - ?" , . , , ,
, .. .
.
, .
;
DSEG
SEGMENT
; (. )
MAX
DB 255
LEN
DB
STROKA

DB 256 DUP(?)

;
ENT
DSEG

DB 13,10,'$'
ENDS

;-- --

STSEG

SEGMENT STACK
DB 30 DUP(?)
TOP
DB ?
STSEG ENDS
;
CODSEG SEGMENT
ASSUME CS:CODSEG, DS:DSEG, SS:STSEG, ES:CODSEG
BEGIN:' '"'
' '
,
'' " '
" ' v"/ ' '
':";
'
'JMP BEG

''".

36

ASSEMBLER.

;-- -CONVERT PROC


/-- -LEA
MOV
MOV
ADD

DI,STROKA
BL,LEN
BH,
BX,DI

DEC BX

CICL:
CMP D I , B X
/ DI=>BX
JNB KONEC
/--
MOV AL, [DI]
MOV , []
MOV [DI],AH
MOV [ B X ] , A L
/-- -INC DI
DEC
JMP CICL
KONEC:
RET
;
CONVERT ENDP
/-- .-DISP_STR PROC
/--
MOV DX,OFFSET ENT
MOV AH,09H
INT 21H
/-- -MOV DI,OFFSET STROKA
MOV CL,LEN
MOV AH,02H
/ 21
PROD:
MOV DL, [DI]
INT 21H
/ DS:[DI]
INC DI
/
DEC CL
/
JNZ PROD
/ 0
RET
;
DISP_STR ENDP
BEG:
/-- -MOV AX,DSEG

3.

37

MOV DS,AX
MOV AX,STSEG
MOV SS,AX
MOV SP,OFFSET SS:TOP
/--
MOV DX,OFFSET MAX ;
;
MOV ,
;
INT 21H
CMP LEN,0
; ,
JZ EXIT
CALL CONVERT
CALL DISP_STR
EXIT:
MOV ,4
INT 21H
CODSEG ENDS
END BEGIN
. 3.4. .
.3.4, , , ,
,
. 02 21
, . .
.
, , , ,
. . , : CONVERT DIS_STR
(, CONVERT ENDP DIS_STR ENDP ). , , . . 3.4 ,
END BEGIN END BEG. JMP BEG. , .
,
(. 3.5 - 3.6).
; ,
CODSEG
SEGMENT
ASSUME CS:CODSEG
ORG 100H
BEGIN:
MOV A X , 6 5
PUSH AX

38

ASSEMBLER.

/ 0041 (65)
MOV BP,SP

L1:

'

CMP WORD PTR [],65


; ,
; ,
;
JNZ L1
POP
/ 0041 ,
L2:
,
JNZ L2
LEA AX,EXIT
PUSH AX
; EXIT,
/ RET JMP EXIT
RET
JMP BEGIN
EXIT:
MOV AH,4CH
INT 21H
CODSEG ENDS
END BEGIN
. 3.5. (1).
/ ,
CODE SEGMENT
ORG 10
ASSUME CS:CODE
BEGIN:
MOV AH, 2
MOV DL,65
PUSH AX
/ PUSH DX
SUB SP,2
MOV BP,SP
MOV
[BP],DX
;
MOV DH,78
MOV AH, 56

39

3.

POP DX
; POP AX
MOV BP,SP
MOV AX, [BP]
ADD SP,2
;
INT 21H
;
RET
CODE ENDS
END BEGIN

. 3.6. (2).
. , , , , . ,
, . , ,
, () ,
(. 11,15).
.
. (. 3.7)
16 9.

15

1 13 12 11 10 9
OF DF IF

TF SF ZF

5 4
SF

2
PF

CF

. 3.7. , 8086/8088.
16 , , .
CF - . 1,
, . CF
, . CF .
PF - . 1, , 0 - .
AF - . CF,
.
, 80386 32- (. 20).

40

ASSEMBLER.

ZF - . 1, , 0 - .
SF - . . .
TF - . 1, (). .
IF - . 0, ( ).
(NMI). NMI , .
DF - . () .
, , . .
OF - . 1,
. 1,
. OF=0, .
PUSHF POP AX (. ), ,
(. ). (PUSH AX/POPF)
. ,
, , Intel. , . ,
, , (, 80386
80486) (. 23).

4.
8088/8086.

, :

.
.
.
: 8088/8086. , , 1, . , ..
. ,
, 1. , .
, 8088/8086.
80386 32- 20.
.
, 32- , .. 16 .
, , . , , , .
, .

I. .
2
. : MOV
,; MOV CL,DH ..
( ): MOV CX,2000; MOV Ml,80. : , 80 - . , M l - DB DW
( , Ml). ,
.
, , MOV BYTE PTR 1,80,
, MOV BYTE
PTRMl+1,80.
MOV AX,DSEG - DSEG -
. , ,
, , .

42

ASSEMBLER.

. THERE , , , MOV AX,SEG THERE.


- ( ) LEA AX,THERE MOV AX,OFFSET THERE. , .
LES. , LES DX.KONEC :
MOV DX,KONEC
MOV ES,KONEC+2

LDS, DS. ,
[3] .
, , . :
IN AL,15H
IN AX,DX
OUT DX,AX
OUT DX/AL

/ AL 15
; DX
;,
/ , DX

.. .
. 9.
. PUSHF - , POPF - . ,
:
PUSH
POPF
, . , , . LAHF SAHF (. 1),
. 8086/8088.
XLAT .
DS:BX . AL
. XLAT AL
.

II. .
, IP. IP . -

4. 8088/8086

43

, , -
. JMP :
JMP SHORT L1 - . .
128 ( ).
JMP L1 - . .
. JMP [BX]-
, , . .
. . 4.1.
CODE SEGMENT
ASSUME CS:CODE
ORG 100H
BEG:
JMP SHORT BEGIN
/
; ,
;
LI
DW OFFFOH
;
DW OFOOOH
;
BEGIN:
JMP DWORD PTR LI
/
CODE ENDS
END BEG
. 4.1. , .
, , RESET.
. JMP DWORD PTR L1 :
LEA DI,L1
JMP DWORD PTR C S : [ D I ]

, .
. 1, . .
:

INT 21H

JC ERROR ; ,, DOS
ERROR:

44

ASSEMBLER.

JC
ERROR 128 . . ,
. :

INT 21H
JNC NO_ERROR
JMP ERROR
NO ERROR:

ERROR:



. , JC JNC
, (, . 3). , LOOP.
. .4.2 . .4.2 , .
, LOOP .
LOOP . 1.

MOV ,10
;
LOOP1:
PUSH
MOV ,100 ;
LOOP2 :
PUSH

POP
LOOP LOOP2
POP
LOOP LOOP1

. 4.2. .

4. 8088/8086

45

, . ,
(). - . CALL (). RET.
( ) .
FAR ( , , ), .
. , . RET, , , .. .
RETF. ,
. , RET
, .. RETF. RETF RETF. RETN. ,
FAR (CALL FAR PTR SORT), ,
RET, , RETF. (. 4.3) RETF. . 4.1.
CODE SEGMENT
ASSUME CS:CODE
BEG:
JMP SHORT BEGIN
/ ,
;
LI
DW OFFFOH
;
DW OFOOOH
BEGIN:
PUSH Ll+2
PUSH LI
RETF
; RESET
CODE ENDS
END BEG
Puc. 4.3. RETF JMP.

III. .
: , , , .
. . 4.4 OPER1 OPER2. SUM. ,
4 .
ADC. (-

46

ASSEMBLER.

). , , 4 .
, ;

MOV
ADD
MOV
MOV
ADC
MOV

AX,WORD PTR OPER1


AX,WORD PTR OPER2
WORD PTR SUM,AX
AX,WORD PTR OPER1+2
AX,WORD PTR OPER2+2
WORD PTR SUM,AX

; OPER1
/ OPER2
/ SUM
; OPER1
/ OPER2
/ SUM

. 4.4. .
(.4.5) SUBnSBB.

MOV AX,WORD PTR OPER1


SUB AX,WORD PTR OPER2
MOV WORD PTR SUM,AX
MOV AX,WORD PTR OPER1+2
SBB AX,WORD PTR OPER2+2
MOV WORD PTR SUM,AX

/ OPER1
/ OPER2
/ SUM
/ OPER1
/ OPER2
; SUM

. 4.5. .
: .
, ,
. :
MUL DX / DX , DX:AX
IMUL BYTE PTR MEM1 / 1 AL ,
/
MUL BL / BL AL, .
, ( ), (AL)
(). DX:AX.
MUL CF OF 0, ( ) . 1. -

4. 8088/8086

47

IMUL CF OF 0,
, 1.
. .
DIV / DX:AX , , DX
IDIV BYTE PTR MEM1 ; AH:AL 1
; , AL,
DIV DL ,- AH:AL DL , AL, .

- . -, 0 -
Divide overflow. . INC,DEC,NEG, , , .
-
, . CBW 7- AL
. CWD 15- DX.
BCD .
, . BCD . . ,
87 BCD 87 (!). BCD , . 48, , . ASCII
. , , , . . , ,
. . :

- ,
DAA - .
. ,
AL. :

AAS - ,
DAS - .
. ,
AL. :
- .
. :

AAD - .

48

ASSEMBLER.

(!) . , , AL, .

IV. .
AND OR,
. . , 0 - , 1 - . . :

MOV AL,0101111B
MOV DL,1001001
MOV BL,0001111
MOV CL,1111000
AND AL,DL
OR
DL,BL
XOR BL,CL

AL 0001001 , DL 1001111, BL -1110111. . XOR


. , ,
, .
( ,
).
- , .
.
XOR. ,
XOR . XOR
. XOR , MOV
,0, .. . OR ,
, .
- ,
( ) . , .
- . , ,
,
MUL DIV. , 16 :

4. 8088/8086

MOV , 456
MOV CL,4
SHL A X / C L

49

/ 456
;
;, .. 16

. , 2, . ,
NUM 130. 130= 128+2. , :

MOV AX,NUM
MOV CL,7
SHL AX,CL

;
/ 7
/ 128

MOV BX,NUM

SHL BX,1
ADD AX,BX
ADD AX,NUM

/ 2
/ * 130
/

-
. . , ,
AL, .
. , SHR AL,5.
, :

ROL AL, 3
/ 3
MOV AH,AL .
/
AND AL,00000111B /

SHR ,3

V. .
, . ,
. . : REP
REPE/REPZ
REPNE/REPNZ

50

ASSEMBLER.

, (REP) - =0 Z= I (Z=0 REPNE/REPNZ).


-. REPE/REPZ, REPNE/
REPNZ (), REP - .
. . . ,
- , DS SI,
- , ES,
DI. DI.SI 1 (
) 2 ( ). =, , =, . DF CLD - ,
STD - . : '' , 'W -
, . , , . , , . DB, , DW,
. ,
REP MOVS DEST,SOURCE

DEST SOURCE () DW, MOVS


MOVSW. ,
. , ,
, 64.
- MOVSB MOVSW.
SOURCE DEST.
200. .
CLD
MOV , 2 0 0
LEA SI,DS:SOURCE
LEA DI,ES:DEST
REP MOVSB

.
SI -

4. 8088/8086

51

. DI . ,
DS ES ,
. (, ES), . LEA SI,ES:SOURCE. , ES.
- CMPSB CMPSW. :

STD
MOV ,100
LEA SI,DS:SOURCE
LEA DI,ES:DEST
REPNE CMPSW

- SOURCE DEST. , .
- 100 . =0,
. , , Z= 1. ,
JNZ NO_FOUND ; , Z=0
, , . ,
.
- SCASW SCASB.
. DI. .

CLD

MOV ,200
LEA DI,STRING
MOV AX,7890H
REPNE SCASW

/ 200
;DI
;

7890. , DI. Z
1.
- LODSB,LODSW,STOSB,STOSW. LODSB (LODSW) (), SI AL (),
SI . STOSB (STOSB)
AL () , DI, -

52

ASSEMBLER.

DI .
. SI , DI - , ,
, . , - . DS
, , a ES - , ;
:
L1:

LODSB
STOSB
LOOP L1
(DF):
L1:
MOV AL, [SI]

MOV ES:[DI],AL
INC DI
INC SI

LOOP LI
, . (^) . , .
CODE SEGMENT
ASSUME CS-.CODE
ORG 100H
BEGIN:
JMP BEG

TEXT1 DB ' ',13,10,'$'


TEXT2 DB ' 1,13,10,'$'
WHE
DW ?
/ ,
DW ?
;
BEG:
MOV AX,ES
ADD AX,1000H
/
MOV ES,AX
MOV DI,0
M O V WHE, D I

, MOVrWHE+2,ES,.:
LEA SI,Ll

;ES:DI ,
/
=
,
. . , < .

..,;
'.,.'.'.','.
.',/.'. -,:-.
,, ,
;

4. 8088/8086

53

MOV CX/L2-L1+1 . /
CLD
REP MOVSB
;
CALL DWORD PTR WHE /
JMP L2
;

L1:
LEA DX,TEXT1
MOV AH,09H
INT 21H
RETF
;

L2:
LEA DX,TEXT2
MOV AH,09H
INT 21H
MOV ,4
INT 21H
CODE ENDS
END BEGIN
Puc. 4.6. , MOVSB.
- ( - , ).
, ,
. , MOV
LEA , , DS.

VI. .
, , .
. .
LOCK - .
.
.
NOP - . , . , ,
, .
HLT - . .
, , . CLI/HLT "" .

54

ASSEMBLER.

WAIT .
, -
. , , . , HLT
. ,
. ,
. , . WAIT.
ESC ,
, , .
. .
- . ESC , [2,17]. ESC
, (. 3).

VII. .10
, , 8088/8086. ,
: 8088,8086, 80188, 80186,80286, 80386, 80486, Pentium.
NEC20 NEC30. ,
. , ( ). ,
8088 80286. 8086 8088?
, ,
. .
3 .
( ) . . . ,
, , , .
, , INT, IRET, RET, CALL
.
. , 8088 4 , 8086 - 6. ,
NEC20 4 ,
. (. 4.7) ,
. NOP,
.

4. 8088/8086

55

CODE SEGMENT
ASSUME CS:CODE
ORG 100H

BEGIN:
MOV DI,OFFSET MET
JMP SHORT MET1

MET1:

MOV BYTE PTR [DI],OC3H

NOP
MET: NOP

; ,
; JMP SHORT MET1
LEA DX,TEXT
MOV ,9
INT 21H
RET
TEXT DB '!',13,10,'$'
CODE ENDS
END BEGIN
Puc. 4.7. .
, , .
. , . ,
. , , . :
MOV AX,FLAG
PUSH AX
POPF
PUSHF
POP

CMP AX,BX
"" ,
. PUSH
SP. , SP 2 - ,
, . , 286- SP , . , , ,
. , PUSHA 8088/8086 . . 4.8 , .

56

ASSEMBLER.

.286
! -
' - , ;
CODE SEGMENT
ASSUME CSrCODE
ORG 100H
BEGIN:
MOV AX,SP
PUSHA
CMP AX,SP
JNZ P286
MOV AH, 9
MOV DX,OFFSET MES
INT 21h
: :
JMP ^SriORT RON
P286:
POPA
KON:
RET
MES DB ' 86 88 1,13,10, '$'
CODE ENDS
END BEGIN
. 4.8. , PUSH POP A.
, , ,
. [15].
,
. 23 , .

VIII. .
. ,
. , -
, .
, , . ,
( ). 1 ,
.

5.
.
- , , .
.. .
.

I.

8088/8086.
.
- . 20
, .
80286 80386, ..
, . 80286, , , , .
80286 8088/8086.
, (. ),
, . ,
8086- ". , , 286- .
, - ,
.
. [18,22].
80286 : .
8088/
8086 . .
,
.

80186. , . (. 20). 286-


Pentium'oB, , .

58

ASSEMBLER.

II.
80286 (
8086). , ,
Pentium'bi, , , - .
. PUSHA - 12. ,
. ,
, , PUSH 457H ( 0457).
. : IMUL DX,BX,123 (BX*123 --> DX) IMUL CX,MEMW,567
(MEMW*567~>CX). MEMW - . NOT, . . SHL ,7 SHR MEM, 10. 8086/8088 : MOV CL,7/SHL AX.CL.
() : OUTS - ; INS - . .
INS , DX,
, DI, ()
DI. OUTS .
JCXZ - , 0.
80286 ,
. .
BOUND , 16- . .
; . , BOUND AX.MEMW ,
, MEMW MEMW+2.
, .
ENTER LEAVE .
ENTER OP 1 ,2 . 1
, 2 - .
2=0 ( ).
LEAVE , , ENTER.
12

, , III,
80186.

5.

59

, :
ENTER N,0 ( )
PUSH BP\MOV BP,SP\SUB SP,4, LEAVE - MOV
SP,BP\POP BP. (. 15).
,
.286 .286, (. ).
80286. .

III.
.
8088/8086 80286 () (. 2).
16 . 20- (20- ).
() ,
, - . 286- 24 ( 32
386-). ( ) :
13

S JC

RPL

RPL - ,
;
-,
=0 - (GDT) - GLOBAL
DESCRIPTTABLE.
= 1 - (LDT) - LOCAL
DESCRIPTTABLE.
( - ) LDT. , , GDT. "" LDT. , () .
, (24
16 ). ,
24- . =0
- - . GDT, , .
13 ,
213 . -

60

ASSEMBLER.

, 2 16 . , ,

2 13*2 16 . 2 16 ,
. . , IDT (. 26).

IV. .
GDT LDT, .

GDT GDT (24 )


(16 ). (). LDT (16 )
, LDT.
GDT.
LDT.
GDT LDT ( ) LGDT, LLDT SGDT, SLDT
(. ).
GDT .
.
, ,
- LDT.
LDT (CS, DS, SS, ES)
. , , .
:
1. .
2. TI GDT, GDT
4.
3. TI LDT,
) LDT LDT;
) 8. , 8 ;
) GDT GDT;
) ;

61

5.

4.
5.
6.
7.

) , LDT. . 4.
, 8
. .
.
. .
.

V. .
.
8

16

24

16

, . 5.1.

PL

6-6

DPL

WD

6-5

DPL

6-5

3
I

DPL

- LDT

I
Y f
1

. 5.1. .
, *
. .

62

ASSEMBLER.

DPL - ,
.
- . , (0 - , 1 ). , , - .
- .
( ) . 1,
. 0 . ..
, ,
0. 0. 0.
= 1, . .. .
R - . R= 1, . R=0,
. .
W - . W= 1, , , . W=0, .
LDT , .
- .
ED- . , .
. ED=1 .
4 :
0 -
1 - TSS13 80286
2 - LDT (. . 5.1)
3 - TSS 80286
4 - 80286 (. )
5 - 80286 80386
6 - 80286
7 - 80286
8 -
9 - TSS 80386
-
- TSS 80386
- 80386
D -
- 80386
F - 80386
13

TSS - Task State Segment - , .. ,


, .

5.

63

.
- , 1.
- 24 .
(16 ) 286- 0. 386-
, , 32- .
, 286- 2 24 , .. 16 . 386- 256 (2 8 ), .. 4 .
. .
.
16

16

16

.
16 32- 32- . .

6-5

DPL

6-5
DPL

4
0

1
1

6-5
DPL

4
0

0
1

()

64

ASSEMBLER.

(IDT).
GDTR.
LIDT.

386- .
, 386- . . 20,26.
16 386- .
.
48 51 , .. . .. 20 , , 1 .
52 - , .
53 - .
54 - 0,
16-, 32-.
55 - . .
56 63 . ,
, 32-.
LDT.
, 52 55 .
.
16 32 .

VI. .
, ,
LDT .
, LDT. .
LDT.
,
, . .
, LDT, . , LDT.
(TSS). ,
. () (TR).

5.

65

. .
. , (
), .
. , TSS. TR.
.

,
, 1
, 2

IP

__

SP

SI

ES
CS

DS
LDT

" ".
TSS. ,
. . ( JMP).
3-4072

66

ASSEMBLER.

VII. .
.
LGDT - . .
GDT, ( 386-
). (. 26).
SGDT - GDT . .
LLDT - - LDT.
,
GDT. .
SLDT - LDT -. ,
LLDT.
L AR - , .
LSL - LAR,
.
LMSW - .
. , LMSW .
SMSW - .
LTR - . .
CLTS - .
LIDT - .

VIII. .
80286 ,
, , . LMSW, (
) , KOTQPOM 1 ( 0). ,
(GDT, LDT ..)
(GDT, LDT .).
1. ,
.
SMSW

OR

AX, 1

LMSW

AX

3 , :
1 - ,
(80287), . . .. .. .., ...........
.. : ..
,. , . . .,..,'. . . , ," , . , ' , ' _ , .' ,/;"
2- ,
3 - ( ).

5.

67

286- .
,
:
1. GDT.
GDT, (. ).
2. .
3. ,
20 (. [19,22]).
4. GDTR.
5. IDTR.
.
6. ,

LDTR. , ,
.
7. .
8. .
9. ( LTR).
26 .
89 1SH
(. ).

IX. .
80286 . .
( )
:
1. ;
2. , ;
3. , .
DPL . DPL
2 , 4 . ,
DPL 00, - ,
, 00.
, 3. 0,1,2 . -

68

ASSEMBLER.

0.
1. 2 .
:
1. ,
.
2. ,
.
2 . CALL , (). , LDT. , , . , ( ,
). , .

. -: OUT, IN, OUTS, INS. , ()
. , , : CLI, STI, LOCK.

X. 15.
- , ,
. 89 . . , .
[19]. , BIOS
,

.
, . ,
MS DOS.
, , IBM- (, MOV ES:[BX],AL) 640 . (. 2). (. 22). , (
). , . , , 16 (
286 ).
. 87 15
1 .

5.

69

88:
-88
:
- ,
100000 (1048576). , .
, MS DOS, , 15. 88 0 . , , HIMEM.SYS.
87, .
:
-87,
- , 8000,
64 .
ES:SI - ( GDT), .
:
, - 0, ,
-1 ,
2 ,
3 .
GDT:
- , 0, , 0, BIOS,
- ,
- , ,
- , 0, BIOS,
- , 0, BIOS.
, , 0, .
(. IV ):
(16 ) . ,
2*-1, (24 ) - ,
, 93, , .
.286
WHERE EQU
/
DATA SEGMENT
/-- GDT1
INT 15 GDT LABEL BYTE

70

ASSEMBLER.

/16
DB 8 DUP(O)
DB 8 DUP(O)
/ = *2-1
DW 31
; 24-
SRC_LO DW ?
SRC_HI DB ?
;
DB 93H
;
DW
; = *2-1
DW 31
;24-
DST_LO DW ?
DST_HI DB ?
;
DB 93H
;
DW
;1
DB 8 DUP(O)
DB 8 DUP(O)
; GDT1
; GDT2
INT_15_GDT1 LABEL BYTE
;1
DB 8 DUP(O)
DB 8 DUP(O)
/ = *2-1
DW 31
/24-
SRC_L01 DW ?
SRC_HI1 DB ?
;
DB 93H
/

DW
/ = *2-1
DW 31
/24-
DST_L01 DW ?
DST DB ?

5.

;
DB 93H
;
DW
; 1
DB 8 DUP(O)

DB 8 DUP(O)
; GDT2
DATA ENDS
;
; , ''
DATAl SEGMENT
DB 32 DUP(65)
DB 13,10,'$'
DATAl ENDS
;
ST1 SEGMENT STACK
DB 200 DUP(?)
ST1 ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:ST1
BEGIN:
; I
;
MOV AX,DATA
MOV DS,AX
MOV ES,AX
LEA SI,DS:INT_15_GDT
; GOT
;
MOV AX,DATAl
MOV DL,AH
SHL AX,4
;*
SHR DL,4
;*
MOV SRC_LO,AX
MOV SRC_HI,DL
/
MOV DST_HI,WHERE
MOV DST_LO, OOOOOH
;
MOV CX,16
MOV AH,87H
INT 15H
;

71

72

MOV DL,AH
MOV AH, 2
INT 21H
;
MOV AX,DATA1
MOV DS,AX
MOV DX, 0
MOV AH, 9
INT 21H
; ,
MOV ,32
MOV BX,DATA1
LL:
MOV BYTE PTR DS:[BX],66
INC BX
LOOP LL
; II
/--
MOV AX,DATA
MOV DS,AX
MOV ES,AX
LEA SI,DS:INT_15_GDT1
; GOT
;
MOV AX,DATA1
MOV DL,AH
SHL AX,4
;*
SHR DL,4
;*
MOV DST_L01,AX
MOV DST_HI1,DL
;
MOV SRC_HII,WHERE
MOV
SRC_LO1,OOOOOH
;
MOV CX,16
MOV AH,87H
INT 15H
;
MOV DL,AH
MOV AH, 2
INT 21H
;
MOV AX,DATA1
MOV DS,AX

ASSEMBLER.

5.

MOV

DX,

MOV

,9

73

INT
21H
EXIT:
MOV A H , 4 C H
INT 21H

CODE ENDS
END BEGIN

Puc. 5.2.
.
. 5.2 , . ,
, .
, ,
. , 286-
.
, ,
, UMB 22.

6. .
- , - , -
.
..
.

I.

MS DOS . -
( 21, 25, 26
). - BIOS (
, 13, 15, 16 .). - -
. , . , , [5] : ,
DOS BIOS .

. . , , . - : .
, :
. , .

.
,
MS DOS. . :
1. () , .
2. MSDOS.SYS IO.SYS, ().
, MS DOS .
. , ,
, .
Windows , (. 24,25).

6.

75

3. - COMMAND^QM. , (2)
(3), , , (BIOS),
MS DOS, .
( 21, 25, 26 .)
MSDOS.SYS. . ( 1) ( ).
IO.SYS BIOS, .
:
1. MS DOS. , BIOS
, BIOS .
2. , . , , ,
3. , , |5.
COMMAND.CQM , .

.

. , VGA . , .
. MS DOS ( 7) 1 . -. 02 09. .
, .
, , BIOS - .
06 DOS, , ,
. , .
MS DOS, , . MS DOS " ". , DOS
HANDLE - .
, (. 8).
, - 0 4. :
15

76

ASSEMBLER.

() - ,
() -1,
( ) - 2,
(1) - 3,
(LPT1) - 4.
.
8, . DOS 40H .
, , a DS:DX
. PRIMER.TXT
( ).
DSEG

SEGMENT

BUFER DB 200 DUP(?)


FILE DB 'PRIMER.TXT',0
HANDLE DW ?
EOF
DB 0
DSEG

; -
;
;
; 1,

ENDS

SSEG SEGMENT STACK


DB 30 DUP(?)
TOP DB ?
SSEG ENDS
CODE SEGMENT
ASSUME CSrCODE, DS:DSEG, SS:SSEG
BEGIN:
;
MOV AX,DSEG
MOV DS,AX
MOV AX,SSEG
MOV SS,AX
MOV SP,OFFSET SS:TOP
;-
MOV AH,3DH
MOV AL,0
LEA DX,FILE
INT 21H
. ;
JC ER
; -
LEA DX,BUFER
; DX -
MOV BX,AX
MOV HANDLE,
/
MOV CX,200
;- 200
I

CIKL:

6.

77

/
MOV AH,3FH
INT 21H
JC CLOSE
; -
CMP CX,AX
JZ NOT_EOF
;
MOV EOF,!
MOV CX,AX
NOT_EOF:
;
MOV ,40
MOV ,1
;
INT 21H
CMP EOF,1
;
MOV BX,HANDLE
JZ CLOSE
JMP CIKL
/
,
CLOSE:
;
MOV AH,3EH
INT 21H
ER:
;
MOV ,4
INT 21H
CODE ENDS
END BEGIN
. 6.1. .
8. , . , DOS . DOS , , , BIOS.
DOS . .
, . . .
, , 06 07.
. , -

78

ASSEMBLER.

DOS () - 06 . ,
.
PROC CLS

CLS

MOV , 0
; -,CL-x
MOV DX,184FH ; -,DL-x
MOV AL, 0
; , 0,
MOV ,06
;
MOV ,7
/
INT 10H
;
RET
;
ENDP

. 6.2. .
, .6.2, ,
.
. . 7 - .
. ( 2,3) : .,.,.... EGA VGA .
DSEG
SEGMENT
STROKA DB ' ' , 1 , ' ' , 2 , ' ' , 3 , ' ' , 4 , ' ' , 5 , ' ' ,
DSEG ENDS
SSEG SEGMENT STACK
DB 60 D U P ( ? )
TOP DB ?
SSEG ENDS
CODE SEGMENT
ASSUME CSrCODE, DS:DSEG, SS:SSEG
BEGIN:
MOV AX,DSEG
MOV DS,AX
MOV AX,SSEG
MOV SS,AX
MOV SP,OFFSET SS:TOP
I ~ ~~~'

PUSH DS

POP ES
MOV BP,OFFSET DS:STROKA

;ES
;BP

6.

MOV DX,0205H
MOV AL,3
MOV ,13
MOV C X ,
INT 10H

79

/ 2,5
/ 3
/
/ (!)
/

*~ ~ ~

MOV ,4
INT 21H
CODE ENDS
END BEGIN
. 6.3. .
, BIOS ,
-, .
, , . , 800: ( CGA, EGA, VGA ). . , - ( , , ).
,
.

MOV ,800
MOV ES,AX
MOV BYTE PTR E S : [ 9 ] , ' A ' /
MOV BYTE PTR E S : [ 1 0 ] , 5 / 5

. , 16 . 0 7 , 8 15 - . 4,5,6 . ,
. 7 1, . , ,
. . 32 .
, 8 . . , , , 25 80 ,
2 . , , ,
. : ; , 0 ( ), , 3,
.
.

ASSEMBLER.

80

COPY_P PROC
; ,
; DH
; , a DL ,
PUSH DS
PUSH ES
PUSH AX
PUSH BX
PUSH CX
PUSH DI
PUSH SI
PUSHF

REP

PUSH
XOR
MOV
MOV
MUL
MOV
POP
XOR
MOV
MOV
MUL
MOV
MOV
MOV
MOV
MOV
CLD
MOVSW

DX

BH,BH
BL,DL
AX,4000
BX
SI, AX
DX

BH,BH
BL,DH
AX,4000
BX

DI,AX
AX,OB800H
ES,AX
DS,AX
CX,2000

;DX
;
;
; 4000
;
; SI
; DX
;
;
; 4000
;
; DI
;
; ES
; DS
; 2000
;
;

;
POPF
POP SI
POP DI
POP CX
POP
POP
POP
POP
RET

BX
AX
ES
DS

COPY P ENDP
Puc. 6.4. .

6.

81

.
, . ,
. , . , DX.
. , ,
15.
III.


.
<>
- DOS 05
4.
- BIOS 17H. ($)
- - .
<.>
-
DOS 0 ($).
- BIOS 16H, ($).
- 9.
^ >
- DOS 04 03.
- 14.
- .
< .>
- DOS,
25 26. ($)
- 1 - .
- . (@)
<, .>
- .
- .
- . ($)
$ - .
@ - .

82

ASSEMBLER.

IV. .
! ,
...
.. .
DOS BIOS - ,
, 7
(MOV DL,7/MOV ,2 21). . , , ( ) .
, . . IBM PC.
( . 9).
. 0
. . 18.2
, 8. , . ,
.
( ), . 0 - 40.
1 . - 4. , .
, .. .
2 ,
. - 42.
. 42 ().
. 0 .
. ,
.
2 61. 1
1, 2 . ,
2 0
1 ( ).
43.
.

6.

0 - , 1 - - ;

1-3

, 3;

4-5

:
00 ,
01 / ,
10 / ,
11 / , ;

6-7

83

(0-2).

CODE SEGMENT
ORG 100H

ASSUME CSrCODE
BEGIN:
MOV AL,10110110B
/
OUT 43H,AL
IN AL,61H
OR AL,3
/
OUT 61H,AL
MOV AX,1200
;
;
;
OUT 42H,AL
MOV AL,AH
OUT 42H,AL
MOV CX,OFFFFH
;
LOO: LOOP LOO
/ , ..
IN AL,61H
AND AL,11111100B
OUT 61H,AL
RET
CODE ENDS
END BEGIN
Puc. 6.5. , .
, . 6.5, . .
MS DOS () .

84

ASSEMBLER.

.
.
,
. .
. , , . , ,
.
, , 21: 2, 2, 2, 2DH. ,
BIOS 1 , . =(1/18.2).
, MS DOS. AT , . 1 .
.
. 9.

7. , , .
"Reset".
"Any key "?
.

.
. , , . ,
, .

I.
, . . . 9.
, INT, (. ). ,
9. INT 9H |6.
.
, 9, - - ( ASCII
). - , - -, ( ASCII)
. -, ASCII -
(. ). ,
|7. ,
, 9-
, 004017. ,
, -
. Ins. ASCII, . , 9- : PrtSc, Ctrl-Break
. . - . 7.1. ( ) . 16
17

9.
, , , , ASCII ,
.

ASSEMBLER.

86

Windows. MS DOS . , ( 9)
.

40:17
0:1 - Shift ;
1:1- Shift ;
2:1 - Ctrl () ;
3:1 - Alt () ;
4:1 - ScrolLock;
5:1 - NumLock;
6:1 - CapsLock;
7:1 - Insert;

40:18
0:1 - Ctrl ;
1:1- Alt ;
2:1 - SysRec ;
3:1 - ;
4:1 - ScrolLock ;
5:1 - NumLock ;
6:1 - CapsLock ;
7:1 - Insert ;

. 7.1. - .
-
BIOS - 16 (. 8).
. DOS
. 0 .
.
1 - , ( 0 ) .

7. , ,

87

2 - - , 5
..
- .
. ESC
. .
CODE SEGMENT
ASSUME CS:CODE

ORG 10OH
BEGIN:
/
MOV ,0
MOV ,03
INT

; DH-, DL-
LOO:
;
MOV ,
INT 16H
/ ESC,
CMP AL,27
JZ EXIT
CMP AL,0
JNZ LOO
/ ,
,50 / ?
JNZ N01
CMP DH,24
/?
JZ LOO
INC DH
JMP SHORT EX

N01:
CMP
JNZ
CMP
JZ
DEC
JMP

AH,48H
N02
DH,0
LOO
DH
SHORT EX

/ ?

CMP
JNZ
CMP
JZ
DEC
JMP

AH,4BH
NO3
DL,0
LOO
DL
SHORT EX

/ ?

/?

N02;

/?

88

ASSEMBLER.

N03:
'CMP
JNZ
CMP
,JZ
INC

AH,4DH
LOO
DL>79
LOO
DL

/ ?
/?

EX:
/
/ DH,DL
XOR ,
/
MOV ,02
INT 10H
/
JMP LOO
EXIT:
MOV AH,4CH
INT 21H
CODE ENDS
END BEGIN
Puc. 7.2. .
.
40. .
1 ( ). 1.
60. : ASCII ( 0, ), - - ( ). , .
, 1 1
( 1 2 1)
1 30, 1 - 60. ,
, :
1. , . , 2, .
2. , 1. - . ,
0, .
3. 1 60, 30,
2.
, 18. , , 1 1 . .
18

9. . ,
, 9.

7. , ,

CLRBUF

89

PROC

CLI

PUSH
PUSH
MOV
MOV
MOV
MOV

AX
ES
AX,40H
ES,AX
AL,BYTE PTR ES:[1CH]
BYTE PTR E S : [ 1 A H ] , A L

POP
POP
STI
RET

ES
AX

CLRBUF

ENDP
. 7.. .

. 7.4 .
ASCII CL, - . , .
IN_BUF PROC
CLI
PUSH ES
PUSH SI
PUSH DI
MOV DI,40H
MOV ES,DI
MOV DI,ES: [1CH] ;
MOV SI,ES: [1AH] ;
CMP DI,60
JZ
SPEC
ADD DI,2
CMP DI,SI
JZ
FUL
/ ?
MOV ES: [DI-2],CL
MOV ES: [DI-1],CH
JMP SHORT EN
/
SPEC:
CMP SI, 30
JZ
;
FUL
MOV ES: [DI],CL
MOV ES: [DI+1],CH
MOV DI,30
EN:
MOV ES: [1CH],DI

90

ASSEMBLER.

FUL:
POP
POP
POP

DI
SI
ES

STI

RETN
IN_BUF ENDP
Puc. 7.4. , .
, . , (CLI) .
. 17
.
(. 7.5). CTRL, ALT, F1.
CODE SEGMENT
ASSUME CS:CODE
ORG 100H

BEGIN:
;
MOV ,
INT 16H
CMP AL,0

JNZ BEGIN
; -
CMP ,94
; Ctrl F1
JZ PROV
,104
; Alt F1
JZ PROV
JMP SHORT BEGIN
PROV:
; Ctrl Alt
MOV AX,40H
MOV ES,AX
TEST BYTE PTR ES:[17H],00000100B ;
; Ctrl
JZ BEGIN
TEST BYTE PTR ES: [17H],00001000 ,-
; Alt
JZ BEGIN
EXIT:
MOV AH,4CH
INT 21H
CODE ENDS
END BEGIN
Puc. 7.5. CTRL, ALT, Fl.

7. , ,

91

, Ctrl F1 Alt F1
. , ,
. , , , F1. ,
Ctrl Alt. 9,
. , - F1, .
, ,
. ,
MS DOS Ctrl CtrlBreak " "?
, , , ,
, . , . ,

.
DOS, BIOS .
DOS . :
1. Ctrl Break (Ctrl ) - , , .
2. DOS.
CONFIG.SYS BREAK OFF ( ) BREAK ON
( ). , , BREAK. , DOS , . ,
DOS -. ,
,
". , , . 1.
Ctrl Break Ctrl DOS INT
23. 23-
( MS DOS). , 23
(. 9) ,
- IRET. Ctrl Break (Ctrl ).
- .
, Ctrl Break.
9- .
19

- .

92

ASSEMBLER.

1. , , :
MOV BYTE PTR CS:[MEM],3
IRET
MEM - . 3 , Ctrl Break.
.
MEM 3 MS DOS INT 23H. Ctrl
. MS DOS. ,
- 3. MS DQS, INT 23H. Ctrl Break, MEM 3, Ctrl
3 ( - - ).
. 1 , IRET.
Ctrl . 3
16-, 9- . , 9- , , ,
Ctrl. , . , Ctrl Break, , MS DOS
(,, 9).

.
. , ,
( , ) -
. , , , , .. ,
, . . : EGA VGA-. BIOS . 0
127 - . 128 255
. . . , 44. .
- 20 . , . , 20

, - ,
.

7. , ,

93

, , . -.
,
.
ASCII. . . ,
127 (
). ,
( , 0
). 1 .
, , . ,
. , :
MOV ,
INT

. -

. , AL 80H.
. 7.5 , ( 65) . 0 11 1 .
11 1 - , ,
.
CODE SEGMENT
ASSUME CS:CODE
ORG 100H
BEGIN:
JMP BEG

; , 65
FONT:
DB 11111111
DB 10000001
DB 10000001B
DB 10000001B
DB 10000001B
DB 10000001B
DB 10000001B
DB 10000001B
DB 40000001
.
,.-...
.
.
DB 10000001B

94

ASSEMBLER.
DB
DB
DB
DB

10000001
10000001
10000001B
11111111B

BEG:
; - .
;?
PUSH CS
POP ES
MOV BP,OFFSET CS:FONT
;ES:BP
MOV CX,1
;
MOV DX,65
;
MOV BL, 0
; 0,
MOV ,14
; 14 ()
MOV AL,0
/
MOV ,11
,- 11
INT 10H
;
MOV ,4
INT 21H
CODE ENDS
END BEGIN
. 7.6. (65).

. .
.
VGA-. - 21.
VGA- 32 .
. CGA- 16, Hetcules'a
4. , .
, ,
. : , . , , .
- . . .
, 7, 3-. , 800,
2

' CGA - . , , - .

7. , ,

95

. , .
, VGA- 7 3 .
, , , , , . , .
AL 0 VGA, 1 EGA, 2 CGA, 3 - MDA, 4 - Hercules (HGC).
WHAT_AD
PROC
PUSH DX
PUSH BX
'
.
PUSH CX; 1 - VGA
XOR AL,AL
.
.<
,'.
MOV ,1
INT 10H
CMP AL,1AH
JNZ NO_VGA
XOR AL,AL
JMP SHORT EXIT
NO_VGA:
; 12 - EGA
MOV , 12
MOV BL,10H
INT
CMP BL,10H
JZ
NO_EGA
MOV A L / 1
JMP SHORT EXIT
NO_EGA:
; CGA
,
MOV DX,3D4H
CALL SEARCH_6845
JC NO_CGA
'
MOV
AL,2

JMP SHORT EXIT


NO_CGA:
:
; MDA
M O V DX,3B4H
....CALL SEARCH 6845
NO_MDA
JC
MOV AL,3
JMP SHORT EXIT
N0__MOA:
MOV AL, 4

96

ASSEMBLER.

EXIT:
POP CX
POP BX
POP DX
RET
WHAT_AD ENDP
,- 6845
; ,
; ,
; OFH, CGA MDA
SEARCH_6845 PROC
MOV AL,OFH
OUT DX,AL
INC DX
IN AL,DX
MOV AH,AL
MOV AL,66H
OUT DX,AL
MOV CX,100H
DELAY:
LOOP DELAY
IN AL,DX
XCHG AH,AL
OUT DX,AL
CMP AH,66H
JZ
QUIT
STC
QUIT:
RET
SEARCH_6845 ENDP
PMC. 7.7. .
, , , .
, , , " ", .

VI.
. ,
, . , [5].

7. , ,

97

,
. MS DOS - 5. , .
BIOS . 17. ,
( LPT1, LPT2, LPT3), DOS - LPT1. , (. [5,13]).
. , .. . , INT 17, , .
. 7.7 , .
. .
, . .
DS:[81H] , . DS:[80H] ,
. , DS:[81H]
. - ,
, , (
).
( DL) , .

. 400 ,
. ,
0 17.
.
( ) 40:08. .
, . 1, . , 2.
CODE SEGMENT
ASSUME CS:CODE
ORG 10OH
BEGIN:

JMP BEG
TEXT1 DB ' . ' , 1 3 , 1 0 , ' $ '
4 - 4072

98

ASSEMBLER.

2 DB
DB
PATH DB
BUF
DB
PORT DW
PRIZ DB
COUNT DW
BEG:
XOR
XOR
MOV
LOO:
CMP
JZ

' .',13,10,'$'
' . ?(Y/N)', 13,10,'$'
80 DUP(O)
/
160 DUP{?)
/
?
;
0
/
?
/
SI,SI
DI,DI
DL, 1

BYTE PTR [81H+SI],ODH


NO_PAR

MOV AL,[81H+SI]

CMP A L , ' '


/
JZ SPACE
XOR DL,DL
/
MOV [PATH+DI],AL
/ PATH
INC DI
JMP. SHORT L001
SPACE:
OR DL,DL
/ DL=0,
JZ NO_PAR
L001:
INC SI
JMP SHORT LOO
NO_PAR:
OR SI,SI
/
JNZ CONT
/,
MOV DX,OFFSET TEXT1
MOV AH,9
INT 21H
JMP EXIT
CONT:
/
LEA DX,PATH
MOV AX,3DOOH
INT 21H
JNC CONT1
/ , -,
MOV DX,OFFSET TEXT2
MOV ,9

7, , ,

99

INT 21H
JMP SHORT EXIT
CONT1:
MOV BX,AX
; BX
;
/ LPT1
MOV ,40
/ 40:08
MOV ES/AX
MOV DX,ES:[8H]
INC DX
; 1
MOV PORT,DX
/
PR_CONT:
MOV DX,OFFSET BUF / BUF
/160
MOV CX,160
MOV AH,3FH
INT 21H
CMP AX,0
JZ CLOSE
/ ,
MOV COUNT,AX
/ - COUNT
/
CMP AX,CX
JZ NORM
/ 1,
MOV PRIZ,1
NORM:
LEA SI,BUF
N1:
XOR CX,CX
MOV DX,PORT
NORM2:
IN AL,DX
/
/
TEST AL,00010000B
JZ N2
TEST AL,00001000B
JZ N2
TEST AL,10000000B
JNZ NORM1
N2:
CMP CX,400 / 400 ,
JZ
PAUSE / -
INC CX
JMP SHORT NORM2
NORM1:
/
XOR ,
4*

100

ASSEMBLER.

XOR DX,DX
/ LPT1
MOV AL, [SI]
; AL
INT 17H
;
CMP AH,1
; time-out
JZ N1
; ,
INC SI
;
DEC COUNT
;
JNZ N1
; 0,
CMP PRIZ,1
;
JNZ PR_CONT
; ,
;
CLOSE:
MOV AH,3EH
INT 21H
EXIT:
MOV AH,4CH
INT 21H
;
;
; Y, DOS
PAUSE:
MOV ,9
LEA DX,TEXT3
INT 21H
MOV AH,0
INT 16H
CMP AL,'Y'
JZ CLOSE
CMP AL,'y1
JZ CLOSE
JMP SHORT N1
CODE ENDS
END BEGIN
. 7.8. .
17 . .
, . .
- , .
. .
. . :

101

7. , ,

:
3:0=
4:0=
5:1= " "
6:0=

7:0= ,

. . :
6

:
0: (. )
1:1=
( MS DOS
)
2: ^
3:1=
( )
4:1= ;

. ,
. , . ( ) , .
1. .
2. - 0 ,
. 11, 10.
3. , 3-5 . ,
.
4. 7. , 1.

102

ASSEMBLER.

, , . 2 J7H. 17
- , '. .
, 7- 4-. ,
7 , 4. , 7.

V.
,
, .
, . , " ".
[5] (. [9,13]). 23.
,
.
MS DOS. , , 1, 1, 32, 52.
, DOS, : ,
.
BIOS. 11, . 1, 1 , .
. DOS, 1 , 25 (.
14).
BIOS. BIOS 2,
[13]. , EGA
, ( , 11), .
-.
. . [5]. - 9.

8.
MS DOS.
- ; - .
.

, , ,
MS DOS .
. .
.
, FCB. , DOS .
.
. [5].
MS DOS
. MS DOS
:.
1. , ( ), .
. 0.
2. , -
5 256. .
PSP , 18 . 20 ,
20 . , FFH, . . 19 . ,
PSP 32 () , 34 (
18 PSP).
3. .
4. , DOS ().
, ,
, . , ,
. , , . , . , . . , ,

104

ASSEMBLER.

, .
,
(, , ).
. MS DOS 68,
, , , .
,
. .
, .
1.

. .
LEA DX,PATH ; : :\\,
; ,
MOV A L , 2
;
; 0 , 1
MOV ,
;
INT 21H
;
JC ERRO
;, ,
; ,
;

, , ( , ). , .
.
CONFIG.SYS: FILES=N. 5 255.
, (8
, , . 6). , , , ( ) 20, . 5 , , ,
15 . ,
.
2. . 1
( ), :
) ;
) (, , ), , 0 32 (,
32 , BACKUP
). , , , . , , ,
. , , 5, ,
, , , .

8. MS DOS

105

3. .
MOV ,

;
;
/
; ,

INT 21H
JC ERROR

. ,
.
4. . , . 0 L-1, L
. 0.
( ). , ( . 6).
MOV , 4 0
LEA DX,BUF
MOV , 5 0 0
JC ERROR

;
;
;
;

( 3FH) .
. <, , (
!). ,
, .
,
. 42, . .

42


CX:DX :
AL

0 + CX:DX,
1 + CX:DX,
2 + :DX

CX*65536+DX

, , AX:DX .
: DX
AL=2, AX:DX .
, , . , , DOS 7.

ASSEMBLER.

106

,
: 1. , 2. , 3. , 4. , 5. , 6.
( ) , 7. , 8. , 9. . , , .

II
, (. 8.1).
. ,
13,10.
. , 10.
13 .
10,13, .
DATA
PATH
BUF
CX_
DX_
DATA
SSEG

SEGMENT
DB "PRIMER.TXT",
; ( )
DB ?
;
DW ?
/
DW ?
; DX
ENDS
SEGMENT STACK
DB 200 D U P ( ? )
SSEG ENDS
CODE SEGMENT
ASSUME CS:CODE, DStDATA, SS:SSEG
BEGIN:
MOV AX,DATA

MOV DS,AX
;DS
;
MOV AX,3DOOH
LEA DX,PATH
INT 21H
; ,
JC EXIT
; ,
MOV ,
XOR ,
XOR DX,DX
MOV AX,4202H
INT 21H
; ( 13,10)
MOV CX,DX
MOV DX,AX
MOV AX,4200H
SUB DX,3

8. MS DOS

SBB
MOV
MOV
INT

,
CX_,
DX_,DX
21H

LOO:
;
MOV AH,3FH
LEA DX,BUF
MOV CX,1
INT 21H
/,
CMP BUF,10
JZ OUT_STR
;
SUB DX_,I
SBB _,
MOV DX,DX_
MOV CX,CX_
MOV AX,4200H
INT 21H
JMP SHORT LOO
;
OUT_STR:
MOV AH,3FH
LEA DX,BUF
MOV CX,1
INT 21H
CMP BUF,13
; ?
JZ CLOSE
CMP AX,CX
; ?
JNZ CLOSE
;
MOV DL,BUF
MOV AH,2
INT 21H
JMP OUT_STR
CLOSE:
;
MOV AH,3EH
INT 21H
EXIT:
MOV AH,4CH
INT 21H
CODE ENDS
END BEGIN
. 8.1. .

107

108

ASSEMBLER.

( , , ). , - , .. ,
.
DATA SEGMENT
PATH DB "*.*",
DTA DB 50 DUP{?)

;
;
; 4 4FH

DATA ENDS
SSEG SEGMENT STACK
DB 200 DUP(?)
SSEG ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:SSEG
BEGIN:
MOV AX,DATA
MOV DS,AX
/ DTA
MOV AH,1AH
LEA DX,DTA
INT 21H
; DTA,
/ PSP 80
;
CALL FIND_F
JC
EXIT
; -
DIR:
;
CALL FIND_N
JC
EXIT
;
CALL OUT_NAME
JMP SHORT DIR
;
EXIT:
MOV AH,4CH
INT 21H
;
FIND_F PROC
LEA DX,PATH
MOV AH,4EH

8. MS DOS

109

; , ,
; ,
;
MOV ,110101
INT 21H
RET
FIND_F ENDP
;
FIND_N PROC
; 4 DTA
;
LEA DX,DTA
MOV AH,4FH
INT 21H
RET
FIND_N ENDP
;
; DTA, 1
OUT_NAME PROC
MOV
MOV , 2
OUT_S:
MOV DL,[DTA+BX]
CMP DL,0
KON
JZ
INT 21H
INC BX
JMP SHORT OUT S
KON:
;
MOV DL,13
INT 21H
MOV DL,10
INT 21H
RET
OUT_NAME ENDP
CODE ENDS
END BEGIN
Puc. 8.2. .
.8.3 , : PRIMER2.TXT PRIMER1 ..
, .

ASSEMBLER.

110

, . :
.
DATA SEGMENT
1 DB 'PRIMER1.TXT', 0 ;
2 DB 'PRIMER2.TXT', 0 ; ( )
HANDL1 DW ?
;
HANDL2 DW ?
/
BUFER DB 1000 D U P ( ? )
;
EOF DB 0
; 1,
/
DATA ENDS
SSEG SEGMENT STACK
DB 200 D U P ( ? )
SSEG ENDS
CODE SEGMENT
ASSUME CS:CODE,
BEGIN:
MOV AX,DATA

DS:DATA,

SS:SSEG

MOV DS,AX
;
MOV ,
MOV AL,0
LEA DX,PATH1
INT 21H
JC EXIT
MOV HANDL1,AX
;
MOV ,
MOV AL,1
LEA DX,PATH2
INT 21H
JC CLOSE1
MOV HANDL2,AX
;
MOV AH,42H
MOV BX,HANDL2
XOR CX,CX
XOR DX,DX
MOV AL,2
INT 21H
/
LEA DX,BUFER

'"'.

8. MS DOS

111

MOV ,1000
;

LOO:
;
MOV BX,HANDL1
MOV ,3FH
INT 21H

CMP AX,CX
JZ
NORM
MOV CX,AX

;<1000
;

MOV EOF,1

NORM:
;
MOV BX/HANDL2
MOV A H , 4 O H
INT 21H

CMP EOF,0
JZ

LOO

;
CLOSE2 :
MOV AH,3EH
MOV BX,HANDL2
INT 21H

;
CLOSE1:
MOV AH,3EH
MOV BX,HANDL1
INT 21H

; DOS
EXIT:
MOV AH,4CH
INT 21H
CODE ENDS
END BEGIN
. 8.. .

, . , ,
. 7.6 ( 7). . , 255 . ,
.

112

ASSEMBLER.

CODE SEGMENT
ASSUME CS:CODE, DS:CODE
ORG 100H
BEGIN:
JMP BEG
TEXT1 DB ' .',13,10,'$'
TEXT2 DB ' .',13,10,'$'
PATH DB 80 DUP(O)
;
BUF
DB 160 DUP(?)
/
BEG:
;
XOR SI,SI
XOR DI,DI
MOV DL,1
LOO:
CMP BYTE PTR [81H+SI],ODH
JZ NO_PAR
MOV AL,[81H+SI]
CMP AL,' '
JZ SPACE
XOR DL,DL
MOV [PATH+DI],AL
INC DI
JMP SHORT L001
SPACE:
OR
DL,DL ; DL=0
JZ NO_PAR
L001:
INC SI
JMP SHORT LOO
NO_PAR:
OR SI,SI
;
JNZ CONT
/,
MOV DX,OFFSET TEXT1
MOV AH,9
INT 21H
JMP EXIT
/
CONT:
/
LEA DX,PATH
MOV AX,3D02H
INT 21H

8. MS DOS

113

JNC NORM
MOV DX,OFFSET TEXT2
MOV AH,9
INT 21H
JMP EXIT
NORM :
MOV BX,AX
XOR DI,DI ; DI
POVT:
;
LEA DX,BUF
MOV ,3FH
MOV CX,160
/
INT 21H
MOV AH,AL
LEA SI,BUF
CMP AL,0
;
L02 :
JZ ZER
CMP BYTE PTR [SI],97
JB L01
CMP BYTE PTR [SI],122
JA L01
SUB BYTE PTR [SI],32
L01:
INC SI
DEC AL
JMP SHORT L02
ZER:
PUSH AX
;
MOV AX,4200H
XOR CX,CX
MOV DX,DI
/
INT 21H
;
; , ,
; 160
MOV ,40
POP
PUSH
MOV CL,CH
XOR CH,CH

114

ASSEMBLER.

LEA DX,BUF
INT 21H

'

;,
POP AX
MOV AL,AH
XOR ,
ADD

DI,

CMP AL,160
JZ
POVT
;
MOV ,

INT 21H
EXIT:
RET
CODE ENDS
END BEGIN

. 8.4. .
III

.
,
( 6, . 6.1). 45 46. .
..
:
-45,
- (, ).
:
( )
- .
.
:
-46,
- ,
- .
:
- , .
10 . , ( )

8. MS DOS

115

, .
. .
1. (1).
MOV ,45
MOV ,1
INT 21H
.
2. .
3. .
MOV ,46
MOV ,1
INT 21H ;
4. .
.
5. .
6. 1 (. . 1).
7. , . 1.
, , .
,
. . .
, , , .
- .8.5.
DATA SEGMENT

PATH DB ' 1 . T X T ' , 0 ;


BUF DB ?
;
DATA ENDS
STA SEGMENT STACK
DB 100 D U P ( ? )
STA ENDS
CODE SEGMENT
ASSUME CSrCODE, DS:DATA, SS:STA
BEGIN:
MOV AX,DATA

MOV DS,AX
;
MOV AH,3CH
LEA DX,PATH

MOV cxyo
INT 21

'

116

ASSEMBLER.

JC KONEC ; -
MOV , /
;
LEA DX,BUF
READ:
;
PUSH
MOV ,0
MOV ,1
MOV AH,3FH
INT 21H
POP
JC CLOSE / ,
MOV SI,CX
MOV DI,AX
MOV CX,AX
;
MOV AH,40H
LEA DX,PATH
INT 21H
JC CLOSE ; ,
CMP CX,AX
JNZ CLOSE
CMP SI,DI
JZ READ
;
CLOSE:
MOV AH,3EH
INT 21H
KONEC:
MOV AH,4CH
INT 21H
CODE ENDS
END BEGIN
Puc. 8.5. ,
:
1 .. , Ctrl+C. ,
.
MS DOS, . INP.EXE. : DIRJINP -
1 . .

8, MS DOS

117

, DOS.
7.

IV.
,
( 15) (. ). :
1. CONFIG.SYS FILES=N, N -
. , ,
.. PSP 20 .
2. . .
DSEG SEGMENT
NUM DB
;
DESC DB 50 DUP(OFFH)
/
; 4- 5-
;
PATH DB ' F I L E ' , 0 , 0 ,
DSEG ENDS
STSEG SEGMENT STACK
DW 50 DUP(?)
STSEG ENDS
CSEG SEGMENT
ASSUME CS:CSEG, DS:DSEG, SS:STSEG
BEGIN:
MOV AX,DSEG
MOV DS,AX
MOV NUM,0
;
CALL OPENJTAB
;
XOR ,
LEA DX,PATH
; SI+4
MOV SI,DX
MOV BL,65
; 40
LOO:
MOV ,

MOV [si+4],BL
INT 21H

'

'

,;; : "

'""

118

ASSEMBLER.

JC

_END

; ,

CMP B L , ' Z '


JNZ N0

INC SI
; SI+5 5-
MOV BL,65
NO:
INC BL
INC NUM
CMP NUM,40
JNZ LOO
; ,
__END:
/,
MOV AL,NUM
CALL DISP_BYTE
MOV AX,4COOH
INT 21H
;
; AL
DISP_BYTE PROC NEAR
XOR ,
MOV BL,100
DIV BL
MOV SI, AX
MOV AL,AH
XOR AH,AH
MOV BL,10
DIV BL
MOV BX,AX
MOV DX, SI
MOV AH, 2
ADD DL,48
INT 21H
MOV DL,BL
ADD DL,48
INT 21H
MOV DL,BH
ADD DL,48
INT 21H
RETN
DISP_BYTE ENDP
;
OPEN TAB PROC NEAR

8, MS DOS

119

/
MOV ,20
LEA DI,DESC
MOV SI,18H
LOO1:
MOV AL,ES:[SI]
MOV D S : [ D I ] , A L
INC SI
INC DI
LOOP L001
;
;
MOV WORD PTR ES:[32H],50
;
MOV E S : [ 3 6 H ] , D S
MOV WORD PTR ES:[34H],OFFSET DS:DESC
RETN
OPENJTAB ENDP
CSEG ENDS
END BEGIN
Puc. 8.6. .
40 ,
CONFIG.SYS FILES=N, N>45. . 40.
OPENJTAB. ,
15 ( ). . , MS DOS, .
,
(. 11).
67 DOS (. 7).

( ES).

9. .
, ,
..
.

I.
- .
INT CALL . ,
. , . , , , .
, ,
, ( ,
..) .. , ,
, , , - . - NMI. CLI.
NMI, 26.
CALL INT .
? .
1, ( ) . , MS DOS. , 8 (.. 0:8*4, . 2) .
18.2 , . ( 21, 16, .)
( 1, 9, 8 .). , , .. . ? ,
, , , .
.
: , ?
. . . 9.1 .
, . 9.1, () .
, - . ,
, , . ,
21 . , MS DOS -

9.

121

. .
, . , , , , . , , ,
, (), . .

(IRET)

()

(IRET)

()

(IRET)

()

. 9.1. .

122

ASSEMBLER.

.
: OJTNT S_INT:
O_INT - , ,
S_INT - , ; , .
:
JMP DWORD PTR DS:[0_INT]
, .
:
PUSHF
CALL DWORD PTR DS:[O_INT]
, ( ) 23. PUSHF ,
IRET. ,
. , ,
CALL, ,
, , .
(. 12).
.
(. ) INT. , 16.
. 16 , , FEH.
INT FEH.
CALL (. ).
:
1) DOS 25H 35;
2)
.
, .
22
23

, RETF .
, ( ),
.

9.

MOV AH,35H
MOV AL,5
INT 21H
MOV OLD_S,ES
MOV OLD_0,BX
MOV AH,25H
MOV DX,OFFSET P_5
MOV AX,SEG P_5
MOV DS,AX
INT 21H

123

;
; 5 ( ) :
/
; ES:
/
/
/
/

, DOS.

CLI
/
MOV ,
MOV E S / A X
MOV DX,ES:[5H*4]
/ DX
MOV BX,ES: [5*4+2] /
MOV OLD_S,BX
/
MOV OLD_0,DX
/
MOV DX,OFFSET P_5
MOV AX,SEG P_5

MOV E S : [ 5 H * 4 ] , D X
MOV ES:[5*4+2],
STI

/
/

, , ,
. ,
, . MS DOS
.

.
. . MS DOS
, , .
, ,
"" . 23 24 ( 22) - ,
, .

124

ASSEMBLER.

7 , 23.
Ctrl Break (Ctrl ), ,
- IRET. . , ,
(. 7).
2424. , , ( , ..). . 24
.
. , AL : 0 -
(); 1 - ( ); 2 -
23; 3 - .
, , ,
. , -
MS DOS. : AL=3 - MS DOS . . , . MS DOS .
24.
. .9.1
, ESC.
Ctrl Break, Ctrl , ,
MS DOS ( 0 ). , .
Ctrl -, ,
.
,
, . ,
, (!):
AND

BYTE PTR ES:[417H],11111011 .

Ctrl .
PrtSc Pause. ( 5) , IRET. Pause 0:418 (. 7, ).
60
61. . 61,
. , .
.
. ,
, .

9,

125

7- , -
. 60
- .
DATA

SEGMENT

;
;
OLD_09_0 DW ?
OLD_09_S DW ?
; Ctrl Break
OLD_1B_0 D W ?
. , OLD_1B_S DW ?
;
OLD_05_0 DW ?
OLD_05_S DW ?
DATA ENDS
SSEG SEGMENT STACK
DB 200 DUP(?)
SSEG ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:SSEG
BEGIN:
MOV AX,DATA
MOV DS,AX
; 09, 1BH, 05
MOV AX,351BH
INT 21H
MOV OLD_1B_S,ES
MOV OLD_1B_0,BX
MOV AX,3509H
INT 21H
MOV OLD_09_S,ES
MOV OLD_09_0,BX
MOV AX,3505H
INT 21H
MOV OLD_05_S,ES
MOV OLD_05_0,BX
/
PUSH DS
PUSH CS
POP DS
MOV DX,OFFSET CS:INT09
MOV AX,2509H
INT. .2.1H
,
..
MOV DX, OFFSET CS:,INT1B
MOV AX,251BH

126

ASSEMBLER.

INT 21H
MOV DX,OFFSET CS:INT05
MOV AX,2505H
INT 21H
POP DS
;, ESC
L001:
MOV DL,48
MOV , 2
INT 21H
MOV ,06
MOV DL,OFFH
INT 21H
JZ LO01
CMP AL,27
JNZ LO01
/
PUSH DS
POP ES
MOV DX,ES:OLD_0 9_0
MOV DS,ES:OLD_09_S
MOV AX,2509H
INT 21H
MOV DX,ES:OLD_1B_0
MOV DS,ES:OLD_1B_S
MOV AX,251BH
INT 21H
MOV DX,ES:OLD_05_O
MOV DS,ES:OLD_05_S
MOV AX,2505H
INT 21H
; DOS
MOV AH,4CH
INT 21H
;
INTO9 PROC FAR
PUSH AX
PUSH ES
PUSH DS
/ DS ,
/ ,
/ DS
; (, DOS)
MOV AX,DATA
MOV DS, AX
MOV AX,0

127

9.

MOV ES,AX
IN AL,60H
CMP AL,46
;-
JNZ LOO
TEST BYTE PTR ES:[417H],4 /, Ctrl
JZ
LOO
; ,
/ ,
IN
AL,61H
;*
MOV AH,AL
;*
OR
AL,80H
;*
OUT 61H,AL
;*
MOV AL,AH
;*
' .',
f
OUT 61H,AL
;*
/ ,
;
MOV AL,20H
;*
OUT 20H,AL
/. *
POP DS
r. *
.*
POP ES
r
.*
POP AX
1
IRET

.*

LOO:
PUSHF
CALL DWORD PTR DS:[OLD_09_0]
AND BYTE PTR ES: [418H],11110111B
;Pause
POP DS
POP ES
POP AX
IRET
INT09 ENDP
/ Ctrl Break
INTIB PROC FAR
IRET
INT1B ENDP
/ PrtScr
INT05 PROC
IRET
INT05 ENDP
CODE ENDS
END BEGIN

. 9.1. .

128

ASSEMBLER,

IV.
, (Intel 8259) (. 9). , , .. , , (
..). . ,
- , , INT.
. , , , . ,
. ,
. , , , , , - CLI.
, - ,
STI.
( ). , (.
. 9.1).
- 08. , .
. .

IRQO

IRQ1

IRQ2

OAH

*IRQ8

70H

(AT)

*IRQ9

71H

*IRQ10

72H

*IRQ11

73H

*IRQ12

74H

*IRQ13

75H

. (AT)

*IRQ14

76H

(AT)

*IRQ15

77H

9.

129

IRQ3

COM2 ( XT 1 )

IRQ4

1 ( XT COM2)

IRQ5

LPT2 ( XT )

IRQ6

IRQ7

OFH

LPT1

. 9.2. .
, -
, . ,
.
, AT , XT.
, AT 8259. - , - .
. 8, - 70. ,
1+8, .. 9.
(. 20). 20-21, -1.
. 21 -
( AT 1 ). , ,
, :
MOV A L , 0 0 0 0 0 0 1 0
OUT 2 1 H / A L

.
(sic!) (. . 9.2) (), ..
, :
MOV AL,20H
OUT 20H,AL (OUT OAOH,AL - ).

(. . 9.1).
( ) . , IRQ8 ( ) .
1
.
. 9.3 .
5 - 4072

ASSEMBLER.

130

-X)

->s

->

20

20H

20

. 9.3. .
.9.3.
( 2)
.
, . . ,
. , , . ,
. . ,
.
, .
, ( CLI). 1,
, , , . . , :
1. . , - .
2. .
.
3. -
CLI.
,>
4. .

9.

131

, . ,
. , , , , .. CLI. , ,
STI.
20 20 (. ).
, 8,
- 70. .
. 26 , . , . , .
1. 20()11().
2. 21 ( 1 ).
3. , , . 2. 2 4,
21 ( 1).
4. 21 ( 1 ) 1.
26.
:
1. , , , .
2. , , .
.
3. :
) (CLI),
) (. ),
) - .

V.
, .
( ) , , . .

752

ASSEMBLER.

25


25. ,
IRET.
(. [3]), (. 9.5).


. .
-
, 1 .

.
. ,
.
, IRET.

18.2 .
- .

. 1.
,
.

.
.
, Shift, Alt, Ctrl, CapsLock ..

OCH

, 1.
.

, COM2.
.

OFH

. ,
. ,
.


.
.

11

().

.
-.

14

8086/8088 , .

9.

15

- (. 5)

16

. 9
.

1 7

.
.

.

1 8

19

Control_Break.

. 8-.
.
: , ,
..
;

21

DOS.
.
.

23

Ctrl Break. 7.

24

.
.

25-26

DOS - .
.

27

" " .
.

28

.
.

2FH

.
"" .
MS DOS PRINT.EXE .


-. , . .
, , .
,

134

ASSEMBLER.

-
.
. , , (-) ..
. , , . . , ( 08 1). , ' PRINT.EXE.
.
INT_PRINT PROC
{ }
MOV DS,SEG BUF
;DS ,
CMP LEN_BUF,0
;
JZ
QUIT
CALL OUTPUT
; , ,
;
JC
QUIT
CALL MOV_POINT
;
;
QUIT:
{ }
IRET
INT_PRINT ENDP
. , . , (. 7). . . .
. . ( 0).
,
. , ,
, 4 (. 7).

VI.
( ). ,
, , .
.
, - -

9.

135

, .
.
. . .
DATA SEGMENT
;
OLD_VEC_OFF DW ?
OLD_VEC_SEG DW ?

STR DB 0 , 0 , 0 , 1 3 , 1 0 , ' $ ' /


DATA ENDS

ST1 SEGMENT STACK


DB 200 DUP(?)
ST1 ENDS
CODE SEGMENT
ASSUME CSrCODE, DSrDATA, SS:ST1
BEG:
;
MOV AX,DATA
MOV DS,AX
MOV AX,ST1
MOV SS,AX
;
MOV AX,
MOV ES,AX
MOV BX,WORD PTR ES:[OCH*4]
MOV DS:OLD_VEC_OFF,BX
MOV BX,WORD PTR ES:[OCH*4+2]
MOV DS:OLD_VEC_SEG,BX
CLI
.
LEA BX,CS:INT_AD
MOV ES:[OCH*4],BX
PUSH CS
POP BX
MOV ES:[OCH*4+2],BX
; , -
MOV AL,0
OUT 21H,AL
/
MOV DX,ES:[400H] ; 1.
ADD DX,3
IN AL,DX

136

ASSEMBLER.

AND AL,01111111
OUT DX,AL
; 7-
SUB DX,2
MOV AL,1
OUT DX,AL
/
STI
;
MOV ,
INT 16H
/ 1
CLI
MOV BX,DS:OLD_VEC_OFF
MOV WORD PTR ES: [OCH*4],BX
MOV BX,DS:OLD_VEC_SEG
MOV WORD PTR ES: [OCH*4+2],BX
MOV AL,0
OUT DX,AL
STI
; DOS
MOV AH,4CH
INT 21H
;
INT AD PROC FAR
PUSH DS
PUSH AX
PUSH DX
PUSH ES
MOV AX, SEG STR
MOV DS, AX
MOV AX, 0
MOV ES, AX
MOV DX, ES: [400H]
IN
AL,DX ;
CALL WRI_BYTE
;
MOV AL,20H
OUT 20H,AL
(
POP ES
POP DX
POP AX
POP DS
IRET
INT AD
ENDP

9.

137

/
WRI_BYTE PROC
PUSH AX

PUSH DX
; ASCII
XOR ,

MOV DL/10
DIV DL
/, DS (!)
; ,
ADD ,48
MOV DS:STR+2,AH
XOR ,
DIV DL
ADD AL,48
ADD ,48
MOV DS:STR,AL
MOV DS:STR+1,AH
/
LEA DX,DS:STR
MOV AH, 9

INT 21H
/
MOV BYTE PTR DS:STR,0
MOV BYTE PTR DS:STR+1,0
MOV BYTE PTR DS:STR+2,0
POP DX
POP AX
RET
WRI_BYTE ENDP
CODE ENDS
END BEG
. 9.4. - .
. 9.3 -.
, ,
1. COM2,
. . 1 0:400, COM2 - 0:402. . , . ,
. ( 0).
, 3, . ,

138

ASSEMBLER.

.
, .. (. ).

VII.

. , .
.
:
) ASCII- XLAT
) 0: , 0
DATA SEGMENT
;
;ASCII ->
1 DB 48 DUP(O)
DB 0,1,2,3,4,5,6,7,8,9
DB 7 DUP(O)
DB 10,11,12,13,14,15
DB 26 DUP(O)
DB 10,11,12,13,14,15
DB 153 DUP(O)
; -> ASCII
TAB2 DB '0123456789ABCDEF1
; 4
MAX
DB 5 ; 4 + ()
DB ?
STROKA DB 4 DUP(?)
DB ?
MES
DB ' !', 13,10,'$'
;
OLD_INT_OF DW ?
OLD_INT_SEG DW ?
DATA ENDS
ST1 SEGMENT STACK
DW 50 DUP(?)
ST1 ENDS
CODE SEGMENT
ASSUME CSrCODE, DS:DATA, SSrSTl
/ ,
INT_0 PROC
;
LEA DX,MES

9.

139

MOV , 9
INT 21H
;
POP ES
MOV AX,OLD_INT_SEG
MOV ES:[2],AX
MOV AX,OLD_INT_OF
MOV ES:[0],AX
;
MOV ,401
INT 21H
INT_0 ENDP
BEGIN:
MOV AX,DATA
MOV DS,AX
/
XOR AX,AX
MOV ES,AX
PUSH ES
;
MOV AX,ES:[0]
MOV OLD_INT_OF,AX
MOV AX,ES:[2]
MOV OLD_INT_SEG,AX
PUSH CS
POP AX
/ ,
MOV ES:[2],
LEA AX,CS:INT_0
MOV ES:[0],AX
;
LEA SI,STROKA
;
CALL CLEARJSTR
LEA DX,MAX
MOV AH,OAH
;
INT 21H
MOV BL,MAX+1
/
CALL SHIF
CALL STR_NUM
/
CALL CLEAR STR

140

PUSH AX
CALL ENT
;
LEA DX,MAX
MOV AH,OAH
INT 21H
MOV BL,MAX+1
/
CALL SHIF
CALL STR_NUM
LEA SI,STROKA
MOV BX,AX
POP AX
XOR DX, DX
/
DIV BX
PUSH DX
CALL ENT
CALL NUM_STR
;
CALL PRINT_STR
POP AX
CALL NUM_STR
;
CALL PRINT_STR
/
POP ES
MOV AX,OLD_INT_SEG
MOV ES:[2],AX
MOV AX,OLD_INT_OF
MOV ES:[0],AX
_END:
MOV AX,4COOH
INT 21H
,-
/ 2 (1-)
/ - DS:SI -
; -
STR_NUM PROC
PUSH SI
ADD SI,3
MOV CX,2
LOO:
XOR AH,AH

ASSEMBLER.

9.

MOV AL, [SI]


LEA BX,TAB1
XLATB
MOV DI,AX
MOV AL,[SI]-1
LEA BX,TAB1
XLATB
MOV DL,16
MUL DL
ADD AX,DI
PUSH AX
SUB SI,2
LOOP LOO
POP AX
MOV CL,8
SHL AX,CL
POP BX
ADD AX,BX
POP SI
RETN
STR_NUM ENDP
;
;
; DS:SI
NUM_STR PROC
PUSH AX
MOV CL,8
SHR AX,CL
MOV BL,16
DIV BL
LEA BX,TAB2
XLATB
MOV [SI],AL
MOV AL,AH
LEA BX,TAB2
XLATB
MOV [SI]+1,AL
POP AX
AND AX,OOFFH
MOV BL,16
DIV BL
LEA BX,TAB2
XLATB
MOV [SI]+2,AL

141

142

MOV AL,AH
LEA BX,TAB2
XLATB
MOV [SI+3],AL
RETN
NUM_STR ENDP
;
ENT PROC
PUSH AX
PUSH DX
MOV DL,13
MOV AH,2
INT 21H
MOV DL,10
MOV AH,2
INT 21H
POP DX
POP AX
RETN
ENT ENDP
; '0'
;DS:SI -
CLEAR_STR PROC
PUSH SI
PUSH AX
MOV CX, 4
L002:
MOV BYTE PTR [SI],'0'
INC SI
LOOP L002
POP AX
POP SI
RETN
CLEAR_STR ENDP
;
; BL
;DS:SI -
/ 78 -> 0078
SHIF PROC
CMP BL,0
JNZ NO_ZER
RETN
NO_ZER:
PUSH SI

ASSEMBLER.

9.

143

XOR ,
MOV DI,SI
ADD DI,3
L001:
MOV AL,[SI][BXJ-1
MOV BYTE PTR [SI][BX]-1,'0'
MOV [DI],AL
DEC DI
DEC BX
JNZ L001
POP SI
RETN
SHIF ENDP
/
;DS:SI -
PRINT_STR PROC
MOV CX,4
MOV AH,2
L004:
MOV DL, [SI]
INT 21H
INC SI
LOOP LOO4
CALL ENT
RETN
PRINT_STR ENDP
CODE ENDS
END BEGIN
Puc. 9.5. ,
.
, ,
, .
1. 0 ( 0)
. 0. .
, . , 8088/8086 ( DIV IDIV),
. IRET : . .
( , ).

144

ASSEMBLER.

2. , ,
(. DOS OAH). CLEARJSTR SHIF . '0', 123 -> 0123,2->0002
.. STR_NUM NUM_STR .
3. , , XLAT.

VIII.
9, , , , .
. , - . -. 9 .
. 1.
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
ORG 100H
BEGIN:
MOV AH,9
LEA DX,TEXT1
INT 21H
;
MOV CX,10
CALL TIME
MOV AH,9
LEA DX,TEXT2
INT 21H
RET
TIME PROC
;
XOR AX,AX
MOV ES,AX
;
MOV AX,ES:[1CH*4]
MOV INTOFF,AX
MOV AX,ES:[1*4+2]
MOV INTSEG,AX
/
CLI
LEA AX,INT1C
,

' . ,
:

9.

MOV ES: [ 1 C H M J / A X
PUSH CS
POP AX

MOV ES:[1CH*4+2],AX
;
MOV COUNT,CX
MOV AH,2CH
INT 21H
MOV SEC,DH
STI
;
LOO:
CMP CS:COUNT, 0
JNZ LOO
/,
;
CLI
MOV AX,INTOFF
MOV ES:[1*4],
MOV AX,INTSEG
MOV ES:[1*4+2],
STI
RETN
TIME ENDP
INT1C PROC
MOV AH,2CH
INT 21H
CMP CS:SEC,DH
JZ CONT
DEC CS:COUNT
MOV CS:SEC,DH
CONT:
IRET
INT1C ENDP
/
SEC DB ?
;
COUNT DW ?
1 DB ' .. 10 .',13,10,'$'
TEXT2 DB '',13,10,'$'
INTSEG DW ?
INTOFF DW ?
CODE ENDS
END BEGIN
Puc. 9.6. .

145

146

ASSEMBLER.

, . 9.6, : ,
1, 18 ,
. , .
. , .
, , . , .

IX.
, ,
.. 24.
, . 9.7 . , ,
, , , , .
DATA SEGMENT

PATH DB " A : \ F I L E " , 0


; HANDLE DW ?
;
HANDLE DW ?

1 DB " ",13,10,"$"
2 DB " ",13,10,"$"
DB " ",13,10,"$"
DATA ENDS
STA SEGMENT STACK
DB 500 DUP(O)
STA ENDS
CODE SEGMENT
ASSUME CS:CODE, DSrDATA, SS:STA
BEGIN:
MOV AX,DATA
MOV DS,AX
/ 24
MOV AX,0
MOV ES,AX
LEA AX,CS:INT24
MOV ES:[24H*4],AX
MOV ES: [24H*4+2] , CS
INP:
LEA DX,TEXT1
CALL TEXTOUT
CALL INPUT
;

9,

CMP AL,27
; ESC
JZ
_END
;
MOV ,
LEA DX,PATH
MOV ,0
INT 21H
JNC DAL2
LEA DX,TEXT3
CALL TEXTOUT
;
JMP SHORT INP
DAL2:
MOV DS:HANDLE, AX
;
LEA DX,TEXT2

CALL TEXTOUT
INP1:
LEA DX,TEXT1
CALL TEXTOUT
CALL INPUT
LEA DX,TEXT2
;
MOV BX,DS:HANDLE
MOV CX,11
MOV AX,4000H
INT 21H
JNC DAL1
LEA DX,TEXTS
CALL TEXTOUT
;
JMP SHORT INP1
DAL1:
;
INP2:
LEA DX,TEXT1
CALL TEXTOUT
MOV BX,HANDLE
MOV AH,3EH
INT 21H
JNC _END
LEA DX,TEXT3
CALL TEXTOUT
;
JMP SHORT INP1
_END:
MOV AX,4COOH

147

148

ASSEMBLER.

INT 21H
INPUT PROC
"
, , M O V 'AH,0.

.
- . INT 16H
RET
INPUT ENDP
/ 24
INT24 PROC
MOV AL,1
IRET
INT24 ENDP
;
TEXTOUT PROC
MOV AH,9
INT 21H
RET
TEXTOUT ENDP
CODE ENDS
END BEGIN

''-'
,

:
''!'-''. ' ' ''"> ' "
'
..-../.- . ' ."
- .

-;

. 9.7. .
, , , ,
, . AL=1 , .. ,
. AL -. , , . , , , :
. ,
: , . .
4.0 MS DOS, , 6,
, .
, , . ,
, 59. :
?
,
, . :
1.

MS DOS (3 : IP,CS,Flags). IRET,


.
2. int 21H: AX,BX,CX,DX,SI,pI,BP,DS,ES.
3. int 21 (3 : IP,CS,Flags).

9.

149

X. .
,
, .
INI_KB .
RE_KB. INI_KB PAUSE, PRTSC, Ctrl Break, Ctrl , Ctrl Alt
Del. -. , .
CODE SEGMENT
ASSUME CS:CODE
PUBLIC INI_KB, RE_KB
;
INT_050 DW ?
INT_05S DW ?
INT_1BO DW ?
INT_1BS DW ?
INT_090 DW ?
INT 09S DW ?
;
/- Prtsc
_05 PROC
IRET
_05 ENDP
;- Ctrl Break
_1 PROC
IRET
_1 ENDP
SCAN DB ?
;-
_09 PROC
PUSH AX
IN AL,60H
MOV CS:SCAN,AL
PUSH ES
XOR AX,AX
MOV ES,AX
/ Ctrl Alt Del
TEST BYTE PTR ES: [417H],00000100B
JZ
PROD
TEST BYTE PTR ES : [417H],00001000B
JZ
PROD

ISO

ASSEMBLER.

AND
POP
JMP

BYTE PTR ES: [417H] , 11110111B


ES
TO INT9

PROD:

/ Ctrl
CMP CS:SCAN, 46
JNZ PRODI
TEST BYTE PTR ES: [417H],00000100B
JZ PRODI
POP ES
JMP SHORT EMUL
PRODI:
POP ES
TO_INT9:
PUSHF
CALL DWORD PTR CS:INT_090
PUSH ES
XOR AX,AX
MOV ES,AX
PAUSE
AND BYTE PTR ES: [418H],11110111B
POP
ES
'

POP AX
IRET
EMUL:
IN AL,61H
MOV AH,AL
OR AL,80H
OUT 61H,AL
MOV AL,AH
OUT 61H,AL
MOV AL,20H
OUT 20H,AL
POP AX
IRET
09 ENDP
(
INI_KB PROC FAR
CLI
PUSH AX
PUSH ES
XOR AX, AX

9.

MOV ES,AX
MOV A X , E S : [ 0 5 H * 4 ]
MOV CS:INT_050,AX
MOV A X , E S : [ 0 5 H * 4 + 2 ]
MOV CS:INT_05S,AX
LEA AX,CS:_05
MOV E S : [ 0 5 H * 4 ] , A X
MOV E S : [ 0 5 H * 4 + 2 ] , C S
/ *~ "

MOV
MOV
MOV
MOV
LEA
MOV
MOV

AX,ES:[1BH*4]
CS:INT_1BO,AX
AX,ES:[1*4+2]
CS:INT_1BS,AX
AX,CS:_1B
ES:[1BH*4],AX
ES:[1BH*4+2],CS

MOV AX,ES:[09H*4]
MOV CS:INT_0 90,AX
MOV AX,ES:[09H*4+2]
MOV CS:INT_09S,AX
LEA AX,CS:_09
MOV ES:[09H*4],AX
MOV ES:[09H*4+2],CS
POP ES
POP AX
STI
RETF
INI_KB ENDP
/
RE_KB PROC FAR
CLI
PUSH AX
PUSH AX
XOR AX,AX
MOV ES,AX
;
MOV AX,CS:INT_050
MOV E S : [ 0 5 H * 4 ] , A X
MOV AX,CS:INT_05S
MOV E S : [ 0 5 H * 4 + 2 ] , A X
/ "" *~

MOV
MOV

AX,CS:INT_1BO
ES:[1BH*4] ,AX

151

752

ASSEMBLER.

MOV
MOV

AX,CS:INT_1BS
ES:[1BHM+2],AX

MOV
MOV
MOV
MOV

AX,CS:INT_090
ES: [09H*4],AX
AX,CS:INT_09S
ES: [09H*4+2],AX

POP
POP
STI

AX
AX

RETF
RE_KB ENDP
CODE ENDS

END
Puc. 9.8. .

10.
.
,
, .

, EGA-,
.
27.
MS DOS Windows (. 24,25), , . BIOS
-
. , ..
. . , -
. . , , ,
, . , . : , .
, , , ,
. ,
.
, , .
, , ,
.
( VGA SVGA).
, , ,
.
, BIOS, VGA- (. [8]).
7 .

I.
1 .
.

:
- , AL - .

154

ASSEMBLER.

EGA VGA- 14-19( 17-19


VGA ).
16 - 640*350,16 .
.
-
AL - 0 - .
BL- ,
- (6 ). AL -1 - . - .
AL - 2 - .
ES:BX -17 ( 16,17- ).
AL - 3 - .
BL - 0 (16 - ).
BL -1 (8 + . ).
:

. Rr
(red), Gg - (green), - (blue). ,
, ( 0 3).
.
-
- .
DX - .
- .
AL - .
.
AH-ODH.
, AL .
( ).
-5
AL - ( 2).
. 10.1 BIOS.
, .
, . ,
, .

155

. ,
( ).
. .
, . , ,
.
CODE SEGMENT
ASSUME CS:CODE
ORG 100H

BEGIN:
;
MOV A X , 0 0 1 O H

INT 10H
;
MOV ,
MOV ,
MOV 31,120
/
MOV 01,50
;
MOV AL,13
;
MOV DX,10
;
MOV ,30
/
LO:
INT 10H
INC CX
DEC SI
JNZ LO
INC DX
MOV CX,30
MOV SI,120
DEC DI
JNZ LO
;
MOV CX, 64
MOV AX,1000H
MOV BL,13
MOV BH,0
LOO:
PUSH AX
;
XOR ,
:
INT
16H
'
"- ' '
CMP A L , 2 7

>

'

156

ASSEMBLER.

POP

AX

JZ

OUT_C

INT
INC

BH

LOOP LOO
/
OUT_C:
XOR ,
MOV DH,15

MOV DL,35
MOV ,2
INT

MOV AL,128
MOV AH,OAH

;A -

MOV CX,1

INT 10H
; 1
MOV BH,1
MOV DH,15
MOV DL,35
MOV AH,2
INT 10H
MOV AL,129
; -
MOV AH,OAH
MOV CX,1
INT 10H
XOR AH,AH
INT 16H
;
MOV ,05
MOV AL,1
INT
XOR AH,AH
INT 16H
;
MOV AX,0002H
INT 10H
; DOS
RET
CODE ENDS
END BEGIN

. 10.1. .

157

.
, , .
VGA ,
000:0000.
64 . 256 . 16 640*350/2= 122500 . ,
.

. .
. , , 16 . -. -
- .
- . - .
.
,
122500/4=30625 . 64
.
( 27
).
0 (/).
.
1 ( /). /. - , .
2 ( ). 1 (. ).
3 ( / ).
: 0. .2
, ;
. 3 4
(), . 0,
, 3 1, 4 0,
"", 4 1, 3 0,
"", 0, "".
4 ( ).
.
5 ( ). /.
0-1 ( VGA ). (0 1).

158

ASSEMBLER.

6 ( ). 0 0 . 1 - . 2-3 , :

OAOOOOH-OBFFFFH
OAOOOOH-OAFFFFH
OBOOOOH-OB7FFFH

ObSOOOH-OBFFFFH

7 ( ).
1 .
8 ( ). 1,
.
.
.
, , 3CFH.
- .
5. 4 2 ( ). ( 0).
(. 10.2-10.7) -
EGA. .
0.
. , .
.


****** 10

01100111

11001110

00011011

01010000

. 10.2. 0.

1 1001110

159

1. .
, 1. "" .
0(). / OFH,
/.
( ).
: 0-2, 3-4.
. 10.4 0, , .

( "" )
1 1 0 0 1 1 1 0
*
0 0 0 1 1 1 0 1
-
*

0 0 0 0 1 1 1 1
*
*
1 0 1 0 1 1 0 1
*
*
*
1
1
*
1
0

1
0
00000001

. 10.3. 1.
0(6). . 11111111. , 15
(1111). .
1001. , ,
. , .
0(6) :
1. .
. .. . 27.
2. .
FFH, ..
. .
(1,2,4,8 0,1,2,3). , , .

160

ASSEMBLER.

***00000

0 0 0 1

* * * *

01100111

1111

/ OFH,

.10.4. 0().
1. .
.
2. : 0-3
( , ).

161

***00000

\ 00010000 |

11111111

.10.5. 0(6). . 9 (1001).

6-4072

162

ASSEMBLER.

. 10.6. 1.

'00000


01011010
11000110
00111011
01111110

I 00010000 |

1011

. 10.7. 2. . 11 (1011).

163

'00000

/

/

* * * *

0001

I 01100111 I

1111

| 11111111 | +

. 10.4. 3.
3. VGA .
0 (). . .
"".
. , /
, /
.
27.
(. 10.7) DH. 0(6). , :

164

ASSEMBLER.

1. . ,
-:
MOV DX,3CEH
MOV A X , 0 0 0 5 H
OUT D X , A X

:
MOV
MOV
OUT
INC
MOV
OUT

DX,3CEH
AL,5
DX,AL
DX
AL,0
DX,AL

.
2. , .
,
.
3. . ..
. ,
.
CODE

SEGMENT
ASSUME CS:CODE
ORG 100H
BEGIN:
;
MOV A X , 0 0 1 0 H

INT ; , 0;
MOV DX,3CEH
MOV AX,0005H
; -
OUT DX,AX
/
MOV ,
;
OUT DX,AX
;
MOV ,8008
,- ( )
OUT DX,AX
;
MOV DX,3C4H
MOV AX/OD02H
; , DH
OUT DX,AX

165

/
MOV ,
MOV ES,AX
MOV BX,80*20+2
;
MOV AL,BYTE PTR ES:[BX]
/
MOV BYTE PTR ES:[BX],OFFH
/
MOV ,
INT 16H
;
MOV ,0002
INT 10H
/ DOS
RET
CODE ENDS
END BEGIN
Puc. 10.8, 0.
. 10.9, 2. ,
, .. .
CODE SEGMENT
ASSUME CS:CODE
ORG 100HBEGIN:/B
MOV A X , 0 0 1 0 H
INT 10H

/ , 2
/
MOV DX,3CEH
MOV AX,0205H
OUT DX,AX
/
MOV A X , 0 0 0 3 H
OUT DX,AX
;
MOV AX,8008H
OUT DX,AX
/
MOV ,
MOV ES,AX
MOV BX,80*20+2
MOV AL,BYTE PTR ES:[BX]

MOV AL,13
MOV BYTE PTR ES:[BX],AL

166

ASSEMBLER.

MOV ,
INT 16H
;
MOV ,0002
INT 10H

; DOS
RET

CODE ENDS
END BEGIN
Puc. 10.9. 2.
, .
( 1) (
0), .. : (FFFFH DIV 2)+1=8000.
,
(. . 10.1), .

.
.
, , . ,
(
). : (640* Y+X)
DIV 8 , , 80*Y+X DIV 8. X , Y - DX. :
PUSH /
MOV , 8 0
;
MUL DX
,-
SHR ,1
; X 8
SHR ,1
SHR ,1
ADD A X , C X
/
POP
/
. :
MOV ,
AND ,0111 /
MOV ,1
SHR AH,CL
/ ,
, .

167

IV.
, 0
1. , . , 1
.
, 1 8000 .
CODE SEGMENT
ASSUME CS:CODE

ORG 100H
BEGIN:
;
MOV AX,0010H

INT 10H
/ 1
XOR BH,BH
MOV DH,24
MOV DL,20

MOV AH,2
INT 10H
MOV BL,11
MOV AL,65
MOV AH,OAH

;
;

MOV CX,1
INT 10H
/ 1
CALL COPY
;
MOV ,
INT 16H
; 2
XOR ,
MOV DH,14
MOV DL,20
MOV ,2
INT
MOV BL,09
;
MOV AL,166
;
MOV AH,OAH
MOV CX,1

INT 10H
;

MOV ,

168

INT
/
MOV
MOV

ASSEMBLER.

16H
1
,05
AL,1

INT
;
MOV ,
INT 16H
;
MOV ,0002
INT 10H
; DOS
RET
; 0 1
COPY PROC NEAR
PUSH AX
PUSH
PUSH
PUSH DX
PUSH ES
; -
MOV DX,3CEH
MOV AL,05
OUT DX,AL
; , 1
MOV AL, 1
INC DX
OUT DX,AL
DEC DX
;
MOV AX,0003H
OUT DX,AX
;
MOV AX,OAOOOH
MOV ES,AX
XOR BX,BX
;
MOV CX,80*350
;
PUSH DX
MOV DX,3C4H
MOV AL,2
OUT DX,AL
MOV AL,OFH
;
INC DX

169

OUT DX,AL
POP DX
;
POVT:
MOV A L , E S : [ B X ]
MOV E S : [ B X + 8 0 0 0 H ] , A L
INC BX
LOOP POVT
; -
MOV AX,0005H
OUT DX,AX
f "~ "~

_._

_-..

_ ___._

POP ES
POP DX
POP CX
POP BX
POP AX
RET
COPY ENDP
CODE ENDS
END BEGIN
Puc. 10.10. 0 1.
, 0 1. .

V. PCX
.
PCX
. PCX-. PCX
128 . . .
. .
MANUF DB ? ; 10
HARD DB ? ; , 5

ENCOD DB ? / 1, ,
BITPX DB ? ; (1 2)
;
XI
DW ?
:
;
Yl
DW ?
2
DW ?

170

ASSEMBLER.

Y2
DW ?
HRES DW ? ;
VRES DW ? ;
PAL
DB 48 DUP(?) ,-
VMODE DB ? ;
NPLAN DB ? ; ( 4)
BPLIN DW ? ;
PALINFO DW ? / (1 - ., 2-.)
; ,
;
SHRES DW ?
SVRES DW ?
XTRA DB 54 DUP(?) /
EGA VGA EGA,
48 (. ). VGA SVGA . (. ) . EGA- 16 .
: , . . , (. ) 64 . (16*3=48).
0 255, 0 63 , 64 127 ..
,
. . .
: 0, 1 .. . ,
: -, . . , 64 .
, : , , , , 1.
,
PCX . , : , , , , , . , , 64. [12] ,
( ). -

171

, , .
, , .
, , , , 11.
, PCX 26 (. [12]), . ,
, VGA SVGA-.
DATA
PATH
MES1
MES2
MES3
MES4
MES5
MES6
DATA
SSEG

SEGMENT
DB, 80 D U P ( O )
DB ' .',13,10,'$'
DB ' .', 13,10,'$'
DB ' .', 13,10, ' $ '
DB ' .',13,10, '$ '
DB ' .',13,10,'$'
DB ' .',13,10,'$'
ENDS
SEGMENT STACK
DB 100 DUP(?)
SSEG ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:SSEG
BEGIN:
;
,-
MOV AX,DS
MOV BX,SEG RR
SUB BX,AX
MOV AH,4AH
INT 21H
;
MOV AX,DATA
MOV DS,AX
MOV AX,SSEG
MOV SS,AX
;

MOV DL,1
XOR SI,SI
XOR DI,DI
26

PCX , . : 1. . 2. , PCX ,
, GIF, JPG .

172

ASSEMBLER.

PROO:
CMP BYTE PTR ES: [81H] [SI],ODH
JZ KON_1
CMP BYTE PTR ES:[81H][SI],32
JZ KON_6
CMP DL, 2
JNZ KON_4
MOV DL,1
JMP SHORT KON_2
KON_4:
MOV AL,ES:[81H][SI]
MOV PATH[DI],AL
INC DI
MOV DL,0
KON_5:
INC SI
JMP SHORT PROO
KON_6:
CMP DI,0
JZ KON_5
MOV DL,2
JMP SHORT KON_5
KON_1:
CMP DI,0
JNZ KON_2
LEA DX,MES4
JMP PROD3
KON_2:
CMP DL,1
JNZ KON_3
LEA DX,MES5
JMP PROD3
KON_3:
/
MOV ,
MOV AL,10H
INT
;
LEA DX,DS:PATH
CALL LOAD_PCX
PUSH AX
CMP AH,0
JNZ ERR

173

;
MOV ,
INT 16H
;

ERR:
MOV ,
MOV AL,3
INT
POP AX
CMP ,
JZ WYH
,1
JNZ PRODI
LEA DX,MES1
JMP SHORT PROD3
PRODI:
CMP AH,2
JNZ PROD2
LEA DX,MES2
JMP SHORT PROD3
PROD2:
LEA DX,MES3
PRODS:
;
MOV AH,9
INT 21H
;
WYH:
MOV AH,4CH
INT 21H
; PCX
; DS:DX - , BL 0 1 ()
; - 0 -, 1- , 2- ,
;3-
LOAD_PCX PROC
PUSH DS
PUSH ES
PUSH BX
PUSH CX
PUSH DX
/
MOV AX,3DOOH
INT 21H
JNC NORM1

174

ASSEMBLER,

MOV , 2
JMP RON

NORM1:

MOV BX,AX ;
MOV A X , 4 2 0 2 H
XOR ,
XOR DX,DX
INT 21H
; DX:AX
MOV ,1
DIV

INC
;
MOV CS:_PAR,AX
;
MOV ,4200
XOR ,
XOR DX,DX
INT 21H
; 128 ()
MOV ,128
MOV AH,3FH
PUSH CS
POP DS
LEA DX,CS:BLOK
INT 21H
CMP CX,AX
JZ
NORM2
MOV AH, 2 .

JMP KON
NORM2:
;
PUSH
MOV BX,CS:_PAR
MOV AH,48H
INT 21H
POP BX
JNC NORMS
/
MOV , 1
JMP KON
NORMS:
MOV CS:_SEG,AX
;
PUSH BX

XOR BL,BL
LEA SI,CS:PAL
MOV CX,16
PAL_D:
PUSH CX
;RED
XOR AH, AH
MOV AL,CS:[SI]
MOV CL, 6
SHR AL,CL
MOV CL,2
DIV CL
MOV CL,5
SHL AH,CL
MOV CL,2
SHL AL,CL
ADD AL,AH
MOV BH,AL
;GREEN
XOR AH,AH
MOV AL,CS:[SI+1]
MOV CL,6
SHR AL,CL
MOV CL,2
DIV CL
MOV CL,4
SHL AH,CL
SHL AL,1
ADD AL,AH
ADD BH,AL
; BLUE
XOR ,
MOV AL,CS:[SI+2]
MOV CL,6
SHR AL,CL
MOV CL,2
DIV CL
MOV CL,3
SHL AH,CL
ADD AL,AH
ADD BH,AL
;
MOV AX,1000H
INT

175

ASSEMBLER.

776

INC

BL

ADD 51,3
POP
CX
LOOP PAL_D
POP
BX
/ ""* ""* "~

_. .

; DS
MOV DS,CS:_SEG
XOR DX,DX
POVT:
MOV CX,60000
MOV AH,3FH
INT 21H
CMP AX,CX
JNZ NORM4
; 16, DS
MOV CX,DS
ADD CX,3750
;, DX 1]
;( 0)
MOV DS,CX
MOV A L ,

JMP SHORT POVT


NORM4:
MOV AX,CS:_SEG
MOV DS,AX
;
MOV AH,3EH
INT 21H
;
;
MOV AX,CS:Y2
SUB AX,CS:Y1
INC AX
MOV CS:KOL_STROK,AX
; , PAINTBRUSH
NORMS:
MOV AX,CS:X2
SUB AX,CS:X1
INC AX
MOV CL,8
DIV CL
MOV CS:KOL_BYTE,AL
;
MOV AX,CS:X1
MOV CL,8

DIV CL
XOR ,
PUSH AX
XOR DX,DX
MOV CX,80
MOV A X , C S : Y 1
MUL CX
POP BX
ADD BX,AX
MOV CS: BX,BX

MOV CL,CS:NPLAN
SHL CS:N_PL,CL
/
MOV DX,3CEH
MOV AX,0005H
OUT DX,AX
MOV AX,0003H
OUT DX,AX
MOV AX,OFF08H
OUT DX,AX
MOV AX,OAOOOH
MOV ES,AX
XOR SI,SI

; , ES.-BX ,
;DS:SI , KOL_STROK -
MOV AL,2
MOV CX,CS:KOL_STROK
LOOP1:
;
PUSH CX
CMP 31,60000

JB

PUSH
PUSH
PUSH
PUSH
MOV

AX
DX
CX
BX
AX,SI

XOR
MOV
DIV

DX, DX
CX,16
CX

MOV
ADD
MOV
MOV

BX,DS
AX,BX
DS,AX
SI,DX

177

ASSEMBLER.

178

POP
POP
POP
POP

BX
CX
DX
AX

MOV

AH,1

LOOP2:

;
PUSH AX
MOV DI,CS:BPLIN /
;
MOV DX,3C4H
;
OUT DX,AX
MOV DL, CS:KOL_BYTE
MOV BX,CS:_BX
LOOPS:
;

MOV CL,DS:[SI]
CMP CL,OCOH
JB LOOP4
;
SUB CL,OCOH
MOV CH,DS:[SI+1]
LOOPS:
CMP DL,0
LOY
JZ
MOV ES:[BX],CH
INC BX
DEC DL
LOY:
DEC DI
JZ
WOWO
DEC CL
JNZ LOOPS
ADD SI,2
JMP SHORT LOOPS
WOWO:
DEC CL
JNZ WOWOWO
ADD SI,2
JMP SHORT LOOP
WOWOWO:
ADD CL,OCOH
MOV DS: [SI],CL
JMP SHORT LOOPS

LOOP4;

JZ

DL,0
LOOP7
ES:[BX],CL

MOV
INC
DEC

BX
DL

INC
DEC
JNZ

SI
DI
LOOPS

POP
SHL
CMP
JNZ
POP
DEC
JZ
MOV
ADD
MOV
JMP

AX
AH,1
AH,CS:N_PL
LOOP2
CX
CX
KONN
BX,CS:_BX
BX,80
CS:_BX,BX
LOOP1

LOOP7:

LOOP6:

KONN:
MOV BX,DS
MOV ES,BX
MOV A H , 4 9 H
INT 21H
MOV AH,0
JMP SHORT KON
;
;
CLOSJBUF:
MOV BX,DS
MOV ES/BX
MOV AH,49H
INT 21H
KON:
POP DX
POP CX
POP BX
POP ES
POP DS
RET

179

180

ASSEMBLER.

KOL_STROK DW ?
_BX
DW ?
;=(Xl/8)+Yl*80
KOL_BYTE DB ?
N_PL
DB 1
_PAR
DW ?
SEG
DW ?

;
; ((;}> =

;
;
; PCX
BLOK:
;10 PAINTBRUSH
MANUF
DB ?
; (5)
HARD
DB ?
ENCOD
DB ?
; (1)
; (4)
BITPX
DB ?
;
XI
DW ?
Yl
DW ?
2
DW ?
Y2
DW ?
;
HRES
DW ?
;
VRES
DW ?
PAL
DB 48 DUP(?) ;
/
VMODE
DB
NPLAN
DB
;
DW
BPLIN
;
PALINFO DW
;
SHRES
DW
;
SVRES
DW
DB 54 DUP(?)
XTRA
LOAD_PCX ENDP
CODE ENDS
;
ZSEG SEGMENT
RR
DB ?
ZSEG ENDS
END BEGIN
. 10.11. PCX (16 ).

11. .
.
, .
.
( , )
( ) . ,
. , , . ,
( conventional), (. 2). (extended), (expanded)
MS DOS (.
22, 5 20).

I.
21 -ro :
48, 49, 4. 1 , DOS. .
. 48 49 12 (. 10).
, ().
, J2 .
:
48 - . .
,
. , ,
. .
49 - , . ES .
, .
4 - . ES ,
. , ,
( ).
,
. - ' , .

.
,
. , , -

182

ASSEMBLER.

, ?
:
1. , .
2. , , , ,
. :
ZSEG SEGMENT
ZSEG ENDS

, /
( .ALPHA). , . MASM , ,
ZSEG . : MOV AX,ZSEG MOV ES,AX, ES ,
. . , , , ,
. .
.
48- . ,
, . , . , .

; ES DS PSP
; , ES 27
MOV
MOV
XCHG
SUB
MOV
INT

AX,ZSEG
BX,ES
AX,BX
BX,AX
AH,4AH
21H

He , /.
, .
, 13.
-. , -. - .
DOS 62H PSP .

11.

183

. - SP,
. . 4 (. . 4.6) .
.
. ,
. ,
.

III.
.
DOS 4BH.
-, .
, ,
.
. 11.1,
. , -
, ORG 0, ORG1 (. ,
PSP. LINK.EXE - - ( ). , , . CS. , .
, DS
( ). , DS. DS
CS, , , DS.
CODE SEGMENT
ASSUME CS:CODE
ORG 0
BEGIN:
LEA DX,CS:TEXT
MOV AH,9
INT 21H
RETF
TEXT DB ' 1 ,13,10, '$'
CODE ENDS
END
. 11.1. . 11.2.
. 11.2. ,
. , -

184

ASSEMBLER.

, , ( 4). , 28.
DSEG SEGMENT
DB 18 DUP(O)
;
PATH DB ' P R l . C O M ' , 0
;
DSEG ENDS
SSEG SEGMENT STACK
DB 30 DUP(?)
SSEG ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DSEG, SS-.SSEG
BEGIN:
MOV AX,DSEG
MOV DS, AX
MOV AH,3DH
MOV AL,0
LEA DX,PATH
INT 21H
;
JC
EXIT
MOV BX,AX
XOR DX,DX
MOV AH,3FH
MOV CX,18
INT 21H
;
MOV ,
INT 21H
CALL DWORD PTR CS:[OVERL]
/
;
EXIT: ;
MOV ,4

INT 21H
28

- . .
, ,
- , .
, . :
. , - . . ,
. , . ,
.

11.

185

; / .
OVERL DW 0, ,..'-.'.,.' ....

...;

DW SEG PATH
CODE ENDS
END BEGIN

..:..-.: ..-.. ;;;;;.;;,:..;

. 11.2. (. . 11.1) 4.

IV.
4.
.

4
DS:DX ,
, , 0.
ES:BX (. )
AL
0- ,
3- .

,
. : ,
( )? :
-. - !
. (. 11.3).

. 0,
. .

.
80 PSP.
.
13.

FCB PSP 5.

10

FCB PSP 6.

14

Pud. 11.3. .

186

ASSEMBLER.

FCB 6-13 ,
. ,
FCB, .
(. 11.4) .

, .

, .

. 11.4. .
, .
, .
(, MOV BX,SEG
MEM, .). .
DATA SEGMENT
F_NAME DB ':\DOS\FORMAT.COM 1 ,
PARAM DW
0

FC1
FC2
FCB1
FCB2
STR
_SS
_SP
TEXT
DATA

DW OFFSET STR
;
DW SEG STR
DW OFFSET FCB1
; FCB
DW SEG FCB1
DW OFFSET FCB2
/ FCB
DW SEG FCB2
DB 40 DUP(O)
DB 40 DUP(O)
DB 2,':'
;
DW ?
DW ?
DB ' FORMAT.COM .', 13,10,'$'
ENDS

SSEG
SSEG
^

_ _* _ 4__

CODE

SEGMENT STACK
DB 50 DUP(?)
ENDS
_-___.______.-.____

SEGMENT
ASSUME CS:CODE, DS:DATA, SS:SSEG, ES:DATA
BEGIN:
MOV AX,DATA
MOV DS,AX

11.

187

. MOV BX,SEG ZSEG


MOV AX,ES
;ES PSP
SUB BX,AX
MOV ,4
INT 21H
;
/--
MOV AX,SEG PARAM
MOV ES,AX
LEA BX,PARAM
/--
MOV _SS,SS
MOV _SP,SP
/--
LEA DX,F_NAME
;
MOV ,4
INT 21H
;
MOV AX,DATA
MOV DS,AX
MOV SS,_SS
MOV SP,_SP
JC EXIT
/ ,
LEA DX,TEXT
MOV ,9
INT 21H
EXIT:
MOV ,4
INT 21H
CODE
ENDS
ZSEG
SEGMENT
ZSEG
ENDS
END BEGIN
Puc. 11.5. FORMAT.COM.
. 11.5 . DOS FORMAT.COM. ,
FCB29. , , PSP 80 ( ,
29

FCB - .
DOS (.[5]).

188

ASSEMBLER.

, ODH). FCB
, : PARAMDB 14DUP(0).

V.
DOS 4BH .
. 11.6 , . ,
-. , , : RETF.
, ,
, - "". ,
, , .
SS SP ,
. .
DS , , . , ,
. 11.6-11.7.
/. , ZSEG ,
, , OVR_SEG:OVR_OFF
, .. BEGIN30. , , .
DATA
TEXT
DATA
SSEG

SEGMENT
DB '!',13,10,'$'
ENDS
SEGMENT STACK
DB 50 DUP(?)
SSEG ENDS
CODE SEGMENT
ASSUME CS:CODE, DS-.DATA, SS:SSEG
BEGIN:
MOV AX,DATA
MOV DS,AX
LEA DX,TEXT
MOV AH, 9
INT 21H
RETF
;
CODE ENDS
END BEGIN
Puc. 11.6. -, . 11.7.
50

, PARA (. 13), .

11.

189
:

DATA SEGMENT
'
'
;
PARAM
DB 4 DUP(O)
" "
'
PATH DB ' PR1. EXE ',
OVR_OFF
DW 0
OVR_SEG
DW ?
STR_ER
DB ' .',13,10, '$'
STR
DB ' .',13,10,'$'
DATA ENDS
,
SSEG
SEGMENT STACK
DB 50 DUP(?)
SSEG
ENDS
CODE

SEGMENT
ASSUME CS.-CODE, DSrDATA, SS:SSEG, ES.-DATA
BEGIN:
MOV AX,DATA
MOV DS,AX .; .,.
MOV BX,SEG ZSEG
MOV AX,ES
;,
;ES PSP
SUB BX,AX
MOV ,4AH
INT 21H
/
; 2000
MOV BX,2000
MOV ,48
INT 21H
JC ERR
; ,
MOV OVR_SEG,AX
;
MOV AX,DATA
MOV ES,AX
LEA BX,PARAM
MOV AX,OVR_SEG
;,
MOV
[BX],AX
MOV [BX]+2,AX
/
LEA DX,PATH
MOV AL,3
MOV ,4
INT 21H
JC
ERR
. .,
CALL DWORD PTR DS:OVR_OFF ;

MOV
MOV

,DATA
DS,AX

190

ASSEMBLER.

LEA
MOV
INT

DX,STR
AH,9
21H

MOV
INT

AH,4CH
21H

EXIT:

ERR:
LEA
MOV
INT
JMP
CODE
ZSEG
ZSEG

DX,STR_ER
AH, 9
21H
EXIT
ENDS
SEGMENT
ENDS
END BEGIN

Puc. 11.7. , (. . 11.6).


"" -
DOS. 2 . . , ,
. ( ,
..) , . ,
, . (. VII ).

VI.
. 4 . , -.
, . .
PSP INT 20H.
. , , ,
CS PSP. - ,
, INT 20H. - , ,
, JMP (JMP FAR) PSP.
- DS ES PSP,
. :
PSP_OFF DW 0
PSP_SEG DW ?

; 0 PSP

MOV PSP_SEG,ES (DS


). :

11.

191

JMP DWORD PTR DS:PSP_OFF


. , 0. , - RET (!).
, DOS 0,
20. 22.
, (),
.

VII.
2 .
,
.
DATA

SEGMENT

DB ' ' , 13, 10, ' $ '


DB ' 1 , 13, 10, '$ '
DB ' ' , 13 ,10,'$'
DB ' ',13, 10, '$'
DB ' ' , 13, 10, '$ '
1 ,1J,1U,
1 in i i

1

I
?
STR6
DB ' ' , 13, 10, '$'
STR7
DB ' ' ,13,10, '$'
;
STROKA
DB '0000', 13, 10, '$'
;
1
1
SHABL
DB '0', ', '2', '3', ', '5', '6', '7', '8', '9', ' , '
DATA ENDS
;
STECK SEGMENT STACK
DB 100 DUP(?)
STECK ENDS
/
CODE SEGMENT
ASSUME CS:CODE, DSrDATA, SS: STECK
BEG:
MOV AX, DATA
MOV DS,AX
CALL BEG_MEM
PROD:
;
LEA DX,STR1
CALL TEXT
MOV AX,ES
STRO
STR1
STR2
STR3
STR4

192

ASSEMBLER.

INC AX
CALL HEX
;
LEA DX,STR2
CALL TEXT
MOV AX,ES:[3]
CALL HEX
;
LEA DX,STR4
CALL TEXT
MOV AX,ES:[1]
CALL HEX
;
LEA DX,STR6
CALL TEXT
CALL NAM
LEA DX,STR5
CALL TEXT
; ?
CALL NEXT
CMP AL, 0
JZ
PROD
LEA DX,STRO
CALL TEXT
LEA DX, STR7
CALL TEXT
MOV AX,ES
ADD AX,ES:[3]
MOV ES,AX
CALL HEX
KONEC:
MOV ,4
INT 21H
;
; ES
BEG_MEM PROC
MOV AH,52H
INT 21H
MOV ES,ES:[BX-2]
RET
BEG_MEM ENDP
/ ,
HEX
PROC
XOR DX,DX
MOV BX,1000H

11,
DIV
MOV ,
MOV BL,BYTE PTR SHABLfBX]
MOV STROKA,BL
MOV AX,DX
XOR DX,DX
MOV BX,100H
DIV BX
MOV BX,AX
MOV BL,BYTE PTR SHABLfBX]
MOV STROKA+1,BL
MOV AX,DX
XOR DX,DX
MOV BX,10H
DIV BX
MOV BX,AX
MOV BL,BYTE PTR SHABLfBX]
MOV STROKA+2,BL
MOV BX,DX
MOV BL,BYTE PTR SHABLfBX]
MOV STROKA+3,BL
LEA DX,STROKA
CALL TEXT
RET
HEX
ENDP
;
; ES, AL 0, 1,
; 2,
NEXT
PROC
MOV AL,1
CMP BYTE PTR ES:[0],'Z'
JZ NET
CMP BYTE PTR ES:[0],'M1
JZ NET1
MOV AL,2
JMP SHORT NET
NET1:
MOV AX,ES
INC AX
ADD AX,ES: [3]
MOV ES,AX
XOR AL,AL
NET:
RET
ENDP
NEXT
7-4072

193

194

ASSEMBLER.

;
NAM
PROC
CMP WORD PTR ES: [1 ] ,
; ?
JZ WWWW
PUSH ES
MOV DI,ES .
MOV SI,ES:[1]
DEC SI
CMP SI,DI
JZ WO
MOV ES,SI
WO:
XOR BX,BX
MOV AH, 2
WW:
MOV DL,ES:[BX][8]
CMP DL,65
JB WWW
INT 21H
INC BX
JMP SHORT WW
WWW:
MOV DL,13
INT 21H
MOV DL,10
INT 21H
POP ES
RET
WWWW:
LEA DX,STR3
CALL TEXT
RET
NAM
ENDP
;
TEXT PROC
MOV AH, 9
INT 21H
RET
TEXT ENDP
CODE
ENDS
END BEG
. 11.8. .
- MEMO - , . , MEMO > MEMO.LST. ,

11.

195

. 52
' ,
ES:BX. , .
, NEXT AL 2, .

VIII.
: PSP
, , ? ,
, (. 12). , PSP : , ,
. , .
CODE SEGMENT
ASSUME CS:CODE,
ORG 10OH
BEGIN:

DS:CODE,

SS:CODE, ES:CODE

;
;
MOV ,1
MOV AX,OFFSET PRIVET
XOR DX,DX
DIV BX
INC AX
MOV BX,AX ; 4
/
MOV ,4
INT 21H ; ES CS -
/ PSP
MOV ,1
MOV ,48
INT 21H
MOV ES,AX
/ PSP
MOV 31,0
MOV 01,0
MOV ,100
CLD
REP MOVSB
/ PSP
MOV ,50
MOV BX,ES
INT 21H

196

ASSEMBLER.

; "" PSP
MOV WORD PTR C S : [ 0 ] ,
MOV WORD PTR CS:[OAH],0
MOV WORD PTR CS:[OAH+2],0
;
MOV AH,49H
INT 21H
MOV ES,ES:[2CH]
MOV AH,49H
INT 21H
PUSH CS
POP ES
MOV AH,49H
INT 21H
;
MOV AH,4CH
INT 21H
PRIVET:
CODE ENDS
END BEGIN

. 11.9. , PSP.
, . . PSP (.
), DOS 4.
, PSP, 50 DOS, PSP.
, DOS. : ,
4 . : PSP.

12. TSR- ().


- , - , - ? - ?
- , ! - .

?
, , , , .

..
.
, MS
DOS . ,
Windows. , , .
TSR Terminate State Resident, .. " ". , , .
.
- , - .
. , .
, , , , . " " . , "" .
TSR-. , , , :
1. TSR- ,
MS DOS.
2. , .
3. , ,
.
,
.

198

ASSEMBLER.

I. .
. 27, -,
DOS 31, -. .
27.
: DX - ;
CS- PSP.
PSP. NO_RES -
, , , :
LEA DX,NO_RES
INT 27H

, . 27
DOS 22, 23, 24.
31.
-31,
AL- ,
DX - , . PSP.
, .
-. , .
(. 12.1). . (. 13) - PARA, ..
.
16. , , , ( 16),
. , , ..
( ) 64 . ,
SIZE, . , , .
, , ,
- , , SET, PATH, PROMPT. 32 .
,
. .
;
DSEG SEQUENT
BCJFER 2000 (?)
Pi D D ?
DSEG ENDS

: , . . . . - .

12. TSR- ()

199

;
SSEG SEGMENT STACK
ST
DW 100 (?)
SSEG ENDS
;
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:SSEG
BEGIN:

;,
NO_RES:
MOV AX, SIZE BUFER+SIZE Pl+16 ;
MDV BX, SIZE ST+16 ;
MOV DX,NO_KES-BEGIN+16 ;
MOV CL,4
SHR AX,CL ; 16
SHR BX,CL
SHR DX,CL
ADD AX,BX
ADD DX,AX
ADD / PSP - 10H
MOV AX, 3100H
INT 21H
CODE ENDS
BEGIN
. 12.1. 31 -.

, ,
. , 17 ,
. . 12.10 , .

II. .
9 .
, , TSR-.
- TSR- .
, , ,
. ,
- , , , , .
JMP CALL (. 9).

200

ASSEMBLER.

, -
(. ) . , ,
. 21, 13, 25, 26, 16.
RET 2 IRET
( ). ,
:
1)
, .
2) , ,
.
JMP, , .
, , 8, 9, , .. .
, (PUSH AX/POP AX ..).
. 12.2 . 12.3, .
;
INT_N PPOC FAR

; ,
PUSHF
PUSH AX

;
/

POPF
/
CALL DWORD PTR CS:OLD_INT_N
/
PUSHF
PUSH AX
/

12. TSR- ()

201

INT_N

RETF 2
ENDP

. 12.2. 1 .
/
INT_N PROG EAR

; ,
PUSHF
PUSH AX
/
/
POP

/
JMP DWORD PTR CS:OLD_INT_N
INT_N ENDP

. 12.3. 2 .

III. .
, .. , , .
. :
1. : " ". ,
- . , , ,
. ,
. . 12.4
TSR- . . 12.5 , . -

202

ASSEMBLER.

8. ,
.

PRIZN

DW 12

INT 8

FAR

INT_8

ENDP

. 12.4. TSR- .

M3V ,3508
INT 21H

? PTR ES:[BX-2],PRIZN ;

. 12.5. TSR-, .
, ..
, .
2. "
". , . . , , ( ) ,
. , , , . , . , , . , .
DOS (2FH), , ,
,
. DOS: PRINT,
ASSIGN, SHARE. 80H-FFH (, , ). , , . , ( ). : , , ,

. TSR- ()

203

.
.
, (. 12.6 -12.7) , . 16.

INT16 EROC
,20
JNZ OONT
MDV ,789
;
BX/CS
;
IRET
CONT:
JMP PTR CS:OLD16
INT16 ENDP

. 12.6. , .

M3V ,20
INT 16H
CMP /789
JZ YES
/

. 12.7. , .
3. , , . , .
2 , DOS.
.
, . , . , . PSP . PSP
. . . 12.8
. PSP INT 20H,
.

204

ASSEMBLER.

IV. /
.
- .
.
. - . , . , , . . , .
( )
: - DOS
DOS? , 8- DOS. TSR-
DOS, ( - ).
MS DOS , ..
. , DOS ,
DOS , - .
DOS,
, , DOS.
DOS 34H3|. ES:[BX] , 1, - DOS, 0 . , , 0
( "" ). , .. DOS, ..
1.
21. ,
- ,

. . 12.8 , . , . 16.
"", . , RETF 2.
FLAG_21 =0 TSR- .
.

12. TSR- ()

205

.
INT21 FAR
STI
CMP ,
JZ
A1Z
JMP SHORT A2ZA1Z:
PUSH CX
PUSH AX
A3Z:
M3V CX,OFFFFH
A4Z:
M3V AH,1
LOOP A4Z
INT 16H
JZ
A3Z
AX
POP CX
A2Z:
M3V CS:FLAG_21,1
PUSHF
CALL CWORD PTR CS: [OFF_21]
M3V CS:FLAG_21,0
RETF 2
INT21 ENDP

. 12.8. 21H.
-
. .
. . . , , . , 21-
( , . ), , . , , .
28. , DOS . , ,
. . . 12.9 .
, 21- , 13-, 25- 26- . -

106

ASSEMBLER.

, DOS (. . 12.9
).
, . ,
DOS.
.

V. .
TSR-, , . TSR- .
. ? .
1. . , .
2. . ,
. , ? , ( ) . TSR- .
.
.
, , . , ( ),
,
.
, . ?
,
. . . ,
. ,
.
3. . 22 . , . , .

VI. .
,
.
1.
(. . 12.9 ). , ,

12. TSR- ()

207

. , . , , . , , , , . . , , , . . , , . , . 32
.
. ,
, ,
.
, 49 4 , - .
2. . ( ), , ..
.
, . PSP, (. . 12.9). , PSP . .
.
- , , ,
. (. . 12.9).
3. . ( )
, .
,
. ,
"". ,
, .
4. (, ),
.
5. , , , PSP 32

208

ASSEMBLER,

, (. 8). , .
: $ ( DOS 62H). PSP ( DOS
). PSP ( 50).
6. ( ) . DOS 59 . . - DOS, . , 59.
( 5DH, 5
DOS 5.0).
7. MS DOS. , ,
. . ,
,
DOS, .
5DH ( 6).
:
MOV AX,5D06H
INT 21H

:
DS:SI -
-

VII. .
, , , . SCREEN.TXT
".
. , , ,
.
1. ( SCAN). , PSP . , ,
. 52 21.
2. , , ( FREE_ENV).
33

, [7] , , - . .
, , .

12. TSR- ()

209

3.
PSP ( RE_VECT). ,
. , , .
4. . 25 26. .
POP SI. He , SI, , 25/26 , DS, ES, SS, SP.
5. , . PSP ( ).
6. .
, . , 28- .
CODSEG SEGMENT
ASSUME CS:CODSEG
ORG 100H
BEGIN:
JMP BEG
PRIZN DW OF034H ; 103 PSP
;
; PSP
OLD090 ?
;+105
OLD09S ?
;+107
OLD08O ?
;+109
OLD08S ?
;+10
OLD210 ?
;+10
OLD21S ?
;+10
OLD130 ?
;+
OLD13S ?
;+113
OLD250 ?
;+115
OLD25S ?
;+117
OLD260 ?
;+119
OLD26S ?
;+11
OLD280 DW ?
;+11
OLD28S ?
;+11

OLD240 ?

OLD24S ?

OLD230 ?
OLD23S ?
PI
2

DB 0
DB 0

;
/'

270

ASSEMBLER.

DB
/
;
21
DB 0 ; 21
13
DB 0 ; 13
25
0 ; 25
26
DB 0 ; 26
;
BUEER
DB 2050 DUP{?)
;
_

?
_ES
?
_SS
?
_SP

.;.

;
FILE

DB "SCREEN.TXT",0

;
INT09 PROC FAR

CMP CS:P1,1 ;
JZ YES
MOV CS:_AX,AX
MOV CS:_ES,ES
IN
AL,60H

CMP AL/15

; TAB ?

JZ
MOV
JMP

TAB
AX,CS:_AX
SHORT YES

MOV
MOV
TEST
JZ

AX,0
ES,AX
BYTE PTR ES:[417H],4
NO_CTRL

TAB:

MOV CS:P1,1 ;
NO_CTRL:
MOV AX,CS:_AX
MOV ES,CS:_ES
YES:

JMP PTR CS: [OLD090]


INT09 ENDP
;
INT08 PROC FAR
;
PUSHF
CALL DWORD PTR CS: [OLD08O]
CMP CS:P3,1

12. TSR- ()

JNZ
JMP
NOJTORK:

NOJflORK
WDRK

MOV CS:P3,1
/ , PSP
MOV CS:_AX,AX
MOV CS:_SS,SS
MOV CS:_SP,SP
MOV AX,CS
MOV SS,AX
MOV SP,100H
MOV AX,CS:_AX
;
PUSH AX
PUSH
PUSH
PUSH DX
PUSH SI
PUSH DI
PUSH ES
PUSH DS
CMP CS:P1,1
JNZ N01
CMP CS:P2,1
JZ 2
CALL VID_BUF
MCV CS:P2,1
2:
/
CMP CS:P13,1
JZ 1
CMP CS:P25,1
JZ N01
CMP CS:P26,1
JZ N01
CMP CS:P21,1
JZ 1
CALL BUF_DISK
MCV CS:P1,0
MOV CS:P2,0
N01:

;
;
/

/
POP DS
ES

211

212

DI
SI
DX



/
M3V SS,CS:_SS
M3V SP,CS:_SP
M3V CS:P3,0
WORK:
IRET
INT08 ENDP
/ 21
INT21 PROC EAR
STI
M3V CS:P21,1
PUSHF
CALL DWORD PTR CS: [OLD210]
M3V CS:P21,0
RETF 2
INT21 ENDP
/ 13
INT13 PRDC EAR
MDV CS:P13,1
PUSHF
CALL DWORD PTR CS:[OLD130]
1 CS:P13,0

ASSEMBLER,

RETF 2
INT13 ENDP
/ 25
INT25 PROC FAR
M3V CS:P25,1
PUSHF
CALL PTR CS: [OLD250]
SI
/
MDV CS:P25,0
/
RETF
INT25 ENDP
/ 26
INT26 PROC FAR
M3V CS:P26,1
PUSHF

12. TSR- ()

CALL DWORD PTR CS:[OLD26O]


SI
;
MDV CS:P26,0
; ,
RETF
INT26 ENDP
/ 28 - BUF_DISK
INT28 PROC FAR
PUSHF
CALL PTR CS:[OLD280]
CMP CS:P2,1
JNZ NET
MDV CS:P3,1
CALL BUF_DISK
MOV CS:P1,0
MOV CS:P2,0
MOV CS:P3,0
NET:
IRET
INT28 ENDP
/
INT24 PROC FAR
M3V AL, 3
IRET
INT24 ENDP

/ 23
INT23 PROC FAR
IRET
INT23 ENDP
/
;
VID_BUF PROC
/
CLI
LEA DI,CS:BUFER
XOR SI, SI
AX,OB800H
ES,AX
CX,2000
XOR BL,BL
L002:
MOV AL,ES:[SI]
MDV CS:[DI],AL
INC DI

213

214

ASSEMBLER.

ADD SI,2
INC BL
; 13,10
CMP BL, 80
JNZ N03
XOR BL,BL
MDV BYTE PTR CS:[DI],13
INC DI
MOV BYTE PTR CS:[DI],10
INC DI
N03:
LOOP L002
STI
RET

VID_BUF ENDP
;
BUFJDISK PROC
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH ES
PUSH DS
PUSH CS
DS
;
MDV ,3524
INT 21H
MDV CS:OLD24S,ES
MDV CS:OLD240,BX
MDV AX,2524H
LEA DX,CS:INT24
INT 21H
MDV AX,3523H
INT 21H
MDV CS:OLD23S,ES
MDV CS:OLD230,BX
MDV AX,2523H
LEA DX,CS:INT23
INT 21H
; (FILE)
MDV AH,3CH
LEA DX,CS:FILE
XOR CX,CX

12. TSR- ()

JC

21H
EX

M3V BX,AX
;
LEA DX,CS:BUEER
M3V ,40
M3V ,2050

21
/
MOV ,

21
:
/
M3V ,2524
M3V DX,CS:OLD240
M3V DS,CS:OLD24S
INT 21H
MDV AX,2523H
MOV DX,CS:OLD230
ICV DS,CS:OLD23S
INT 21H
TOP DS
ES
TOP DX
POP CX
BX
AX
RET
BUF_DISK ENDP
RES_END:
;
/
/ , - 1, -
/ES - ,
SCAN PROC
PUSH BX
PUSH DS
PUSH DX
PUSH SI
/ SI ( )
MOV SI,CS
/
M3V ,52
21

215

216

ASSEMBLER.

MOV ES,ES:[BX-2]
MOV AX,1
LOOj
CMP VpRD FTR ES:[1],0
JZ
5
PUSH ES
POP BX
INC BX
; - ?
CMP SI,BX
JZ
CONT5
MOV DS,BX
;
MOV BX,CS:PRIZN
CMP PTR DS:[103H],BX
JZ
_END
CONT5:
; ?
CMP BYTE PTR ES:[0],'M'
JZ
QONT4
XOR AX,AX
JMP SHCRT _END
CONT4:

MDV DX,ES:[3]
M3V BX,ES
BX,DX
INC BX
M3V ES,BX
JMP LOO
_END:
MOV BX,ES
INC BX
MOV ES,BX
SI
DX
DS
BX
RET
SCAN ENDP
/
SET_VECT PROC
PUSH AX
PUSH BX

12. TSR- ()

PUSH DX
PUSH ES
;
M3V ,3509
INT 21
M3V CS:OLD09S,ES
CS:OLD090,BX
MDV , 3508
21
M3V CS:OLD08S,ES
MDV CS:OLD080,BX
M3V ,3521
21
M3V CS:OLD21S,ES
MDV CS:OLD210,BX
MDV , 3513
21
M3V CS:OID13S,ES
MDV CS:OLD13O,BX
MDV AX,3525H
21H
CS:OLD25S,ES
MDV CS:OLD25O,BX
MOV AX,3526H
21H
MDV CS:OLD26S,ES
MDV CS:OLD260,BX
MDV AX,3528H
21H
MDV CS:OLD28S,ES
M3V CS:OLD280,BX
/
AX,2509H
LEA DX, 09
21H
MOV AX,2508H
LEA DX, INT08
21H
MDV AX,2521H
LEA DX,INT21
21H
M3V AX,2513H
LEA DX,
21H

217

,;.

-. ..._

;.'.:.;

.;.,

.,. , i :,,x- ;.., i ; , ,

.: ;

13

218

ASSEMBLER.

MOV
LEA
INT
MOV
LEA
INT
MOV
LEA
INT

AX,2525H
DX, INT25
21H
AX,2526H
DX, INT26
21H
AX, 2528H
DX, INT28
21H

ES
DX
BX

RET
SET_VECT ENDP
;
RE_VECT PROC
PUSH
PUSH
PUSH
M3V
M3V
MOV
INT

AX
DX
DS
AX,2509H
DX,WORD PTR ES: [105H]
DS,WORD PTR ES: [107H]
21H

MOV AX,2508H
MOV DX,TORD PTR ES: [109H]
MOV DS,WORD PTR ES:[10BH]
INT
MOV
MOV
MOV

21H
AX,2521H
DX,WORD PTR ES: [10DH]
DS,WORD PTR ES: [10FH]
INT 21H
MOV AX,2513H
MOV DX,WORD PTR ES: [111H]
MOV DS,WORD PTR ES: [113H]
INT
MOV
MOV
MOV
INT
MOV
MOV
MOV

21H
AX,2525H
DX,WORD PTR
DS,WORD PTR
21H
AX,2526H
DX,WORD PTR
DS,WDRD PTR

ES: [115H]

ES:[117H]

ES:[119H]
ES:[11BH]

12. TSR- ()

INT 21H
M3V ,2528
M3V DX,WORD PTR ES: [11DH]
M3V DS,TORD PTR ES: [11FH]
INT 21H
DS
DX
AX
RET
RE_VECT ENDP
;
ERASE PROC
M3V AH,49H
INT 21H
RET
ERASE ENDP
/
FREE_ENV PRDC
PUSH AX
PUSH ES
MDV ES,DS:[2CH]
CALL ERASE
POP ES
AX
RET
FREEJENV ENDP
/

BEG:
CALL SCAN
CMP AX,0
JZ NO_PR
CALL RE_VECT
CALL ERASE
LEA DX,TEXT2
MDV AH, 9
INT 21H
RET
NO_PR:
CALL SET_VECT
CALL EREE_ENV
LEA DX,TEXT1
MDV AH,9
INT 21H
LEA DX,RES_END
INT 27H

219

220

ASSEMBLER.

TEXT!
DB ' .',13,10,'$'
2
DB ' .',13,10,'$'
CODSEG ENDS
'
'
' -
END BEGIN
. 12.9. .
CTRL+TAB.

VIII. .
. 17
CVFILE.TXT. , 17. , ' , DOS.
. . ,
PSP , .
CODE SEGMENT
ASSUME CS:CODE
ORG 100H

'

BEGIN:
DBS

JMP UST
EW ?

PATH DB 'C:\FILE.TXT',0
BUF
PR

DB
DB

OLD_VEC

?
0

'

DW ?
DW ?

INT17 PROC
;
,78
JNZ PAR

MOV AH,80H
MOV DX,CS
ADD DX,16 ; ( ! ) ?
LEA BP,CS:PR
MOV SI,CS:OLD_VEC
MOV DI,CS:OLD_VEC+2
IRET

PAR:

PUSH DS
PUSH BX
PUSH CX
PUSH DX
CMP CS:PR,0

12.TSR-()

221

PUSH AX

JNZ ODD
;
MOV ,
MOV ,
PUSH CS
DS
. LEA DX,CS:PATH
INT 21H
MOV CS:PR,1

''

MOV CS:DES,AX

ODD:
;
,, :
POP AX
CMP AH,0
JNZ KON ;
/
M3V ,40
MOV

M3V
LEA
PUSH
POP
INT
JC
CMP

CS:BUF,AL
BX,CS:DES
DX,CS:BUF
CS
DS
21H
OKI
AX,CX

JZ
KON
OKI:
,-,
MOV AL,2

MOV ,
LEA DX,DS:PATH

INT 21H
;
MOV CS:DES,AX
MOV BX,AX
MOV AH,42H
MOV CX,0
MOV DX,0
MOV AL,2

INT 21H
/
MOV AH,40H

MOV CX,1

222

ASSEMBLER.

LEA
INT

DX,CS:BUF
21H

KON:

MDV AH,144
POP DX
TOP CX
BX
TOP DS
IRET
INT17 ENDP
UST:
;
MDV AH,78H
INT 17H
CMP AH,80H
JNZ DAL
/
CLOSE:
MDV ES,DX
PUSH ES
XOR AX,AX
MDV ES,AX
CLI
MDV ES:[17H*4],SI
MDV ES:[17H*4+2],DI
ES
MDV AH,49H
INT 21H
LEA DX,TEXT2
MDV AH,9
INT 21H
;
MDV AH,4CH
INT 21H
DAL:
MOV PR, 0
;
MDV ES,DS:[2CH]
MDV AH,49H
INT 21H
/ 17
XOR AX, AX
MDV ES,AX
MDV AX,ES:[17H*4]
MDV CS:OLD_VEC,AX
MDV AX,ES:[17H*4+2]

12. TSR- ()

MDV CS:OLD_VEC+2,AX
MDV AX,OFFSET INT17
CLI
MDV ES:[17H*4],AX
MDV ES:[17H*4+2],CS
;

MDV BX,16
MDV AX, OFFSET _END
XOR DX,DX
DIV BX
INC AX
MDV BX,AX
PUSH CS
ES
;
MDV AH,4AH

INT 21H
/ PSP
MDV
MDV ,48
INT 21H

MDV
/
MDV
MDV

ES,AX / PSP
PSP
81,0
DI,0

MDV

CLD

REP MDVSB ;
/ PSP
MDV ,50
MDV BX,ES
INT 21H
/ PSP
MDV ,49
INT 21H
/
/
MOV BX,DS
DEC
MDV DS,BX
MDV WORD PTR DS:[1],0
;
MDV AX,DS:[3]
PUSH AX

MDV TORD PTR DS:[3],15 ; 240

223

224

ASSEMBLER,


ADD
MOV DS,BX
INC BX

MOV BYTE PTR DS:[0], 'M' /


MOV WORD PTR DS:[1],BX /
MOV AX,OFFSET CS:UST
SUB AX,256
MOV 6
XOR DX, DX
DIV CX
INC

AX

MOV
MOV
ADD
INC

DS:[3],AX
DX, DS
DX,AX
DX

MOV DS,DX
DX
SUB DX, 16
SUB DX,AX

SUB DX, 1

/
MOV BYTE PTR DS:[0],'M'

MOV WORD PTR DS:[1],0 /


MOV DS:[3],DX
/
;
PUSH CS
POP DS
LEA DX,TEXT1
MOV AH,9

INT 21H
/
MOV AH,4CH
INT 21H
TEXT1 DB ' .',13,10,'$'
2 DB ' .',13,10,'$'
JEND:
CODE ENDS
END BEGIN
. 12.10. TSR-, PSP.
, .
1. , . UST.

12, TSR- ()

225


17. , ,
C:\FILE.TXT. . PR , FILE.TXT . ,
, , ,
, .
,
. , .
3. 17 ,
. .
4. 192 .
PSP. . .
) "" _END, .. .
) 256 PSP.
) PSP .
) PSP ( ).
) .
) . .
PSP . ,
. .
) - 4. ,
, , DOS, .
5. PSP, , .
, PSP (. 11, .
11.9) :
PSP.
2.

.
TSR- . 10
, EGA-.
, . VGA-
. , , , INT 10H (..
), . 30 .
. ,
.
.
, .
8 - 4072

13.
.
, -
.
.
- , ,
. , .. ,
,
! ,
, . .

I.
- . ,
. . 13.1 . 13.2 (, , ).
ASM .EXE.
: PR1 .OBJ PR2.OBJ, .
: LINK PR2+PR1. .
-, PR2 (, ).
PR2.EXE PR2.MAP. - . 13.3. ( , , , ),
, ( ).
, PR2, PR1.
, .
LINK PR I+PR2, . PR 1, . ,
, (., , ).
. 13.1 13.2 :
PR2 , PR 1, , , , PR2. PR2, .
: PUBLIC EXTRN.
PUBLIC (, ),
. PUBLIC
, .. .

13.

227

EXTRN , , . : NEAR FAR, BYTE,


WORD DWORD. ,
.
/ 1,
DATA1

PR1.ASM

SEGMENT

TEXT DB '! 1. ',13,10,'$';


DATA1 ENDS
PUBLIC WORK
EXTRN PRI:FAR
LIB SEGMENT
ASSUME CS:LIB
WORK PROC FAR
PUSH AX
PUSH DS
MOV AX,SEG TEXT
MOV DS,AX
MOV AH,9
LEA DX,TEXT
INT 21H
POP DS
POP AX
CALL PRI ; , 2
RETF
WORK ENDP
LIB ENDS
END WORK
Puc. 13,1. ! ( PRI. ASM), PR2. ASM.
; 2, PR2.ASM
DATA SEGMENT
TEXT1 DB ' PRI I. 1 ,13,10,'$'
DATA ENDS
SSEG SEGMENT STACK
DB 40 DUP{?)
SSEG ENDS
EXTRN WORK:FAR
PUBLIC PRI
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SSrSSEG

ASSEMBLER.

228
BEGIN:

MOV AX,DATA
MOV DS, AX
; , 1
CALL WORK
MOV AH,0
INT 16H
MOV AH,4CH
INT 21H
; 1
PRI PROC FAR
PUSH AX
PUSH DS
PUSH DX
MOV AH, 9
LEA DX,TEXT1
INT 21H
POP DX
POP DS
POP AX
RETF
PRI ENDP
CODE ENDS
END BEGIN
. 13.2. 2 (), 1 (. 13.1).
START
OOOOOH

00060H
00090H
OOOBOH

STOP
LENGTH NAME CLASS
0002BH 0002CH DATA
00057 00028H SSEG
00080H 00021H CODE
OOOA9H 0001AH DATA1
OOOC6H 00017H LIB

PROGRAM ENTRY POINT AT 0006:0000


Puc. 13.3. PR2. MAP.
, , . . , . .
, , 11. . -

13.

229

( , , / ).
, 1 (PR I .ASM). , , - . , ,
, PR I .ASM ,
. ZSEG.
, ZS, PUBLIC.
, , , , : EXTRN ZS:FAR. , (.. ), : MOV AX,SEG ZS, , . :
, ( ) - ? - (. . 13.4), .
PUBLIC ZS
ZSEG SEGMENT
ASSUME CS:ZSEG
ZS:
ZSEG ENDS
END
Puc. 13.4. , .
- (LIB.EXE). , .
LIBRARIES [.LIB]: . , , "+".
:
LIB _+__ - . ,
.
LIB _-__ -
.
34

.
(PAGE - , PARA - , WORD - , BYTE - ).
(100 ), ,
, .
. , , BYTE, ZS , ,
.

230

ASSEMBLER.

LIB _*__ - OBJ.


.
_-*__-,
, .
LIB _,_ - . : CON, PRN ..
LIB _-_1 +_2 -
_1 _2.
.

.
. ,
.
, ,
, ?
, . . , , . , . ,
.
(. 13.5). :
? : - (
, .. ), - L1
. PARA,
. 0.
BYTE: DATA SEGMENT BYTE. ,
.
0.
,
,
BYTE35. .
DATA SEGMENT
LI
DB ?

DATA ENDS

CODE SEGMENT
ASSUME DS:DATA, CS:CODE
35

13,

231

BEGIN:
MOV AX,SEG LI
MOV BX,OFFSET Ll

CODE ENDS
END BEGIN
Puc. 13.5. ?

.
, SEGMENT, ,
. :
_ SEGMENT
[""]

[ ]

[ ]

_ ENDS
, . , .
,
( ). .
PUBLIC.
, . .
COMMON. . .
STACK. ,
SS SP. SS
36
, SP - ( ) .
STACK, PUBLIC. . SP , SS - .
MEMORY. (, ).
, MEMORY, , COMMON.
34

14 -, , . CS, IP,
SS,SP.

252

ASSEMBLER.

AT. - . . , :
VIDEO_BUF SEGMENT AT OB800H
LI DB ?
VIDEO_BUF ENDS

LI . , "!":
MOV AX,SEG VIDEO_BUF
MOV ES,AX
MOV E S : L 1 , " ! "

IV.

. , , ..
.
,
.
1. . ,
. ,
, . , , , DS:DX.
, .
, . ,
, . :
( ),
. , ,
"" .
2. . ,
BYTE: LI DB ?. PUBLIC EXTRN
,
. L1 :

MOV AX, SEG L1


MOV ES,AX
MOV BX,OFFSET LI
ES:BX L1.
, ,
, .. ,
.

13.

233

3. .
. , , .. 4 . . 13.6. RETF .
, ( WORD)
. : PUSH
PUSH BX. . , , . 13.7.
, .
: MOV BP,SP, +6 (PUSH AX), a +4 37.
, 4: ADD BP,4. .
. . ,
. ,
SP ( ). . - , SP .
, , . .
, .
PUSH , SP 2,
+6.
.
, RETF. -
, . 13.7, RETF N, N - , SP ( ) .
, . ,
, , ,
, (4 2 ).
, ,
. SP . SUB SP,N, N- .

. ,
(. 15 24,25).
37

, ,
.. V ,[+2] MOV AX,SS:[BP+2] (. 4.).

ASSEMBLER.

234

<

ss

IP

SS

SP

<->P |

CS

<

SP

(B)

(A)

. 13.6. () () .
.

ss
IP
CS

SP

SP

()

SP+4+4

()

SP
.
IP
CS

SP+4+4

()

. 13.7. () () . () .
PUSH PUSHBX.

13.

235

,
. SP
. SP (. 13.7()).
.
. . , .
,
. ,
. ,
, .. ,
, .
; l o c . a s m
; ,
EXTRN COPY:FAR
EXTRN PRINT:FAR

;
STE SEGMENT STACK
DB 100 DUP(O)
STE ENDS
;
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:STE
BEGIN:
;
MOV AX,DATA
MOV DS,AX
;
; INT COPY(BUFER,STRl,STR2)
;BUFER, STRl, STR2 -
;
;
; STR2
;STR1 BUFER
;
;
;, ,
/
PUSH DS
LEA AX,BUFER
PUSH AX
PUSH DS
LEA AX,STROKA1
PUSH AX

256

ASSEMBLER.

PUSH DS .
LEA AX,STROKA2
PUSH AX
CALL COPY
;
/ VOID PRINT(BUFER)
/ ,
/
PUSH DS
LEA AX,BUFER
PUSH AX
CALL PRINT
/
MOV AX,4COOH
INT 21H
CODE ENDS
;
DATA SEGMENT
STROKA1 DB " " ,0
STROKA2 DB " ",
BUFER
DB 100 DUP(?)
DATA ENDS
END BEGIN

Puc. 13.8. .
/ loci.asm
/
PUBLIC COPY, PRINT
/
COD SEGMENT
ASSUME CS:COD
/
COPY PROC
PUSH
MOV BP,SP
SUB SP,2 / [-2] ( WORD)
/ [+6] - STROKA2
/[+10] - STROKA1, [+14] -
MOV WORD PTR [-2],0 /
LDS SI,[+10]
/STROKA1
LDS DI,[+14]
/
LO1:
MOV AL,DS:[SI]
CMP AL,0
JZ
ZER1
MOV DS:[DI],AL

13.

INC DI
INC SI
INC WORD PTR [-2]
JMP SHORT L01

237

ZER1:
LDS SI,[BP+6]

/STROKA2

L02:
MOV
CMP
JZ
MOV
INC
INC
INC
JMP

AL,DS:[SI]
AL,0
ZER2
DS:[DI],AL
DI
SI
WORD PTR [-2]
SHORT LO2

ZER2:
MOV BYTE PTR DS:[DI],0 ;0 -
MOV AX,[-2]
; -
/ ,
ADD SP,2
POP
/
RETF 16
COPY ENDP
; ,
/
PRINT PROC
PUSH
MOV ,SP
LDS SI,[BP+]
/BUFER
LO3:
MOV DL,DS: [SI]
CMP DL,0
JZ
ZER3
MOV AH, 2
INT 21H
INC SI
JMP
SHORT L03
ZER3:
POP BP
RETF 4
PRINT ENDP
COD ENDS
END
Puc. 13.9. .

238

ASSEMBLER.

13.8 13.9. . , ( ) COPY . ,


PRINT ,
, 0. ,
15.

14. .
- , !
. .
.. .
.
(. [5,9,11,17]).
, - (, DISKED1T Norton Utilites)
, . MS DOS, Windows.
Windows .
Windows, [27,29].

I. - MS DOS.

+0

MZ

, -

+2

PartPag

+4

PageCnt

(512 .),

+6

ReloCnt

+8

HdrSize

MinMem

ReloSS

+10

EXESp

SP

+12

ChkSum

+14

ExelP

IP

+16

ReloCS

+18

+1

Overlay

, 0

* **
_____
** ( 1)'
+?
4*?
. ... .

. 14.1. -.

ASSEMBLER.

240

DSEG
TEXT
DSEG
SSEG

SEGMENT
DB ' - . ' , ' $ ' , 1 3 , 1 0
ENDS
SEGMENT STACK
STAC DW 60 DUP(?)
SSEG ENDS
CODSEG SEGMENT
ASSUME CS:CODSEG, DS:DSEG, SS:SSEG
BEGIN:
MOV AX,SEG TEXT
;*
MOV DS,AX
MOV AX,SEG STAC
;*
MOV SS,AX
LEA DX,TEXT
MOV AH,9
INT 21H
MOV AH,4CH
INT 21H
CODSEG ENDS
END BEGIN

. 14.2. .
-.
0000: 4D
0010: 78
0020:
0030: 00
0040: 00
0050: 00
0060: 00
0070: 00
0080: 00
0090: 00
: 00
: 00
: 00
OODO: 00
: 00
OOFO: 00
0100: 00
: 00
0120: 00
0130: 00
0140: 00

5
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00

6
16

00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00

00
FD
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00

02
00

00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00

00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
'00
00
00
00
00
00

02

00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00

00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00

20
IE
00
00
00

00
00
00
00
00

00
00
00
00
00

00
00
00
00
00

FF
01
00
00
00

FF
00
00
00
00

02
01
00
00
00

00
00
00
00
00

MZ.
..
...
...
...

00 00
00 00
00 00
00 00
00 00
00 00
00 00
00 00
00 00
00 00
00 00
00 00
0.0 00
00 00
00 00
00 00

00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00

00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00

00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00

00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00

00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00

00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00

...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...

14.

0150: 00 00 00 00
0160: 00 00 00 00
0170: 00 00 00 00
0180: 00 00 00 00
0190: 00 00 00 00
01: 00 00 00 00
01: 00 00 00 00
01: 00 00 00 00
01DO: 00 00 00 00
01: 00 00 00 00
01FO: 00 00 00 00

00
00
00
00
00
00
00
00
00
00
00

00
00
00
00
00
00
00
00
00
00
00

00
00
00
00
00
00
00
00
00
00
00

00
00
00
00
00
00
00
00
00.
00
00

00
00
00
00
00
00
00
00
00
00
00

00
00
00
00
00
00
00
00
00
00
00

00
00
00
00
00
00
00
00
00
00
00

241

00
00
00
00
00
00
00
00
00
00
00

00
00
00
00
00
00
00
00
00
00
00

00
00
00
00
00
00
00
00
00
00
00

00
00
00
00
00
00
00
00
00
00
00

00
00
00
00
00
00
00
00
00
00
00

.
( ):
0200: 8 1 7 AD EF 20 - 45 58 45 2D AF A3 -
0210: 2 24 OD - 00 00 00 00 00 00 00 .$
( 02):
0220:
0230:
0240:
0250:
0260:
0270:
0280:

00
00
00
00
00
00
00

00
00
00
00
00
00
00

00
00
00
00
00
00
00

00
00
00
00
00
00
00

00
00
00
00
00
00
00

00
00
00
00
00
00
00

00
00
00
00
00
00
00

00
00
00
00
00
00
00

0290: 00 00 00 00 00 00 00 00

00
00
00
00
00
00
00

00
00
00
00
00
00
00

00
00
00
00
00
00
00

00
00
00
00
00
00
00

00
00
00
00
00
00
00

00
00
00
00
00
00
00

00
00
00
00
00
00
00

00
00
00
00
00
00
00

- 00 00 00 00 00 00 00 00

( ):
02: 8 00 00 8 D8 8 02 00
02: CD 21 4 4 CD 21 00 00

- 8 DO 8D 16 00 00 4 09
- 00 00 00 00 00 00 00 00 . ! . L . ! ,

. 14.3. - (. 14.2) .
. 14.1 -.
, -
. , , ,
( JMP CALL,
MOV AX.SEG ). -
. . , -, .

242

ASSEMBLER.

, - . , -
, , ..
, , . . 14.2
, - . 14.3. . 14.1, , 1. 2 ( 4 ):
1- 01 00 00, .. :0001 - ; 2-
06 00 02 00, .. 0002:0006 - . ,
.
.
, , 0. , , , -
. . .
:
8 00 00

MOV , 0

8 D8

MOV DS,AX

8 02 00
8 DO

MOV ,02
MOV SS,AX

8D
4
CD
4
CD

16 00 00 LEA D X , [ 0 0 0 0 ]
09
MOV ,09
21
INT 21H
4
MOV ,4
21
INT 21H

; 0-
; 2-
; 0-

. , - ,
(PageCnt-l)*512+PartPag. . ,
( ):
) ,
) .

- Windows
(16- ).
16- , Windows 95 ( OS/2 1),
:

14.

243

DOS-
DOS-,
MS DOS
Windows-
Windows-
, DOS DOS-, .
Windows , Windows ( NE) . 16- Windows.

NE - , - Windows

+2

2
1

+3

+4

+6

+8
-

32- CRC

: OOOOh - NOAUTODATA OOOlh - SINGLEDATA


0002h - MULTIPLEDATA 2000h -
SOOOh -

automatic

, DS

+12

, DS (0 - DS SS)

+14

CS:IP

+18

SS:SP

+1

+20

(
)

+22

(...)

+24

(...)

+26

(...)

244

ASSEMBLER.

+28

(...)

+2

(
)


( 2, )

32

34

10

- , Windows
(32- ).
-. , WINNT.H
C++ Windows. IMAGE_NT_HEADERS.

II. .
MS DOS 1.
13
. , , -
, , , .. - ,
. , ,
[13,17] (. 8).
. :
-02,
DL - (0 - , 1 - ; 80, -81)
DH - ,
AL - ,
ES:BX - ,
- : 6 - , - , 8 7
(8-10,7-9).
0:0078 - (. 14.10).
:
, .
. .
.
:
-05,

14,

245

AL - ,
- ( , -),
DL - ,
DH - ,
ES:BX - .
: 1- - , 2- - , 3- - , 4- - (0-128,1- 256,2 - 512, 3 -1024).
: 1- 0 - , 80 -
, 2- . .
, .
, . - .
, . , -
.
: - , . , BIOS
. 1 - , , .
25, 26. DOS -
(
-1, - ).
. : - 25, AL - (0 - , 1 - , 2 - ..), ,
DX - ,
DS:BX - .
:
, .
(. 12, 25/26 ).
. . DOS 4.0
32 .
,:
DS:[BX] - (DWORD),
DS:[BX+4] - (WORD),
DS:[BX+6] - (WORD),
DS:[BX+8] - (WORD).
. . . : / ;
, .

246

ASSEMBLER.

III. .
. 0, (1,0,0)38. -.
(. 14.4), . .
. -, 0.
(Master Boot Sector - MBS).
, - . - : , (Partition Table)
(. 14.5). ,
, (. 14.6). BIOS MBS 0:7
. , Partition Table,
- , . , .
MBS. , , , Partition Table, 2. (Extended). , MBS, . Partition Table
, Extended
.. . 14.7. ,
. .

38

JMP

, -

11

13

(<32 )

15

16

FAT

18

: ,
, .

247

14.

""

20

24

25

26

1
1

27

28

11

36

29

1FEH

55

. 14.4. Boot-. 16,


- BIOS Parameters Block.

446

OOH-1BDH

1BEH-1CDH

16

1CEH-1DDH

16

1DEH-1EDH

16

Partition

1EEH-1FDH

16

Table

1FEH-1FFH

55

. 14.5. (Master Boot-).

01
02

1
1

04


80 -
-

0-7: (0-255)
0-5: (1-63)
6-7: ..
0-7: .. (0-1023)

00 -
01 - DOS 2.X 12-. FAT
04 - DOS . 16-. FAT

ASSEMBLER.

248

05
06

1
1

07

05 - DOS 3.3 Extended-


06 - DOS 4.X 16-. FAT

0-7: (0-255)
0-5: (1-63)
6-7: ..
0-7: .. (0-1023)

08


. 14.6. .

Master Bool-
Partition Table
Boot-
Fat-,
, .

master
boot
.
boot-
FAT, ,

master
boot
.
boot-
FAT, ,

. 14.7. .

249

14.

(. 14.8) . - , .
DATA SEGMENT
BUFER DB 512 DUP(?)
DATA ENDS
STT SEGMENT STACK
DW 40 DUP(?)
STT ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:STT
BEGIN:
/

MOV AX,DATA
MOV DS,AX
MOV ES,AX
MOV AX,STT
MOV SS,AX
;
LEA BX,DS:BUFER
MOV AX,0201H
MOV DX,0080H
MOV CX,0001H
INT 13H

;
/
MOV DH,DS:BUFER [1BFH]
MOV CX,WORD PTR DS:BUFER [1COH]

;1+1
;1+2

MOV AX,0201H
;
INT 13H
MOV BYTE PTR DS:BUFER [3+8],'$'
;
MOV DX,BX

ADD DX,3
MOV ,9
INT 21H
KON:
.MOV AH,4CH

INT 21H
CODE ENDS
. END BEGIN
Puc. 14,8. .

250

ASSEMBLER,

. 14.9
. , .
CODE SEGMENT
ASSUME CS:CODE, DS:CODE, SS:CODE, ESrCODE
ORG 10OH
BEGIN:
;
MOV DL,80H ;
MOV ,2
;
MOV DH, 0
;
MOV AL,1
/
MOV , 1
; 1,
LEA BX,BUF ;ES:BX
PUSH CS
POP ES
INT 13H
JC
NO_R
;
CMP WORD PTR BUF+1FEH, OAA55H
JZ
OK
;
LEA DX,MES4
MOV AH, 9
INT 21H
MOV WORD PTR BUF+1FEH,OAA55H
MOV AH,3 ;
MOV DL,80H
MOV DH,0
MOV AL,1
MOV CX,1
LEA BX,BUF
INT 13H
JC
NO_W
RET
OK:
LEA DX,MES3
MOV AH, 9
INT 21H
RET
NO R:
LEA DX,MES1
MOV AH, 9

14.

251

INT 21H
RET
NO_W :

BUF
MES1
MES2
MES3
MES4
CODE

LEA DX,MES2
MOV AH,9
INT 21H
RET
DB 512 DUP(?)
DB ' ',13,10, '$'
DB ' 1,13,10, '$'
DB ' !',13,10, '$ '
DB ' , .',13,10,'$'
ENDS
END BEGIN
. 14.9. .

IV. .
: - __,
- __, ,
- - ., FAT- - _, - ._., FAT- - ._.
-.
: FAT-39 40. 41 . , . .
32 . :
32*._./1024, ._.=512 16, 32 . ( ): ._.+._*._.
( ):
._.+._*._+32*._./__.
, . 14.10.
.
, .
FAT-. FAT- .
39
40

41

FAT - file allocation table, .. .


FAT-, , , , . , ,
, .
"" , .

252

ASSEMBLER.

16

18

. 14,10. .
FAT- . 12-, 16. Partition Table. ( ). , FAT- . , , FAT-
. , .
. MS DOS ( , , ). (5 12- ) FFH. FAT- :
()
(F)FFOH-(F)FF6H
(F)FF7H
(F) FF8H-(F)FFFH
(0)002-(F)FEFH

,
,
,
,
.

16- FAT.

: ..+(-2)*.__., ._. - .
, , FAT-, .
, , , ..
FAT- . , ,
FAT-. : 20740, 16- FAT-, 12- .
-.

14.

253

MS
DOS. , .

:
1:
2:
3:
4:

1
1
1
1
1

- \.
- .
- .
- .
- .

5 : 1 - .

. 14.11. .
, FindFirst
FindNext . .. , . , ,
, : ,
, .
, . , DOS 0,1,2,5. ,
MS DOS.
Windows , ..
32 . .
: 7 - ( ),
8 - , 10 - , 11 - (
). Windows
API GetFileAttributes SetFileAttributes.

.

.
. . : 5 , - 6 ( 5 10), - 5 .
, 2 ( ).
57 (. 6).
Windows.
( ): , , . 100- , 1600 . 64- . API- GetFileTime
SetFileTime. , , Windows
, () , () ,
.
,
, .

254

ASSEMBLER.

40

0-3: SRT (step rate time); 4-7: head unload time

+1

0: l=ncn.DMA; 2-7 :head load time

+2

(55-
)

4-3

(0=1 28, 1=256,2=512,3=1024)

44

4-5

4-6

4-7

4-8

- ( 6)

49

40

( 1 /8- )

. 14.12. , ,
1.

+2
+3

2
1
2

starting reduced-write current cylinder

+5

starting write precompensation cylinder

+7
+8

maximum ECC data burst length +- bit 7: disable disk-access retri


drive step options _-| bit 6: disable ECC retries +- bits 2-0: drive option

+9

1
1

40

()

. 14.13. , ,
41 . ,
46.

14.

255

V. 32- FAT.
FAT. . . -, FAT- . -, , . - .
, , . , . 40% .
Windows 95
32- FAT. 4 . , , .
, 32- FAT - , .. .
( ) . .

VI. .
, 52, . .

-8

-2

CLOCKS

12

CON

16

18

22

32

33

34

18

NUL

63

X BUFFERS=X, Y

65

Y BUFFERS=X,Y

67

ASSEMBLER.

256

2
. 4. : 6 . 4 FFFFH,
. , , ,
MS DOS.
.

,
, 0,

13

15

17

21

25

27

31

32

11

46

PSP ,

53

19 ,
.

. MS DOS.
MS DOS, , ,
, , .

14.

257

1. . -
. Windows 95 (. ).
2. , , . ,
"" , DOS.
3. . Disk Doctor.
4. . DISKEDIT.EXE,
. , 25, 1.

VIII. .
Windows 95 .
.
Microsoft . ( 32- ) .
.
: ,
OFH, DOS. ,
Windows 95 ?
1. :
.
2. .
3. ,
( ), OFH,
, (. ).
4. - . ~, - 1 . , , .
.
:
1. UNICODE ( 2 ).
2. -
, .
:
0 - ,
0-4 1-31,
5 = 0,
6 -1 - (, ),
7 = 0,
1-10 - ,
9-4072

258

ASSEMBLER.

11 - OFH (),
12- ,
13 - ,
14-25 - ,
26-27 ,
28-31 .

. , MS DOS (.
). Windows 95 . , .

15.
.
,
: ...
..
.
, .
, ASM.
, . , , , .
,
, (. 13 1).
.
[16]. . (, ): TURBO C++ (BORLAND), TURBO
PASCAL (BORLAND) QUICK BASIC42 (MICROSOFT). , ,
,
. , , .

I.
. 15.1 , _CLRSCR
. ,
( ), . . 15.2,15.3,15.4. .
1. BASIC
(. 15.2), . LINK.EXE.
2. . ,
: MOD2 /.
42

, , BASIC.

260

ASSEMBLER.

3. ++ TLINK.EXE.
LARGE.
,
(. . 15.13).
EXTRN _PR:FAR
CODE SEGMENT
ASSUME CS:CODE
PUBLIC _CLRSCR
_CLRSCR PROC FAR ;
PUSH AX
PUSH BX
PUSH CX
PUSH ES
MOV AX,OB800H
;
MOV ES,AX
MOV C X , 2 0 0 0
XOR BX,BX
LOO:

MOV

ES:[BX],0700H

ADD

BX,2

LOOP LOO
POP
POP
POP
POP

ES
CX
BX
AX

CALL FAR PTR _PR


RET

_CLRSCR ENDP
CODE ENDS
END

Puc. 15.1. ,
. 15.2, 15.3, 15.4. ASIC
.
DECLARE SUB CLRSCR
CALL CLRSCR
END

SUB PR STATIC
PRINT'TIPOUEflyPA QUICK BASIC"
E N D S U B
.
. . - . .
Puc. 15.2. QUICKBASIC.

15.

261

{ MODI.PAS }
UNIT
. . . ' ; '
MODI;
INTERFACE
PROCEDURE _PR;
PROCEDURE _CLRSCR;
IMPLEMENTATION
{$L BLOK}
PROCEDURE _CLRSCR; EXTERNAL;
PROCEDURE _PR;
BEGIN
WRITELNC TURBO PASCAL1);
END;
END.
{ MOD2.PAS TURBO PASCAL}
USES MODI;
BEGIN
_CLRSCR;
END.

Puc. 15.3. .
#INCLUDE <STDIO.H>EXTERN VOID CLRSCR(VOID);VOID

PR(VOID);

VOID PR(VOID)
{
CHAR 3[]=" TURBO CI++\N";
PUTS(S);

VOID MAIN(VOID)
{
CLRSCR();

. 15.4. .
, . 15.115.2. , .
. , . .
, (, ) -
, . ,

262

ASSEMBLER.

PUBLIC EXTRN43. .
, . :
1. , .
2. .
- . . , .
CODE, CSEG _. ,
, . , . ( ), , . , , -, _PR, _CLRSCR FAR,
-, MOD I .PAS INTERFACE.
: _PR . ,
_PR . RETN,
RETF, . CALL. , FAR _PR NEAR.
. ,
_CLRSCR . , .

_CLRSCR ( FAR NEAR).
, .
MEDIUM LARGE,
. , , .
(FAR NEAR), ..
. SMALL, . , , SMALL . , . FAR NEAR, a
_ SEGMENT BYTE PUBLIC 'CODE'.
, ( , ) . , , . LARGE. ,
, FAR NEAR. He NEAR. ,
, -S . 43

PUBLIC EXTERN .

15.

263

, , ,
, .
, .
44
. .

.
. , ,
.
.
, ,
. ,
. ,
, . .
CONST (), , _ ( ), DATA, DSEG , _BSS. . 15.5 ,
. , . ,
STR. , , ( ASCII,
).
. 15.6 ++. .
0. LARGE MEDIUM.
. , . , . ,
, . BC_DATA BC_VARS (
WORD). , , , . , COMMON. , , BLANK.
COMMON , , . . 15.7 . .
44

BASIC MICROSOFT .

264

ASSEMBLER.

;
DATA SEGMENT WORD 'DATA'
EXTRN STR:NEAR
DATA ENDS
PUBLIC PRINT;
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
PRINT PROC FAR /
PUSH DS
PUSH AX
PUSH CX
PUSH BX
MOV AX,SEG STR
MOV DS, AX
XOR CH,CH
MOV CL,BYTE PTR DS:STR
MOV BX,OFFSET DS:STR+1
MOV AH,2
LOO:
MOV DL,DS:[BX]
INT 21H
INC BX
LOOP LOO
POP BX
POP CX
POP AX
POP DS
RET
PRINT ENDP
CODE ENDS
END
{ 1 }
UNIT MODI;
INTERFACE
VAR
STR: STRING/PROCEDURE PRINT;
IMPLEMENTATION
{$L BLOK}
PROCEDURE PRINT; EXTERNAL;
END.

15.

265

{ 2 }
USES MODI;
BEGIN
STR: = ' ' ;
PRINT;
END.

. 15.5.
Turbo Pascal.
;
_DATA SEGMENT BYTE PUBLIC 'DATA'
EXTRN _STR:BYTE
_DATA ENDS
PUBLIC _PRINT
CODE SEGMENT
ASSUME CS:CODE, DS:_DATA
_PRINT PROC FAR ;
PUSH DS
PUSH AX
PUSH BX
MOV AX,SEG _STR

MOV

DS, AX

MOV

BX,OFFSET DS:_STR

MOV

AH,2

LOO:
CMP

BYTE PTR DS:[BX],0

JZ

_END

MOV

DL,DS: [BX]

INT
INC

21H
BX

JMP

SHORT LOO

POP
POP
POP
RET

BX
AX
DS .

_END:

_PRINT ENDP
CODE ENDS

END
/* */
EXTERN VOID PRINT(VOID);
CHAR STR[]="nE4ATAIO .";
VOID MAIN(VOID)
{

PRINT ( ) ;

. 15.6.
++.

266

ASSEMBLER.

/
COMMON SEGMENT BYTE PUBLIC 'BLANK'
COMMON ENDS
PUBLIC INASM
CODE SEGMENT
ASSUME CS:CODE
INASM PROC FAR
PUSH DS
PUSH AX
MOV AX,COMMON
MOV DS,AX
MOV WORD PTR DS:[0],1234
/
MOV WORD PTR DS:[2],456
/

POP AX
POP DS
RET
INASM ENDP
CODE ENDS
END

'
DECLARE SUB INASM
COMMON SHARED AA AS
COMMON SHARED BB AS
AA=23
BB=990
PRINT AA,BB
CALL INASM
PRINT AA,BB
END

INTEGER
INTEGER

Puc. 15.7.
.

III.
. 13, . , ( , S), . . 15.8.
. 15.9. ,
( ).
RET , - .
, ..

267

15.

(SP-K). , .
.
, [+6],
(
) [-2] ( ). [+4]. , 4 - DS, SS, SP, .
.
, . , - (, ,
DS).
_ PROC FAR
PUSH
MOV , SP
SUB SP, ._. ,-
;
{ }
{ }
{ }
ADD ,._
/
POP
RET
ENDP

. 15. 8. .

<

SP


. 15.9. .

268

ASSEMBLER.

, SUB SP,PA3M._JIOK. ,
. ,
, : ,
. , , , , , . .
, , . . , . . , 4 . 4
, . - . ,
SUM(A,B:WORD), , .
, .
;
PUBLIC PRO
JTEXT SEGMENT
ASSUME CS:_TEXT
PRO PROC
PUSH BP
MOV BP,SP
PUSH AX
PUSH DX
PUSH DS
PUSH BX
LDS B X , [ B P + 4 ]
MOV
DL,[BX]
MOV
AH, 2
INT
21H
MOV
BYTE PTR [BX],65
LDS
BX,[BP+8]
MOV
DL,[BX]
INT
21H
POP
BX
POP
DS
POP
DX
POP
AX
POP
BP
RET,
PRO ENDP,
_TEXT ENDS
END

15.

269

{ }
VAR
A,B:BYTE;
I:LONGINT;
{$L BLOK}
PROCEDURE PRO(VAR , : B Y T E ) ; EXTERNAL;
BEGIN
A:=65; B:=66;
PRO(A,B);
WRITELN;
WRITELN(CHR(A),CHR(B));
END.
Puc. 15.10.
.
. 15.10.
PRO, . , , . PRO, "" :
, - .
, PRO.
, ,
MOV DL, [+4]
MOV ,2
INT 21H

MOV BYTE PTR [+4],65


MOV DL, [+]
INT 21H

RET 4, ..
- . "" .
.
, .
, .
. :
1. .
2. ,
DECLARE
BYVAL. CALLS
, . SEG ,
.

ASSEMBLER.

270

;
PUBLIC INASM
EXTRN INBAS:FAR
CODE SEGMENT
ASSUME CS:CODE
INASM PROC FAR
PUSH BP
MOV BP,SP
PUSH AX
PUSH BX
PUSH DS
LDS BX,[BP+6]
ADD WORD PTR [BX],10
LDS BX,[BP+10]
ADD WORD PTR [BX] , 10
PUSH WORD PTR [BP+10]
PUSH WORD PTR [BP+6]
CALL INBAS
POP DS
POP BX
POP AX
POP BP
RET 8
INASM ENDP
CODE
ENDS

END

'
DECLARE SUB INASM(SEG A1%,SEG A2%)
A%=13:B%=2623
PRINT A%,B%
CALL INASM(A%,B%)
END

SUB INBAS(XI%,X2%)
PRINT X1%,X2%
END SUB

Puc. 15.11. ,
.
. 15.11. , , , . , INBAS ( 10)
. INASM INBAS .

15.

271

. , - . , - .
, .
. , SMALL , LARGE . NEAR FAR.
;
PUBLIC _INASM
EXTRN _INCI:FAR
CODE SEGMENT
ASSUME CS:CODE
I
J

DW 0
DW 0

_INASM PROC FAR


PUSH BP
MOV BP,SP
PUSH DS
PUSH BX
PUSH CS
POP

DS

MOV

A X , [BP+6]

SHR A X , 1
MOV I, AX

MOV
PUSH
MOV
PUSH
PUSH
MOV
PUSH
CALL

J,10000
DS
AX,OFFSET I
AX
DS
AX,OFFSET J
AX
_INCI

ADD SP,8

POP BX
POP DS
POP BP
RET
_INASM ENDP
CODE ENDS
END

/* */
EXTERN INT INASM(INT I ) ;
INT INCIUNT * I, INT * J) ;

272

ASSEMBLER.

VOID MAIN(VOID)

PRINTF("%D",INASM(30000));
INT INCKINT *I,INT *J)
RETURN((*I)+(*J));

Puc. 15.12.
.
. 15.12 . . 2
, . , . ,
. , , , ( ). ,
. , , . : . ,
"", . :
, . , (
"" ), .
, .
, .
.
, ,
.

IV.
, , . , , .
, . , .
: , , .
, , . -

15.

273

, .
, , .
, , . ,
DS SS.
. , .
SI DI. ,
.

V.
, ,
. : _CLRSCR() - . , BORLAND, , , ,
.
; CLR.ASM
EXTRN _CLRSCR:FAR
PUBLIC _MAIN
; COL.OBJ
_DATA SEGMENT
_DATA ENDS
STK SEGMENT STACK
DB 100 DUP(?)
STK ENDS
JTEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TEXT,DS:_DATA,SS:STK
_MAIN PROC FAR
CALL FAR PTR _CLRSCR ;
; , RET
MOV AH,4CH
INT 21H
_MAIN ENDP
_TEXT
ENDS
END
Puc. 15.13. , .
CLR.OBJ.
.
CL.LIB ( ) COL.OBJ,
(

274

ASSEMBLER.

COL.OBJ, _AIN). : LINK


COL+CLR. CL.
.
; PUTS.ASM
EXTRN _PUTS:FAR

PUBLIC _MAIN
; COL.OBJ
_DATA SEGMENT BYTE PUBLIC 'DATA'
;
S DB '.',
_DATA ENDS
STK SEGMENT STACK
DB 100 DUP(?)
STK ENDS
_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TEXT,DS:_DATA,SS:STK
_MAIN PROC FAR
;
PUSH DS
LEA AX, S
PUSH AX
CALL FAR PTR _PUTS ;
/
POP DX
POP DX
; , RET
MOV ,4
INT 21H
_MAIN ENDP
_TEXT ENDS
END
Puc. 15.14. .
. 15.14 , . .
, .
POP DX .

VI.
. DBASE, , .
:

275

15.

LOAD
CALL

* ,
* BIN
[WITH ]

CALL . , . RELEASE. - , ORG100H


ORG 0. DS:[BX].
0, , . .
, .. .
. 15.15 , , .
CODE SEGMENT
ORG 0
ASSUME CS:CODE
CMP B X , 0

JZ EXIT
;
MOV AH,2L1:
MOV DL,DS:[BX]
CMP DL,0
JZ EXIT
; ?
INT 21H
INC BX
JMP SHORT LI
;-- -EXIT:
RETF
CODE ENDS
END
)
AA=' .'
LOAD WWW
* W W W . B I N
CALL WWW WITH AA

)
. 15.15. FOXBASE.
. 15.15
FOXBASE. , .

276

ASSEMBLER.

VII.
, . ,
.
. , . , -:
,
( DEBUGER BORLAND CODEVIEW ). .
, BYTE (UNSIGNED CHAR)
( INT). , .
.
INT 1=1;
WHILE (=10)
[I]='' ;

?
: , . . I SI. .
MOV
JMP

SI,1
SHORT L1

;INT 1=1

MOV
INC

BYTE PTR [BP+SI-10],72 ; C [ I ] = ' H '


SI
;!++

CMP
JLE

SI, 10
SHORT L2

L2:

LI:

.
, I UNSIGNED CHAR (.. BYTE). .
MOV
JMP

CL,1
SHORT LI

/UNSIGNED CHAR 1=1

MOV
MOV
LEA
ADD
MOV

AL, CL
AH, 0
DX,WORD PTR [BP-10]
AX,DX
BX,AX

L2:

15.

MOV
INC

BYTE PTR S S : [ B X ] , 7 2
CL

CMP
JBE

CL,10
SHORT L2

277

;C[I]='H'
;!++

LI:

, ? ! , , . INT1= 1.
MOV
JMP

WORD PTR [BP-12],1


SHORT LI

LEA
MOV
ADD
MOV
INC

AX,WORD PTR [BP-10]


BX,WORD PTR [BP-12]
BX,AX
BYTE PTR S S : [ B X ] , 7 2
WORD PTR [BP-12]

CMP
JLE

WORD PTR [BP-12],10


SHORT L2

;INTI=1

L2:

;C[I]='H'
;!++

LI:

UNSIGNED CHAR 1= 1.
MOV
JMP

BYTE PTR [BP-11],1


SHORT LI

MOV
MOV
LEA
ADD
MOV

AL,BYTE PTR [BP-11]


AH, 0
DX,WORD PTR [BP-10]
AX,DX
BX,AX

/UNSIGNED CHAR 1=1

L2:

MOV
INC

BYTE PTR S S : [ B X ] , 7 2 ; C [ I ] = ' H '


BYTE PTR [BP-11]
;!++

CMP
JBE

BYTE PTR [BP-11],10


SHORT L2

LI:

,
. INT1= 1.
. I .

278

ASSEMBLER.

. ,
, . , . .
1 .
LONG [10] ;
INT I;
FOR(I=0; K10; I++) [1]=1;

2.
LONG [10] ;
LONG * S;
INT I;
S=&C[0] ;
FOR (1=0; K10; I++) * ( S + + ) = 1 ;

, .
1 .
XOR
JMP

DX,DX
SHORT LI

MOV
MOV
SHL
LEA

BX,DX
;
CL,2
;
BX,CL
;
AX, WORD PTR [BP-40]

L2:

ADD

BX,AX

MOV
MOV
INC

WORD PTR S S : [ B X + 2 ] , 0
WORD PTR S S : [ B X ] , 1
DX

CMP
JL

DX,10
SHORT L2

LI:

2.
XOR
JMP

AX, AX
SHORT LI

LES
MOV
MOV

BX, DWORD PTR [BP-4]


WORD PTR E S : [ B X + 2 ] , 0
WORD PTR E S : [ B X ] , 1

L2:

15.

ADD WORD

PTR [BP-4],4

INC

,10

JL

SHORT L2

279

;
; 4

L1:

, . : , , , , . 4,
. , ,
: .
, . , 64
, . . , , . .
, "". , . . , . , ,
, ,
( , ,
..). , ,
. , ,
, .
. , ,
, .
, . , . , , . .
1. if(!a) if(a.=0). ,
, .
- . ""
, , , DI, :
or di,di
jne 11
..
, . ,
.. . , " ", - .

280

ASSEMBLER.

2. . , , if ?. , , :
i f ( j = = 2 ) i=j; else i=k;

i = ( j = = 2 ) ? ( j ) : (k) ;

, ,
,
, . ,
- .
3. , - 0. . , 0 or (or si,si
..), - . , . , , .

.

.

.
:
1 AL.
2 - .
- DX: .
FLOAT, DOUBLE LONG TOS (. ) ST(0).
3 5 - :
SMALL DX: .
:
1 AL.
2 - .
- DX:AX.
REAL DX:BX: ST(0),
.
POINTER DX: .
STRING , .
.

16. .
,
, .
..
.
IO.SYS .
5. , , . , , , . MS DOS , .
CONFIG.SYS DE VICE=. , .

TSR-. :
1. . "" .
2. ,
COMMAND.COM. , ,
, .
, , .
3.
, . PRN, CON .. "" .
4. ,
, IO.SYS. , ,
, CON. , , DOS,
.
.
[11,23].
DOS , . , .
MS DOS , ,
, CONFIG.SYS.
NULL .
.
-1, .
NULL. , DOS

282

ASSEMBLER.

, DOS ,
.
.
:
1. .
.
DWORD . -1, .
WORD .
WORD () (. ).
WORD () (. ).
8-BYTE . "" ,
.
:
- ,
- .
-. (CON), (AUX), (PRN).
. / ,
. , , ..
. , .
, 0-3 .
, , , , D. , .
, ( Z).
. .
.
.

4-5
6
7-10

()
1

3 .2
()

16.

11

283

12

()

13

14
1

15

0
1

()

2-5
6

()

3.2 /
()

7-10

32-

12

/
()

13

FAT

14

15

. 16.1, .
2. . ,
.
ES:BX (. ). . , . FAR.

. - (. . 16.1).
: , , ,
. , [5,11], .

284

ASSEMBLER,

BYTE

( 13).

BYTE

, (
).

BYTE

(. ).

WORD

. .

8 BYTE

3. , ,
, . .
DOS .
4. , ( .), ,
.
, , . [11].
(INI). 0. () .
.
( 14) .
, . - -
DOS.
(CHECK_MEDIA). 1. . , .
( BIOS) (BUILD_BPB). 2. .
. .
. 3 (IOCTLJNPUT). (, ).
44- DOS .
(INPUT). 4.
.
(READ_NO_WAIT). - 5.
. . DOS , .

16.

285

(INPUT_STATUS). 6.
. ,
, .
(INPUT_FLUSH). 7. ,
.
(OUTPUT). 8. .
(VERIFY_OUTPUT). 9. ,
VERIFY ON, . ,
.
(OUTPUTJSTATUS). 10.
, . , .
(OUTPUT_FLUSH). 11.
. ,
.
(IOCTL_OUTPUT). 12. , . , , .
(CLOSE OPEN). -13 14.
DOS, 11 1. , .
.
.
(REMOVE_MEDIA). -15.
11 1.
, ( ).
(OUT_UN_BUS Y). 16. . , , 13 .
.
. -19. /.
/ .
23 24. MS DOS, 6
.
, . / .
, , .. ,
.

286

ASSEMBLER.

0-7

. , 15 1.

1, .

1, .

10-14

().

15

1, .

-, ORG100H , PSP .
- - - (.. , , device =
d r v . s y s device=drv.exe).
. 16.1 . , .
, CON (.. ). ,
COPY, TYPE 'CON', , ,
DOS.
,
.

16.

287

1. ,
. , ..
.
2. (BIOS). , DOS
, DOS.
3. OUTPUT. .
JMP QUIT - ,
. , JMP EXIT,
.
4. 8 DUP(EXIT), .. EXIT.
, OUT_UN_BUSY 16,
24.
5. , .
.
6. , DOS COPY CON
. .
(INPUT).
7. ,
DOS. , , 7. ? .
.
CODE SEGMENT
DRIV PROC FAR

ASSUME CS:CODE
; ()
DD
ATRIBUT
DW

DW
DB

-1
DW

1010100000000010B
STRATEGY

INTERRUPT
'CON
' ;,
; 8
;
FAR
STRATEGY
PROC
MOV
CS :_BX,BX
MOV
CS :_ES,ES
RETF
LABEL
DWORD
REQ
7
DW .
_
p
DW
_ES
ENDP
STRATEGY

288

;
_SS
DW
?
_SP
DW
?
_AX
DW
?
;
DW
100 D U P ( ? )
STAC DW
;
INTERRUPT PROC
FAR
(
CS:_AX,AX
MOV
MOV
CS:_SS,SS
MOV
CS:_SP,SP
MOV
AX,CS
MOV
SS,AX
SP,OFFSET STAC
MOV
AX,CS: AX
MOV
;
PUSHF
PUSH
DS
BX
PUSH
PUSH
SI
AX
PUSH
DX
PUSH
PUSH
ex
PUSH
DI
;
LDS
SI,REQ
XOR
BH,BH
MOV
BL,DS:[SI+2]
SHL
BX,1
JMP
CS:[TABLE+BX]
;
TABLE
DW
INI
DW
CHECK_MEDIA
DW
BUILD_BPB
DW
IOCTL_INPUT
DW
INPUT
DW
READ_NO_WAIT
DW
INPUT_STATUS
DW
INPUT_FLUSH
DW
OUTPUT
DW
VERIFY OUTPUT

ASSEMBLER.

16.

DW
DW
DW
DW
DW
DW
DW
DW

OUTPUT_STATUS
OUTPUT_FLUSH
lOCTLjDUTPUT
OPEN
CLOSE
REMOVE_MEDIA
OUT_UN_BUSY
8 DUP(EXIT)

CHECK_MEDIA:
JMP EXIT
JMP EXIT
BUILD_BPB:
JMP QUIT
IOCTL_INPUT:
INPUT:
JMP QUIT
JMP QUIT
READ_NO_WAIT
JMP QUIT
INPUT_STATUS
INPUT_FLUSH:
JMP QUIT
STROKA
DB
' '
DB
0
;
NUM_STR
_ CX
DW
?
;
OUTPUT:
PUSH ES
;,
MOV ,3
MOV ,0
INT 10H
CMP DH,24
JNZ
MOV ,2
MOV DH,23
MOV DL,0
INT
D6:
MOV AX,DS
MOV ES,AX
LDS DI,ES: [SI + 14] ;DS:DI
MOV CX,ES:[SI+18] ;
/
LOO:
MOV CS:_CX,CX
; ,
CMP DL,80
JNZ D4
DEC DI
10-4072

289

290

ASSEMBLER.

INC
JMP

CS:_CX
SHORT D5

D4:

CMP BYTE PTR DS:[DI],13

,-
;?

JNZ Dl
D5:

INC CS:NUM_STR
CMP DH,23
JNZ D2
;
MOV ,06
XOR CX,CX
MOV DH,23
MOV DL,79
MOV AL,1
MOV BH,07H
INT 10H
; 23
MOV ,
MOV DH,23
MOV DL,0
MOV AH,2
INT 10H
JMP D3
D2:
;
MOV DL,0
INC DH
MOV AH,2
INT 10H
JMP D3
Dl:
MOV AL,DS:[DI]
CMP AL,10
;
;
JZ D3
;
MOV ,
MOV ,1
MOV BL,7
MOV AH,09H

INT

16.

;
INC DL
MOV ,2
INT 10H
D3:
;
INC DI
CMP CS:NUM_STR,23
JNZ D7
MOV CS:NUM_STR,0
;
PUSH
PUSH DI
MOV ,800
MOV ES,AX
MOV ,3840
MOV DI,OFFSET STROKA
MOV CX,21
MOV AH, 13
L001:
MOV AL,CS:[DI]
MOV ES: [BX],AL
MOV ES:[BX+1] ,AH
INC DI
ADD BX,2
LOOP L001
;
MOV ,
INT 16H
MOV CX,21
MOV BX,3840
;
D9:
MOV WORD PTR ES:[BX],0720H
ADD BX,2
LOOP D9
POP DI
POP BX
D7:
MOV CX,CS:_CX
DEC CX
JZ
D8
JMP LOO
10'

291

292

ASSEMBLER.

D8:
POP ES
JMP QUIT
VERIFY_OUTPUT:
JMP QUIT
OUTPUT_STATUS:
JMP QUIT
OUTPUT_FLUSH:
JMP QUIT
IOCTL_OUTPUT:
JMP QUIT
OPEN:
JMP QUIT
CLOSE:
JMP QUIT
REMOVE_MEDIA:
JMP EXIT
OUT_UN_BUSY:
JMP QUIT
EXIT:
OR
WORD PTR DS: [SI+3] , 8003H

,-
;
;8003H = 10000000 - .
QUIT:
OR
WORD PTR DS: [SI+3],0100H ;
;
;0100H = 00000001 00000000
POP DI
POP CX
POP DX
POP AX
POP SI
POP BX
POP DS
POPF
MOV SS,CS:_SS
MOV
SP,CS:_SP
RETF
END_:
;
INI:
/
/
MOV
WORD PTR DS: [SI + 14],OFFSET END_
MOV
DS: [SI + 10H] , CS
~~
PUSH
CS
POP
DS
;
MOV
,9
MOV
DX,OFFSET STR
INT
21H
JMP
QUIT

16.

STR
DB
'Driver OUTJTEXT is s e t . ' , 1 3 , 1 0 , ' $ '
INTERRUPT ENDP
DRIV
ENDP
CODE
ENDS
END

Puc. 16.1. , CON.

293

17. ""
.
"Mine is a long and a sad tale!"
said the Mouse, turning to Alice,
and sighing. "It is a long tail,
certainly, " said Alice, looking
down with wonder at the Mouse's
tail; "but why do you call it sad?"
A lice's A dventures in Wonderland
by Lewis Carroll
. ( MS DOS), , . , . , .
,
. , , MS DOS,
.. Windows (. 24,25).
"". , , .
,
. , , .

:
1. .
2. .

, - .
.
. ,
.

I.
0: .

. , , :

17. ""

OFFFFH(-l),

16/8

8/8

0,0

,

295


,
FFFFH(-1) -

""


0002

1: . 1 1 . 0,
. -1, . , 0, 1
.

0001

2: . 2
1 .
, "".
, - , .
, - .

296

ASSEMBLER.

, 2
1,
. , 2
.
2 , .
,
.

0002

3: . 3 .

0
!
2

(BL)



( MOUSE SYSTEMS)
3-7


DX

(1), , (0) - .
4: . .
,
.

, . , .

DX

0004

17. ""

297

640 X 200

16X8

, , 3270

640 X 200

16X8

, , 3270

640 X 200

8X8

, , 3270

640 X 200

8X8

, , 3270

640 X 200

2X1

, , 3270

640 X 200

2X1

, , 3270

640 X 200

1X1

, , 3270

640 X 200

8X8

640 X 200

F
10
30

3270

640 X 200
640 X 350
640 X 350
720 X 350
720 X 348

(XXY)

, , 3270

16X8

1X1
1X1
1X1
1X1
1X1

1
1
1
.1
1

:
= IBM /
C = IBMCGA
= IBM EGA
3270 = IBM 3270 PC
=
5: . 5 ,
,
.
0 OEFFFH.
. .

0
1
2

0005
(BL)



(AL) .
0

ASSEMBLER.

298

DX

!

2

( MOUSE SYSTEMS)





.

(1), , (0) - .
6: . 6 5 , , .
0 OEFFFH. . .

0
1
2

DX

0006
(BL)



(AL)
0

!

2






.

, (1), , (0) - .
7: (X).
7 . . , .

17. ""

DX

299

0007

,
.
8: (Y). 8 . .

, .

DX

0008

,
.
9: . 9
, " " .
(. .9),
16 16 16 16
( ). 0 16.

0009


DX


ES:DX
16 -
16 -

300

ASSEMBLER.

16 . .
10: . 10
.
-, . .



01
-
DX -


11: . 11 ( , ), . .
-32768 32767. . .


DX

12: . 12
,
. ,
. , .
, .
(1) , (0) - .

0
!
2

17. ""

4
5
6
7-15
ES:DX FAR

301




(MOUSE SYSTEMS)

(MOUSE SYSTEMS)

MISROSOFT .
LOGITECH MOUSE SYSTEMS .
:

DX

SI

( , )




0 12. (
, .)
13: . 13
. "
".
" " " " :
- " ", - " ".

. ,
14 .

OOODH

14: . 14 . -

302

ASSEMBLER.

15: /. , 8 .
1 OEFFFH.
/: - 8/8; - 16/8.

DX

OOOFH
8
8

16: . 16
. , . 1.

ES:DX

0002
0004
0006

00
,

17: .
:
PC MOUSE. MICROSOFT .
17 9. ,
17 , .

0011
(2 )

17. ""

303

BL


( -16 16)
ES:DX
(') -
(') -

OFFFFH (-1)

18: .
19: . ( ), .
64 .

DX

0013

20: . 20 ,
, (. . 12).
,
.

0014
BX-.DXFAR

(. .12)
0
1
2
3
4 .
5
(MOUSE SYSTEMS)
6
(MOUSE SYSTEMS)
7 -15

BX:DX

FAR

AX,BX,CX,DX,SI,DI,DS ES.

304

ASSEMBLER.

21: .
21 , ,
.

0015
,
()

22: . 22
. 21.

ES:DX

0016

23: . 23
, (. 21,22).

ES:DX

0017

24: .
12. ,
, 12. 24.

0018

0
1
2
3
4
5 SHIFT

6 CTRL

17. ""

ES:DXFAR

305

7 ALT

8 -15

OFFFFH-

(1) , (0) .

:

DX

SI

( , )




25: ,
. 25
(
12), , .

0019
( 24)

OFFFFH
BX:DX
(0 = OFFFFH)

(0 = OFFFFH)

26: . 26
,
, .

001



64/

27: . 27 , 26.

306

ASSEMBLER.

001


64/

28: . 28 , .

001
(BL)

01
02

04
05H-FFH


30
50
100
200


04 (BL), MICROSOFT INPORT .
29: . 29
( ).

001DH
(0-7)

30: .

001
(0-7)

31: . 31
, , 71 (
8086) 74 ( 80286/386).
, :, ES:BX. .

17. ""

307

001FH

001FH

: ,


ES:BX

32: . 32
71 (8086) 74 (80286/386), 31.

0020

33: .
33 0 ,
33 .

0021
0021
OFFFFH
0002

34: .

0022
(BL)

01
02

04
05
06
07
08

308

ASSEMBLER.

, ,
MICROSOFT INTERNATIONALMOUSE.
35: .

0023

(BL)

01
02

04
05
06
07
08

36: .

CL

0024
OFFFH , BH:BL


01 ,
02 ,

, MICROSOFT
INPORT
04 , IBM PS/2
roiNnNGDEVICEPORT
05 HEWELETT-PACKARD
(IRQ)
PS/2
01
02HIRQ2
03HIRQ3
07HIRQ7

17. ""

309

.
.
, , . [5,13,24].
, . , ( ,
, ), .
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
ORG 100H
BEGIN:
MOV BYTE PTR SCR,0

CALL

SET_MOUS

CONT:
CALL SCREEN
CALL CUR_VIS
CALL POINT
CALL KEY
INC BYTE PTR SCR
CMP BYTE PTR SCR,20
JNZ CONT
MOV BYTE PTR SCR,2
CALL SCREEN
CALL CUR_NO_VIS
RET
;
SET_MOUS PROC
MOV AX,0
INT 33H
RET
SET_MOUS ENDP
;
CUR_VIS PROC
MOV AX,1
INT 33H
RET
CUR_VIS ENDP
;
CUR_NO_VIS PROC
MOV AX,2
INT 33H
RET

310

ASSEMBLER.

CUR_NO_VIS ENDP
/
SCREEN PROC
XOR AH,AH
MOV AL,SCR
INT 10H
RET
SCREEN ENDP
;
POINT PROC
MOV AH,OCH
XOR BH,BH
MOV DX,20
MOV CX,40
MOV AL,1
INT 10H
RET
POINT ENDP
;
KEY PROC
XOR AH,AH
INT 16H
RET
KEY ENDP
SCR DB 0 /
CODE ENDS
END BEGIN
Puc. 17.1. .
, ,
. - , 9 10 ,
.
( 9). . .
16 16 . , . , , .
, . :
AND . :
0, , ..
, 1, , . -

17. ""

311

XOR
. , ,
, . ,
, ,
1, 0.
( 10,0 )
: . : 15-
- (1) (0) , 12-14 - , 8-11 - , 0-7 - .
: AND , XOR .
, , .
255(11111111),
0. , ,
0. , . , , , , , ,
(. 7).
CODE SEGMENT
ASSUME CS:CODE, DS'.CODE
ORG 10OH
BEGIN:
MOV BYTE PTR SCR,0

CALL SET_MOUS
;
MOV

AX, 9

MOV BX,20
MOV
LEA

CX,10
DX,M1

INT 33H
/
MOV AX,0
MOV
/
MOV
MOV
INT
CONT:
CALL
CALL
CALL
CALL
INC
CMP

,0
/

,01111111111111
/
DX,0001001000000000
/
33H
SCREEN
CUR_VIS
POINT
KEY
BYTE PTR SCR
BYTE PTR SCR,20

312

ASSEMBLER.

JNZ
MOV
CALL
CALL
RET

CONT
BYTE PTR SCR,2
SCREEN
CUR_NO_VIS

;
SET_MOUS PROC
MOV AX,0
INT 33H
RET
SET_MOUS ENDP
;
CUR_VIS PROC
MOV AX,1
INT 33H
RET
CUR_VIS ENDP
;
CUR_NO_VIS PROC
MOV AX,2
INT 33H
RET
CUR_NO_VIS ENDP
;
SCREEN PROC
XOR AH,AH
MOV AL,SCR
INT 10H
RET
SCREEN ENDP
;
POINT PROC
MOV AH,OCH
XOR BH,BH
MOV DX,20
MOV CX,40
MOV AL,1
INT 10H
RET
POINT ENDP

/
KEY PROC
XOR AH,AH:
INT 16H
RET

17, ""

313

KEY ENDP
SCR DB 0 /
Ml:
DW 0000000000000000
DW 0111111111111110
DW 0111111111111110B
DW 0111111111111110B
DW 0111111111111110B
DW 0111111111111110B
DW 0111111111111110B
DW 0111111111111110B
DW 0111111111111110B
. DW 0111111111111110B
DW 0111111111111110B
DW 0111111111111110B
DW 0111111111111110B
DW 0111111111111110B
DW 0111111111111110B
DW 0000000000000000
2:
DW 1111111111111111B
DW 1000000000000001B
DW 1000000000000001B
DW 1000000000000001B
DW 1000000000000001B
DW 1000000000000001B
DW 1000000000000001B
DW 1000000000000001B
DW 1000000000000001B
DW 1000000000000001B
DW 1000000000000001B
DW 1000000000000001B
DW 1000000000000001B
DW 1000000000000001B
DW 1000000000000001B
DW 1111111111111111B
CODE ENDS
END BEGIN
. 17.2. , .
, . 17.2, . 17.1
, , .
, . , , ..

314

ASSEMBLER.

, .
, , , .. .
III.

-
. , , .
, .
. ( ) - (. 12 20).
INT_MOUS.
, , :
MOV ,

MOV
MOV
LEA
MOV
INT

BX,SEG INT_MOUS
ES,BX
,-
DX,INT_MOUS
;
CX,0000000000001011B ;
33H

, . ,
, 0.
, . -
. :
1. - - . , ,
. , " ". , ,
, .
2. .
- . .
, . 17.3, .
TO_BUF

PROC
PUSH ES
PUSH BX
PUSH DI
MOV B X , 4 0 H
MOV ES,BX
MOV BX,1CH

17. ""

MOV
MOV
MOV
CMP
JNZ
MOV
JMP

DI,ES:[BX]
ES:[DI],CL
ES:[DI+1],CH
WORD PTR E S : [ B X ] , 6 0
JJ
WORD PTR E S : [ B X ] , 3 0
SHORT JJ1

ADD

WORD PTR E S : [ B X ] , 2

315

JJ:
JJ1:
POP
DI
POP BX
POP ES
RET
TO_BUF
ENDP

Puc. 17.3. . ASCII


CL, - .
7 . .
-
40: 1 40: 1 . 30 60. 60 30.
2. , . , - 2 -. ,
60, 30. . 17.3 .
. ,
. ,
16 ( 4).
,
TO_BUF.

. ,
(. 12).
,
, , . ,
:
1) , 2) IRET ( CFH) 3)
( 0). , 1, 0.
(. 0).

316

ASSEMBLER.

PROV_MOUS PROC FAR


XOR AL,AL
PUSH ES
PUSH BX
XOR BX,BX
MOV ES,BX
MOV BX,ES:[33H*4]
MOV ES,ES:[33H*4+2]
CMP BX, 0
CONT
JNZ
PUSH BX
MOV BX,ES
CMP BX,0
POP BX
JZ
NO
CONT:
CMP BYTE PTR ES:[BX],OCFH
JZ
NO
XOR AH, AH
INT 33H
CMP AX,-1
JNZ NO
MOV AL,1
NO:
POP BX
POP ES
RETF
PROV_MOUS ENDP
Puc. 17.4. . 1,
.

IV. .
-
. , ,
,
. : , , . .
INT_MOUS PROC
PUSHF
PUSH AX
PUSH BX

17. ""

PUSH
PUSH DS
MOV
AX,DATA

MOV DS,AX ;
TEST BL,1
JZ

N1

TEST BL,2
JZ

N1

XOR DS:PRIZ,255 ;
CALL SOUND
;
JMP

KON

N1:

TEST BL,1
JZ
N2
; ENTER
MOV CL,13
MOV CH,28
CALL TO_BUF
JMP KON
N2:
TEST BL,2
JZ
N3
; ESC
MOV CL,27
MOV CH, 1
CALL TO_BUF
JMP KON
N3:
'
CMP DS:PRIZ,255
JZ
N4
/
OR
SI,SI
JZ
KON
JNS N5
MOV CL,0
MOV CH,75
CALL TO_BUF
JMP SHORT KON
N5:
MOV CL,0
MOV CH,77
CALL TO_BUF
JMP SHORT KON

317

318

ASSEMBLER.

N4:
OR

DI,DI

JZ

KON

JNS
MOV

N6
CL,0

MOV CH,80
CALL TO_BUF
JMP SHORT KON
N6:
MOV

CL,0

MOV CH,72
CALL TO_BUF
;
KON:
MOV AX,OBH
INT 33H
POP DS
POP CX
POP BX
POP AX
POPF
RETF
INT_MOUS ENDP
Puc. 17.5. .
:
(, , , ), ENTER, ESC. , , (ENTER) (ESC).
- . ( ).
PRIZ.
- SOUND (. 6, . 6.5).

V. .
, "" . , , ESC. ENTER,
.
.
- , 1,2 .. . 17.6
.

17. ""

319

INT_MOUS PROC
PUSHF
PUSH DS
PUSH AX
PUSH BX
PUSH CX
;
MOV A X , 0 0 0 3 H
INT

33H

MOV
MOV
MOV
MOV
TEST
JZ

AX,SEG X_MOUS
DS,AX
X_MOUS,CX
Y_MOUS,DX
BX,1
NO_ENT

MOV

MOV
CALL
JMP
NO_ENT:
TEST
JZ
MOV
MOV

CL,11

CH,27
IN_BUF
SHORT NO_ESC
BX,2
NO_ESC
CL,27
CH, 1

CALL IN_BUF
NO_ESC:
;
POP
POP
POP
POP

CX
BX
AX
DS

POPF
RETF
INT_MOUS ENDP
Puc. 17.6. . .
:
1. X_MOUS Y_MOUS , . ,
. ,
, .. . 8.
DS , X_MOUS Y_MOUS.

320

ASSEMBLER.

2.
11. . .
3. , . , -
- : , ..
.
,
. , , .

VI. .
1. , , - ( , ) . 15,19,
26, 28. ,
.
2. .
, .
3. 3 , 640*200. . , 80*25 8:80*8=640,25*8=200. , ,
.
4.
. , - , - ,
. , , , , :
) , -
09 1
)
)
) , ,
) - ,

) , ,

) , , .

18. .
- , .
- ?
- .
, -
.
.. .
.
,
. ,
.
. , .

I. .
- . - , - ( , ). , , . , , , . , ,
, .
, , . , ,
. , ,
. ? ,
. ? . - , , , .
-, :
1. .
.
2. . , , .
3. , , - , .
4. , . , - (
11-4072

322

ASSEMBLER.

) . ,
.
? , : ,
,
, .
- . , ,
, , , .
. , ,
, -? ?
, , .
, . , - . , , . , , , .. , . , ,
. , , ,
( ) . . ( ) ? , .
, MS DOS . , ( ) . ,
, , . , MS DOS Windows, ,
, . .
, UNIX,
. , , ,
.
Windows , .
. ( ,
Word Exel) MS DOS.

. , -, ,
. ,
. , -, ,
. ,

18,

323

. , .
.

.
, .
( ), ,
, ,
.. , .
.
.
, , , - .
, () .
, ( ) ,
.

.
- ,
.
. , , .
, , , . . ,
" " , .

. MS DOS.
().
, (),
,
-. , ,
.
, . , MS DOS (). IV .
() -. "5.
45

11*

ASSEMBLER.

324

1. -. . 18.1
-. -, ,
. , JMP . RET CALL .

JMP

JMP

*-

. 18.1. -.
"" .
2. -. - ,
. -
, CS IP (. 14).
,
. SS SP,
,
.
, .
3. (. 11), . .
DIR . FAT ,
.
,
FAT.
4. . , , , .
, . , , PATH ( , , , ).

18.

325

, , .
Ctrl Alt Del, .. .
, .
. : )
; ) . ,
. , . ,
.. - . .
, ,
.
. , .
-, . , , , .
. "" ,
. , . , (
), DOS BIOS
. , , , , 27. ,
, ,
. , DOS 27 (!). ,
,
.
, , , . , 21-
13- .
.
DOS 4BH,
46. , , ,
. , , 13 21 ,
( ). , , - ,
. , , . , ,
46

CMP AH.4BH.

326

ASSEMBLER.

, (, IRET) , .
, , ( , , ..), (, , ..) .
-.
. , - -, . , .
-, . , .
-. , .

III. () .

boot.

.
.
: , :
1. .
2. .
3. , .
, , 1, . , , . - , .
, , , ,
. . , 0 0 , , Partition Table - ( ).
. , . -
. ( BRAIN) , FAT-, .
, , . ,
. , , .

18.

327

, 6-
(. 18.2). .
MBS - . . BIOS 0000:7 .
ORG
JMP
DW
DW

BEG_VIRVIR_OFF
BEG_1FREE
?
,
,

13_OFF DW
13_SEG DW
INT 13 PROC

; 13
/ 13

BEG_VIR:
XOR ,
MOV DS,AX
;
CLI
MOV SS,AX
MOV AX,7COOH
MOV SP,AX
STI
; 4-
; (RETF)
;
PUSH DS
PUSH AX
; 13
MOV , [13*4]
MOV 13_OFF,AX
MOV AX, [13H*4+2]
MOV 13_SEG,AX
; 2
MOV AX,[413H]
DEC AX
DEC AX
MOV [413],

328

ASSEMBLER.

;
MOV CL,06
SHL AX,CL
MOV ES,AX
/
MOV FREE,AX
;
MOV AX,OFFSET INT_13
MOV
[13H*4],AX
MOV
[13H*4+2],ES

13

;
; 0000:7
;
MOV CX,1BEH
;
MOV SI,7COOH
;
XOR DI,DI
CLD
REPZ MOVSB
; ,
JMP

DWORD PTR CS:VIR_OFF

BEG1:

. 18.2. 6 .
. 18.2 . : ,
. 1 -
. , -
.

IV. .
, , . , , , .
,

CONFIG.SYS. , .. 'DEVICE^'
, .
, , , CONFIG.SYS . ,
. , , CONFIG.SYS . . -

18.

329

:
(. 16)
, .
"". . ,
. IBM- .
, "" .
, ( , MS DOS).
. ( ).
. , 47.
(, , ..) .
, . . MS
DOS - , . , - , . . , - .
, . . .
. .

V. Windows.
Windows 95 .
, :
1. , Visual-Basic ,
MSWORD MSEXEL.
, .
.
, .
, ( AutoOpen). ;- , . . .
47

UNIX .

330

ASSEMBLER.

2. , MS DOS,
Windows. . , - NE. DOS- .
MS DOS. ,
Windows ..
3. Windows-. , ,
. - ( NE ). , -. . , VXD-. SYSTEM.INI,
"" Windows.
SYSTEM.INI ,
WINDOWS. Windows
. , .. . , ,
, . ,
.

VI. .
- , - , - , , ?
- .
.. .
.
- . ...
.. .
.
.
,
:
) . (. ). ,
. , , , 1000
( ) ..
) . , .
.

18.

331

"" , . , . ,
62 (, 63 61 ,
)
.
) , .
, (
..), ..
) , .
, ,
, ..
) ,
. MS DOS (. 9). , ,
( , ).
. , DOS 6.O. . . Windows
.
)
, "" . : *., *., =, COMMAND.
"" , , , .
)
, . , , . ,
.
, , Windows,
. ,
, , . - , , .
, . Windows 95 Windows 98 . , , . ,
.
, .

. .

552

ASSEMBLER.

. ,
, , boot- .. .
. , - . , , . , , , ,
. . , .
. ,
- , . .
. ,
.
. , () .
.
, .. .
.
.
. . "" ,
.
. ,
. - . . , . ,
, , .
, , .

.
. , . , .
. , , "",
.
,
. , .

18.

333

VII. .
.
:
- (),
.
.
. ,
, . , , , , . - XOR:
XOR AL,B, AL.
, , . , , . , , "" - , ,
, , , . , - . , ,
. ,
"" , . NOP, MOV MEM.AX, PUSH AX/POP AX, CLD, STI
.. ,
48.
, . , 49.
,
, . ,
, ,
. , ,

, . , , "-" .
. . DOS FindFirst
48

49

.
, .
, MOV AX.BX XCHG ,/
MOV ,, , MOV , MOV MEM,BX/MOV AX.MEM -
. MEM. ,
.

ASSEMBLER.

334

FindNext . , , ,
, INT 25H
. ,
, DOS . , , , .
, , . , ,
: , .
, . ,
, ( , ?), .
, .
, .
(. 14).
, (, ,
) , , , . . .
MOVAX.BX

PUSHBX

XCHGAX,BX
MOVBX,AX

MOVMEM,BX
MOVAX,MEM

JMPL1

MOVMEM.BX
LEABX.L1
PUSHBX
MOVBX.MEM
REIN

CALL LI

LEABX.L1
MOVMEM,BX
LEABX.MEM
JMP[BX]

ADDAX,CX

PUSHCX
LI:
ADD AX, 1
LOOP LI
POPCX

MOVMEM,CX
ADDAX,MEM

PUSHCX
LI:
ADDCX.1
SUB AX, 1
JNZL1
MOVAX.CX
POPCX

.
,
.
, , . , , "-".
. ,
. ,

18.

335

MS DOS -. .

VII.
,
.
.
, - .50 , ,
( ..).
:
. 18.3 - - - (.
18.5, .).
. 18.4 - - -.
. 18.5 - -. -
. , .
,
.
/ -
CODE SEGMENT
ASSUME CS:CODE, DS:CODE, SS:CODE
ORG 10OH
BEGIN:
;
XOR SI,SI
XOR DI,DI
MOV DL,1
LOO:
CMP BYTE PTR [81H+SI],ODH
JZ
NO_PAR
MOV AL, [81H+SI]
CMP AL,' '
JZ SPACE
XOR DL,DL
MOV [PATH2+DI] ,AL
50

. - .
, .

336

ASSEMBLER.

INC DI
JMP SHORT L001
SPACE:
OR
JZ

DL,DL / DL=0,
NO_PAR

L001:
INC SI
JMP SHORT LOO
NO_PAR:
OR SI,SI
;
JNZ CONT
;,
MOV DX,OFFSET TEXT1
MOV AH,9
INT 21H
JMP _END
CONT:
/ , .
LEA DX,PATH2
MOV ,
MOV AL,2
INT 21H
MOV BX,AX
MOV HANDL2,BX
;
XOR DX,DX
XOR CX,CX
MOV AH,42H
MOV AL,2
INT 21H
;LEN>AX
;
/ +
/ , 1.5
MOV LEN2,AX
CMP AX,64000
JNA _NO
JMP _END
_NO:
/ ""
LEA DX,PATH1
MOV AH,3DH
MOV AL,0
INT 21H

18.

;
MOV ,
MOV AH,3FH
LEA DX,BUF
MOV CX,2000 ,-, 2000
INT 21H
MOV LEN1,AX
;
MOV AH,3EH
INT 21H

MOV BX,HANDL2
MOV AH,40H
LEA DX,BUF
MOV CX,LEN1
INT 21H
;
XOR CX,CX
XOR DX,DX
MOV AH,42H
MOV AL,0
INT 21H
:
LEA DX,BUF
MOV CX,3
MOV AH,3FH
INT 21H

MOV CX,0
MOV DX,LEN2
MOV AL,0
MOV AH,42H
INT 21H
;
LEA DX,BUF
MOV CX,3
MOV AH,4OH
INT 21H
;
XOR CX,CX
XOR DX,DX
MOV AH,42H
MOV AL,0
INT 21H

337

53*

ASSEMBLER.

; , JMP ADR
MOV BYTE PTR BUF,OE9H
MOV AX,LEN2
MOV WORD PTR BUF+1,AX
;
MOV ,4
LEA DX,BUF
MOV CX,3
INT 21H
;
MOV ,
INT 21H
LEA DX,TEXT2
MOV AH,9
INT 21H
_END:
RETN
PATH1 DB 'PO.COM',0 ;
PATH2 DB 80 DUP(O)
; -
TEXT1 DB ' ',13,10, '$'
TEXT2 DB ' ',13,10,'$'
HANDL2 DW ? ,-
;

LEN1
DW ?
LEN2
DW ?
BUF
DB 2000 DUP(?)
CODE ENDS
END BEGIN
. 18.3. -.
; -
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
ORG 10OH

BEGIN:
;
XOR SI,SI
XOR DI,DI
MOV DL,1

LOO:

CMP BYTE PTR [81H+SI],ODH


JZ
NO_PAR
MOV AL,[81H+SI]

18.

339

CMP A L , ' '

JZ SPACE
XOR DL,DL
MOV [PATH1+DI],AL
INC DI

JMP SHORT L001


SPACE:
OR DL,DL ; DL=0,
JZ NO_PAR
L001:
INC SI
JMP SHORT LOO
NO_PAR:
OR SI,SI
;
JNZ CONT
;,
MOV DX,OFFSET TEXT1
MOV AH,9
INT 21H
JMP _END
CONT:
; ,
LEA DX,PATH1
MOV ,
MOV AL,2
INT 21H
MOV BX,AX
/ ( )
MOV AH,42H
MOV AL,0
XOR CX,CX
MOV DX,1
INT 21H
MOV AH,3FH
LEA DX,BUF
MOV CX,2.
INT 21H
MOV DX,WORD PTR BUF ; DX
MOV LEN,DX
;
MOV AH,42H
MOV AL,0
XOR CX,CX
INT 21H

ASSEMBLER.

340

; 3
MOV AH,3FH .
LEA DX,BUF
MOV C X , 3

INT 21H
:
MOV A H , 4 2 H
MOV A L , 0

XOR CX,CX
XOR DX,DX
INT 21H

;
MOV A H , 4 0 H
LEA DX,BUF
MOV C X , 3
INT 21H

:

MOV ,42
MOV A L , 0
XOR CX,CX
XOR DX,DX
INT 21H
:
MOV CX,LEN .
LEA DX,BUF
MOV AH,3FH
INT 21H
:
MOV AH,3EH
INT 21H
: ( )
MOV AH,3CH
LEA DX,PATH1
MOV CX,0
INT 21H
:
MOV ,4
LEA DX,BUF
MOV CX,LEN /
INT 21H
:
MOV AH,3EH
INT 21H
LEA DX,TEXT2

18.

MOV ,9
INT 21H
_END:
RETN
1 DB 80 DUP(O)
; -
1 DB ' ',13,10, '$'
2 DB ' ',13,10, '$'
;
LEN
DW ?
BUF
DB 64000 DUP(O)
CODE ENDS
END BEGIN
. 18.4. -.
; PO.ASM

.286
CODE SEGMENT
ASSUME CS:CODE
ORG
BEGIN:
;
DB 3 DUP(?)
;
PUSH AX
PUSH DX
PUSH SI
PUSH DI
/
MOV
DI,100H
MOV
SI, [DI+1]
MOV
DX,SI
;
ADD
SI,100H
MOV
AL, [SI]
MOV
[DI],AL
MOV
AL, [SI]+1
MOV
[DI]+1,AL
MOV
AL, [SI]+2
MOV
[DI]+2,AL
;
;,
/
.**********************************
,
. **********************************

341

342

ASSEMBLER.

;
ADD
DX,100H
LEA
AX,TEXT1
ADD
DX,AX
MOV
AH,9
INT
21H
MOV
AH,0
INT
16H

;
;
POP
DI
POP
SI
POP
DX
POP
AX
PUSH 100H ; 286- , MOV AX,100H/PUSH AX
RETN
TEXT1 DB " . .",13,10
DB " .",13,10,"$"
_END:
CODE ENDS
END BEGIN
. 18.5. ().
.
1. , -, ..
. JMP ADR, ADR . , .
3 . .
2. , . - .
100, , "".
3. "" , .
18.3. .. .
, ,
, :
1. , . , .
2. ,
, "" 64 .
3. , . : "" ,
.

19.
.
!
.
, ,
: , . ,
.

I.
.
-,
. , . ,
, , . (
).
, ,
.
1. ( ,
, ..). .
: ,
, .
2. .
, .
, .
: (. ), .
3. .
.
) .
)
.
) , ,
.
) , ,
.

344

ASSEMBLER.

: , .
4. , , .
, , , , .. : , , ( ).
, . .
. , , ,
, , , ,
.. , ,
. , ,
, . . . ..
,
. ,
- , . , .
, , . N .
. , - , 1-.
1=>. .
, ,
. , , . , - .

. , , .
- . ,

.
.
, (, ). : ,
.
.
( , ).

19.

345

( , )
.
: . , "".
. .
(
). . , .
. , ,
. . , , .
.
, , , ,
.
( ,
, ..).

. .
,
. .
,
.
. ,
, , ,
,
.
. . , , ,
. ,
, ,
. ,
, .. , , . .
.
, . , .
.

346

ASSEMBLER.

. . , , , .
. . :
1. ;
2. ;
3. ;
4. .
. 19.1 41 () ().
CODE SEGMENT
ASSUME CS:CODE
ORG 100H
BEGIN:
XOR CL,CL

XOR DX,DX
/ ,
MOV CH,41
; 41
MOV AL, 9
;
LEA BX,BUF
/
MOV AH,5
/
INT 13H
;
JC KON
; ,
; 1 BUFFER
XOR DX,DX
;
MOV CH,41
;
MOV CL, 1
; 1
MOV AL,1
;
MOV ,3
;
LEA BX,BUFFER
INT 13H
JC KON
LEA DX,MES
MOV AH, 9
INT 21H
/
KON:
RET
BUF
DB 41,0,1,2
DB 41,0,2,2
DB 41,0,3,2
DB 41,0,4,2
DB 41,0,5,2

19.

347

DB 41,0,6,2
DB 41,0,7,2
DB 41,0,8,2
DB 41,0,9,2
BUFFER DB 512 DUP(12)
MES DB ' !', 13,10, '$ '
CODE ENDS
END BEGIN
() . ,
.
CODE SEGMENT
ASSUME CS:CODE
ORG 10OH
BEGIN:
; , 360
;
; -,
;13
;. 14
XOR AL,AL
MOV ,1
XOR DX,DX
LEA BX,BUF
PUSH BX
INT 25H
POP AX
;
POP BX
JNC NO_KON
JMP KON
NO_KON:
CMP WORD PTR [BX]+13H,720
; 720 ?

JNZ KON
;
XOR DX,DX
;
MOV CH,41
;
MOV CL, 1
;
MOV AL,1
;
LEA BX,BUF
;
MOV ,2
/
INT
13H
JC
KON
CMP BYTE PTR [BX+1],12 / (

348

ASSEMBLER.

;
JNZ KON
" LEA DX,MES
MOV , 9
INT 21H

'

KON:

RET

MES DB ' ! ', 13,10, '$'


BUF DB 512 DUP(?)
CODE ENDS
END BEGIN
() . ,
.
. 19.1. .
(. 14) ,
. ,
, ..
, . , [10,14,17]5|.
(, ) ( ). .
. ,
, .
.
.52
. ,
. . ,
, ,
, .
. ,
.

( ). , , , , SPEEDISK. ,
51
52

. [15], 9.
.
, , , ,
.

19.

349

(READ ONLY).
, , .
, , ,
(. 19.2).
52 (. 14). , , FAT,
. NONAME.COM OFSET.
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
ORG 10OH
BEG:
/
MOV AX,3D02H
LEA DX,PATH
INT 21H
JC _END
PUSH AX

/
;
MOV SI,AX
MOV DL,ES: [SI+18H]
-
XOR DH,DH ; DX
/
MOV ,52
:
INT 21H
/
LES SI,ES:[BX+4] ; ES:SI
/
CMP DX,ES:[SI+4]
JB YES
SUB DX,ES:[SI+4]
LES SI,ES:[SI]
/
;
YES:
MOV AX,59 /
MUL DL
ADD SI,AX
MOV AX,ES:[SI+6+OBH] /
MOV CLAST,AX
/ OFSET, ,
POP
MOV AX,4200H
XOR CX,CX

350

ASSEMBLER.

MOV DX,OFSET
INT 21H
;
MOV AH,40H
MOV CX,2
LEA DX,CLAST
INT 21H
;
MOV AH,3EH
INT 21H
_END:
RET
;
PATH DB 'NONAME.COM',0
/,
OFSET DW 15
;
CLAST DW ?
CODE ENDS
END BEG
. 19.2. .
( ) - 516 (512+4). .
, (. . 19.3).
CODE SEGMENT
ASSUME CS:CODE
ORG 100H
BEGIN:
/: 2, 3,
MOV ,
MOV AL,1
MOV DH,2
MOV CL,4
MOV CH,3
MOV DL,80H
MOV BX,OFFSET BUF
INT 13H
JC ERR_D
; 516
MOV ,
MOV AL,1

19.

MOV DH,2
MOV CL,4
MOV CH,3

MOV DL,80H
MOV BX,OFFSET BUF
INT 13H

JC
ERR_D
MOV DX,OFFSET MES1
JMP SHORT WR
ERR D:

MOV DX,OFFSET MES2


WR:

MOV AH, 9
INT 21H '
RET
MES1 DB ' .', 13,10, '$ '
MES2 DB ' '
DB '.',13,10, '$'
BUF DB 512 DUP(?)
DB 4234'
CODE ENDS
END BEGIN
() .
CODE SEGMENT
ASSUME CS-.CODE
ORG 100H
BEGIN:
/: 2, 3, 4
MOV AH,OAH
MOV AL,1
MOV DL,80H
MOV DH,2
MOV CH, 3
MOV CL,4
MOV BX,OFFSET BUFFER
INT 13H
JC NO_M
; 4
CMP BYTE PTR ES: [BX]+512, '!'
JNZ NO_M
CMP BYTE PTR ES: [BX]+513, '2'
JNZ NO M

351

352

ASSEMBLER.

CMP BYTE PTR ES: [ B X ] + 5 1 4 , ' 3 '


JNZ NO_M
CMP BYTE PTR ES: [BX]+515, ' 4 '
JNZ NO_M
MOV DX,OFFSET MES2
JMP SHORT WR

NO_M:
MOV DX,OFFSET MES1

WR:
MOV AH, 9
INT 21H
RET
BUFFER
DB 512 DUP(?)
MET
DB 4 DUP(?)
MES1
DB ' .'
DB 13,10,'$'
MES2
DB ' .',13,10,'$'
CODE ENDS
END BEGIN
() .
. 19.3. () () .
, ,
- PARTITION TABLE. , . ,
.
. BAD-,
.

. :
- , ;
- ;
- ( );
- .

III. .
,
. , (
, , ..).
? : (), .

19.

353

1 3.
53
. . , (INT 1). 3
. INT 3 ( INT) . ,
. ,
1, . 3, . , "" .
XOR ,
MOV E S , A X
MOV B X , 4
MOV E S : [ B X + 2 ] , 1 2 3 4


. , . ,
- .
. , . :
MOV BX,OFFSET MET2
JMP MET1
1:
MOV BYTE

PTR C S : [ B X ] , O C 3 H

MET2:

, 2 , . .
.
, .
, 53

, , MS DOS. , Windows, .

12-4072

354

ASSEMBLER.

.
. , ,
, .
.

( , ..
).
MOV A L , 2
OUT 21H,AL

, , ,
.
. 1
8, . , .
" ".
, "" , . .
, . ,
.
. 1 3. .
) .
' , . . .
) PSP 2 , DOS
. - DOS, :
MOV A X , S S

CMP A X , E S : [ 3 0 H ] ;ES PSP


,
ES:[30H] .
) PSP 16 . COMMAND.COM PSP,
.
MOV A X , E S : [ 1 6 H ]
MOV ES,AX
CMP A X , E S : [ 1 6 H ]

19.

355

ES:[16H], . , , .
. . , , , ,
, .
: 21 1. :
1. . .
2. . ,
. , 13
2FH J3H BIOS.
21 5DH.
2FH.
MOV ,13
INT 2FH
PUSH DS
PUSH
INT 2FH
POP
POP DS

. 1
, . DS: 1 . 1 BIOS.
. -
, . - - 1 , .
(. 19.4) , 9 DOS
5DH.
CODE SEGMENT
ASSUME CS:CODE,DS:CODE
ORG 10OH
BEGIN:
MOV DX,DS
MOV _DS,DX
MOV _AX,0900H
MOV _DX,OFFSET MES
MOV DX,OFFSET _AX
MOV AX,5DOOH
12'

356

ASSEMBLER.

INT 21H
RET
1
MES
DB ' 09, 21 ,13,10, ' $ '
;
_ DW ?
_
DW
?
_
DW
?
_DX DW ?
_SI DW ?
_DI DW ?
_DS DW ?
_ES DW ?
CODE ENDS
END BEGIN

Puc. 19.4. DOS.

IV.
.
( ) ,
. MS DOS
, , .. .
, .
.
1.
, . , - .
,
. , .. ,
.
2. . ,
, , , .
, .
, .
3.
. , ,
( 1).
4.
, , -

19.

357

(, )
13, 21, 25, 26.
- ,
.
5. .
6. , .
"" , , ..
. ,
54
, , .

V. .
, . , , (
). , .
. Novel Netware . 3.12 .
, , . : , , - , ,
. , .
Novel Netware . , - .
.
1- .
1. . . , . .
.
2. . (,
), ().
3. .
( ), .
54

, , MS DOS.

35*

ASSEMBLER.

4. .
.
5. .
, . , .
6. .
- ,
. , .
2- .
.
,
. :
1. ( Supervisofa - )
2.
3.
4. ( )
5.
6. ( )
7.
8. .
,
.
.
3- .
( ).
, . , . .
4- .
.
. , MS DOS. .
. , , .
, , Novel
, .55

55

, , . - Novel Unix,
, - NT.

20. 8086, 80186,


80286, 80386, 80486, Pentium...
, ,
,
!
"
"
! 386- - .
, .
, INTEL.
(, ), .. , .
INTEL 8086 (1978).
16- , .
8088, 8086, 8- .
, . MOV MEM, . 8088 ,
. , 8088.
(
) : 8086 - ; 80286 - ; 80386 - 32- , , .

I. .
8086/8088.
-

15

SP

()

SI

DI

ASSEMBLER.

360

15
CS

DS

S3

ES

15
IP

15


FLAGS

:
0 (CF) - .
1 (1) - .
2 (PF) - .
3 (0) - .
4 (AF) - .
5 (0) - .
6 (ZF) - .
7 (SF) - .
8 (TF) - .
9 (IF) - .
10 (DF) - .
11 (OF) - .
12-15- (0).

80186/80188.
,
, , 8086/8088.

20. 8086, 80186, 80286, 80386, 80486, Pentium.,

80286.
.

15

(80286)

AL

BL

CL

DX

DL

DH

(80286)

15

SP

()

SI

DI

(80286)

15

CS

DS

S3

ES

361

ASSEMBLER.

362

(80286)

15

IP

, .
-

15

MSW

:
0 () - . 1
.
1 () - . . 80486 1.
2 () - . 1,
WAIT (7).
3 (TS) - , .
4-15 -.

23
GDTR

23
IDTR


15

LDTR

15

TR

20. 8086, 80186, 80286, 80386, 80486, Pentium...

15

363

FLAGS

( 8086) ,
.
12-13 (IOPL) - .
14 (NT) - .

80386.
32-.

31

15

= + AL

= + BL

= + CL

EDX

DX = DH + DL

31

15
SP

()

ESI

SI

EDI

DI

ESP

ASSEMBLER.

364

15

CS

DS

SS

ES

FS
OS

31

15

IP
80386 (. 5),
16 , , . ,
32- .
GDTR, LDTR, IDTR, TR , 80286.

31

15

FLAGS

20. 8086, 80186, 80286, 80386, 80486, Pentium...

365

( 80286) .
16 - - . .
17 - - .

.

31

15

CRO
16 CRO (. 80286).
:
0 - - ,
1 - - ,
2 - - ( ),
3 - TS - .
31 - PG - .
.. (31-).
CR1 - .
CR2 - .
CR3 - ( 12-31).
, CR1-CR3. CRO.

(32-).
DRO-DR3 - .
.
.
DR4-DR5 - .
DR6 - ( ).
DR7 - .
(8 ), :
- ;
- / ;
- , .

366

ASSEMBLER.

(32-).
TR6.TR7 - ( - )
- .

80486.
486- ,
386- .
-18-. .
CRO .
4 - - . .
5 - NE - . .
6 - WP - .
.
7 - AM - .
8 - N W - . (1)
- .
9 - CD - -.
CR3.
12-31- .
2 - PWT - .
3 - PSD - .
, 80486
, 387.

PENTIUM.
19-21.
21 - ID - (CPUID);
20 - VIP - ;
19 - VIF - IF .
CR4 0-6.
0 - - V86,
1 - PVI - ,
2 - TSD - RDTSC ,
3 - DE - -.
DR6 12. , Pentium -. 12: TR1-TR12.

20. 8086, 80186, 80286, 80386, 80486, Pentium...

367

II. .
8086/8088.
4 1,
.

80186/80188.
. 5.
BOUND REG,MEM - .
. MEM , +2 - . ,
5.
ENTER N,M - .
ENTER 16,3 - 16 . 3.
.
LEAVE - . ENTER.
INS - . 1NSB, INSW, INSD. .
OUTS - . OUTSB, OUTSW, OUTD. .
PUSHA, - DI, SI, BP, SP, ,
DX,CX,AX.
PUSH N,N- .
.
, IMULDX,CX,123 (BX*123->DX) (. 5).
: SHL AX,N , N> 1.

80286.
80186.

80386.
BSF REG.REG/MEM . . ,
Z.
BSR REG,REG/MEM . .
REG,REG/MEM/N CF ,
.
REG.REG/MEM/N , . CF.
BTR REG,REG/MEM/N , . CF.
BTR REG,REG/MEM/N ,
. CF.

368

ASSEMBLER.

CWDE - .
CDQ - .
SHLD REG/MEM,MEM,N (SHRD REG/MEM,MEM,N) (, ).
, . .
SETCC - .
1 . .
80286:
-, 32- . ,
ADDEAX.234567H.
-, D. , CMPSD -
, IRETD - 32- ,
MOVSD - ..

80486.
: BSWAP, XADD, CMPXCHG.
BSWAP 32- .
XADD MEM,REG - , .
CMPXCHG MEM,AK,REG (AK - ) - , - -.
- .

PENTIUM.
:
CMPXCHG8B, CPUID, RDTSC, RDMSR, WRMSR, RDTSC CR4.
.
CMPXCHG8B REG/MEM,REG - .
CPUID - .
RDMSR REG/MEM - (TR1-TR12).
WRMSR REG/MEM - (TR I-TR12).
RDTSC - .

III. .
8086/8088.
.

80186/80188.
.

20. 8086, 80186, 80286, 80386, 80486, Pentium...

369

80286.
.
ARPL - .
LGDT - GDT . ..
GDT, ( 386-
). . LGDT MEM.
SGDT - GDT . .
SGDTMEM.
LLDT - - LDT.
,
GDT. . LLDT REG/MEM.
SLDT - LDT -. ,
LLDT. SLDT REG/MEM.
LAR - , . LAR REG,REG/MEM
LSL - LAR,
.
LSLREG,REG/MEM.
LMSW - .
. , LMSW .
SMSW - , .
LTR - . . LTR REG/MEM.
STR - . STR REG,MEM.
CLTS - .
LIDT - . LIDT MEM.
SIDT - . SIDT MEM.
VERR - . VERR REG/MEM.
VERW - . VERW REG/MEM.

80386.
(CR,TR,DR). , MOV CRO.EiAX.

80486.

. , .
INVD - - , -. - .
INVLPG - TLB.
WBINVD - - , -

370

ASSEMBLER.

.
, -.

PENTIUM.
-, .

IV. 32- .
80386 32 . DS:[BX] DS:[EBX]. 64 . , 32- .
.386
DATA
TST
DATA
STAC

SEGMENT
DB ?
ENDS
SEGMENT STACK
DW 50 DUP(?)
STAC ENDS
CODE SEGMENT USE16
ASSUME CS:CODE, DSrDATA, SS:STAC
BEGIN:
; 32-
MOV EAX, 0
MOV EBX, 0
; DS DATA
MOV AX,DATA
MOV DS,AX
; TST - ''
MOV DS:TST,'A'
PUSH DS
LEA BX,TST
/ DATA
SHL EAX, 4
; TST EBX
ADD EBX,EAX
XOR AX,AX
; DS
MOV DS, AX
; TST DL
MOV DL, [EBX]
MOV AH,2
INT 21H
POP DS

20. 8086, 80186, 80286, 80386, 80486, Pentium...

371

; , ()
;
LEA

BX,TST

MOV
DL, [BX]
INT
21H
MOV A H , 4 C H
INT 21H
CODE ENDS
. END BEGIN

Puc. 20.1. 32- .


32- 25.

V. .
, INTEL, :
1. : ().
2. ( ),
( ), .
3. ,
. . .
80386 . .
(. ), ,
, .
.
4 .
386- 4 , , , .
1 .
. , ,
.
, . , ,
. . 4 (. 5) - , 1,2, 3.
: 3, - 0,1,2 .
20 32-
- . 12
. :

572

ASSEMBLER.

1. 10 ( 2 )
() , . . 20- CR3 ( 12-31, ). 32- . 1024 .
2. 12-21 , ,
, , . 32-
(1024 ).
3. "" , 12- () .
.
31
12

9-11

7-8

6 5 4 3. 2 1 0

:
0 - 1 - , 0 - , , .
1 -1 - -, 0 - .
2 - 0 - , 1 - .
3-4 - .
5 -"1 - .
6 -1 - .
7-8- 0.
9-12 - .
, ,
,
, .
, .
, :
PUSHFD
CLI

MOV
MOV
MOV

MOV
JMP

EAX,KAT_ADR ;
CR3,EAX
EAX,CRO
/
,31
CRO,EAX
NEXT

NEXT:
POPFD

20. 8086, 80186, 80286, 80386, 80486, Pentium...

373

, Pentium 4 .
INTEL.
.

VI. .
, - .
.
. ,
: [2,17,32]. , ,
80486, .
. .
,
.

, .
.
. ,
, . , , .
, ,
, . .
, , .. ,
.
. :
) -
, , .. ;
) - , , . TEST. . WAIT (. 4).
. , , FLDZ (. ), : WAIT/FLDZ. ESC. , FIDIV [SI] - , (. )
[SI].

374

ASSEMBLER.

, :
WA1T/FIDIV [SI]. ESC 16H,[SI],
FIDIV.
- 80- , .
ST ( ST(0)) , .
, .
, . . 000 , 111.
.
() ( , ..) , . .
( ) ,
. :
FADD ST,ST(2) - ,
2 (, R3 R5), .56
, .
- 00, - 01, - 10, -11.
, , ( , ..).

. SUM. , . .. 65,
. , WAIT. , , - . , . , . .
CODE

SEGMENT
ASSUME CS:CODE,DS:CODE
ORG 10OH
BEGIN:

JMP SHORT BEG


;
ARRAY DW 25,1,1,1,1,1,5,5,5,3,5,7,5
56

20. 8086, 80186, 80286, 80386, 80486, Pentium...

375

;
SUM

DW ?

BEG:

MOV ,13

/
/, , (=11)
FINIT
;
;
FLDZ
; SI
XOR SI,SI
MORE :
/ ,
FIADD DWORD PTR ARRAY[SI]
ADD SI,2
LOOP MORE
/ SUM
FIST DWORD PTR SUM
/
WAIT
/ ,
MOV , 2
MOV DL,BYTE PTR SUM
INT 21H
RET
CODE ENDS
END BEGIN
Puc. 20.2. .
++. , .
ASCII-, . , , . ,
PRINTF,
57.
57

. , 8088/8086, , .
.

376

ASSEMBLER.

#include <stdio.h>
void main(void)
int num=200;
double sq;
/* */
asm {
/* */
/*, ,
(=11)*/
FINIT
/* */
/* , */
FLDZ
/* */
FILD num
/* */
FSQRT
/* */
FST sq
/* */
WAIT
/* */
printf("%f",sq);
. 20.3. .
200.
, PRINTF. , TINY.
. FILD NUM - NUM
. 1, . FST SQ -
SQ. . FSQRT
- .
. WAIT PRINTF , , SQ .
,
, .
, ,
. -

20. 8086, 80186, 80286, 80386, 80486, Pentium...

377

. , ,
.
. . - ,
2 - 1.
(), 2 , X, 2 . (. ).
,
#include <stdio.h>
tinclude <math.h>
double fun (double i)
/* ,
0<=I<=0.5*/
{
double ex;
asm {
FINIT
/^*/
FLD i
/* */
FLDL2E
/* */
FMUL ST,ST(1)
/* */
F2XM1
/* ()-1*/
*
FST
/* */
'
WAIT
+=1;
return (ex) ;

/* */

void main (void)


{
/* */
printf ( " % f \ n " , f u n ( 0 . 3 5 ) ) ;
printf ( " % f \ n " , f u n ( 0 . 4 ) ) ;
printf ( " % f \ n " , e x p ( 0 . 3 5 ) ) ;
printf ( " % f \ n " , e x p ( 0 . 4) ) ;
. 20.4. .
8087.

ASSEMBLER.

378

FADDdst,src

dst<-dst)+(src)

FADDPdst,src

dst<-dst)+(src) ST <- (ST)+1

FIADDsrc

FSUBdst,src

ST(0)<-ST(0)+(src)
dst<-(dst)-(src)

FSUBPdst,src

dst<-(dst)-(src)ST<-(ST)+l

FSUBRdst,src

dst<-(src)-(dst)

FSUBRPdst,src

FISUBsrc

FISUBRsrc

dst<-(src)-(dst)ST<-(ST)+l
ST(0)<-ST(0)-(src)
ST(0)<-(src)-ST(0)

FMULdst,src

dst<-(dst)*(src)

FMULPdst,src

dst<-(dst)*(src)ST<-(ST)+l

FTMULsrc

ST(0)<-ST(0)*(src)

FDIVdst,src

dst<-(dst)/(src)

FDIVPdst,src

dst<-(dst)/(src) ST <- (ST)+1

FDIVRdst,src

dst<-(src)/(dst)

FDIVRPdst,src

dst<-(src)/(dst) ST <- (ST)+1

FIDIVsrc

ST(0)<-ST(0)/src

FIDIVRsrc

ST(0)<-src/ST(0)

FABS

ST(0)<-|ST(0)|

FCHS

ST(0)<--ST(0)

FPREM

ST(0)<-ST(0)MODST(1)

FRND1NT

.8(0)

FSCALE

ST(0)<-ST(0)AST(1)

FSQRT

ST(0)<-sqrt(ST(0))

FXTPACT

8(0)<-.8(0)
8(1)<-.8(0)

20. 8086, 80186, 80286, 80386, 80486, Pentium...

379

FLDsrc

ST <- (ST)-1 ST(0) <- (src)

FILDsrc

ST<-(ST)-lST(0)<-(src)

FBLDsrc
FSTdst

ST<-(ST)-lST(0)<-(src)
dst <- ST(0)

FISTdst

dst<-ST(0)

FBSTPdst

dst<-ST(0)ST<-(ST)+l

FSTPdst

FISTPdst
FXCHdst

dst<-ST(0)ST<-(ST)+l
dst<-ST(0)ST<-(ST)+l
ST(0)<->(dst)

FCOMsrc

ST(0) - src ,

FCOMP src
FCOMPP

ST(0) - ST(1) ST <- ST+1 ,

FICOM src

ST(0) - src ,

ST(0) - src ST<-ST+1 ,

FICOMP src

ST(0) - src ST <- ST+1 ,

FTST

ST(0) - 0.0 ,

FXAM

, 2, 1,

F2XM1

2 -1

FPATAN

Z<-arctg(ST(0)/ST(l))
ST<-ST+1ST(0)<-Z

FPTAN

FYL2X

Y*lg

tgST(0)=Y/X ST(0)<-Y ST<-ST-1


ST(0)<-XST<-ST+1 ST(0)<-Z

FYL2XP1

Y*ln

ST<-ST+1 ST(0)<-Z

ST(0)<-2AST(0)-1

ASSEMBLER,

380

FLDZ

SK-ST-1 ST(0)<-0.0

FLD1

ST<-ST-1ST(0)<-1.0

FLDPI

ST<-ST-1ST(0)<-3.14..

FLDL2E

log

ST(0)<-log

FLDL2T

log

ST(0)<-log

FLDLG2

log

ST(0)<-log

FLDLN2

log

ST(0)<-log

FIN1T/FNIN1T

coc.<-03FF
T3roB<-NULL
<-08<-0

FDISI/FNDISI

<-1

FENI/FNENI

<-0

FCLEX/FNCLEX

<-0

FINCSTP

ST<-(ST)+1

FDECSTP

ST<-(ST)-1

FSTSW/FNSTSW dst

dst<-oioBO .

FSTCW/FNSTCW dst

dst<-cnoBO .

FLDCWsrc

ynp.<-src

FSTEN/FNSTEN dst

dst<-oioBo .
dst+2<-cnoBococ.
dst+4<-cnoBO
dst+6<-yK33.KOMaHfl
dst+ 10<-..

FLDENVsrc

ynp.<-src
.<-8+2
<-8+4

FFREEdst

FNOP

.<-+6
..<-5+10
ST(i) -

20. 8086, 80186, 80286, 80386, 80486, Pentium...

FSAVE/FNSAVE dst

FRSTOREsrc

dst<-oiOBo .
dst+2<-cnoBOCoc.
dst+4<-cnoBO
dst+6<- .
dst+ 10<-..
dst+14..dst+84<-ST(0),
ST(1),ST(2)...

ynp.<-src
coc.<-src+2
<-5+4

.<-8+6
.. <-src+ 1 0
- <-src+14..src+84

RO


64

78 '

R1
R2
R3
R4
R5
R6
R7
15


. 20.5. .

381

382

ASSEMBLER.

. 80- ,
. ST , . .
. .
. :
00 - ,
01 - ,
10 - ,
11 - .
.
.
6 . 1,
,
0 - ,
1 - ,
2 - ,
3 - ,
4 - ,
5 - .
:
6 - ,
7 -1 - ,
8-9:
00 - 24 ,
10-53 ,
11 - 64 ,
10-11:
00 - ,
01 - ,
10 - ,
11 - .
12 - :
0 - ,
1 - .
. .
, : - 8- , 1 - 9- , 2 - 10- , - 14- .
. ,
.
.
.
, 287- Pentium.

20. 8086, 80186, 80286, 80386, 80486, Pentium...

383

80287.
:
1. .
2. WAIT, ,
.
3. . 6
. 7
.
4. ,
7.
5. 287 .
.
, , , (387-, 487- ...).
1. : FUCOMP st(i) - st(0) st(0)
; FUCOMPP st(i) - st(0) st(0)
; FPREM1 - IEEE; FCOS - st(0); FSIN - st(0); FSINCOS - (st(l )<sin(st(0), st(0)<-cos(st(0)).

21.
.
, , ...
..

IPX SPX, .
,
. ,
, .
Microsoft Windows API ,
(. 24,25).
, Novel
MS DOS.

I. .

NOVEL NETWARE. , IPX SPX, . ,
, NWLite Personal Netware.
, , ,
. , 44 DOS. 9 ,
. (. 21.1) , . )'
.
CODE SEGMENT
ASSUME CS:CODE, DS:CODE, SS:CODE
ORG 100H
BEGIN:
MOV BL,1
MOV CX,33
LOO:
MOV AX,4409H
INT 21H
AND DX,1000H
JNZ YES
INC BL
LOOP LOO

21.

385

;
LEA DX,TEXT1
MOV ,9
INT 21H
RET
YES:
LEA DX,TEXT2
MOV AH, 9
INT 21H
RET
;
TEXT1 DB ' .', 13,10, '$'
2 DB ' .', 13,10,'$'
CODE ENDS
END BEGIN
. 21.1. ,
.
, , , CD-ROM ,
. 15
( 2FH, 0). CD-ROM. 0, .
, CDROM. , , , , , , , , , , .
, . , IPX (.
).

NOVEL.
(),
NOVEL NETWARE. - ,
, .. . , ,
. , :
1. . ,
. . ,
, , .
. (Personal
Netware, Lantastic, Windows .)
13-4072

386

ASSEMBLER.

. , , .
2. . MS DOS - . ,
, , . ,
,
.
3. . ,
, - . - .. ,
(. ).
:
1. , . , ,
.
2. , . ,
, .
3. , , . , . : , . .
4. , , , , .
5. : ,
, .

.

: IPX, SPX.58 ,
. . , IPX SPX. - POINT.
IPX SPX. 2FH 58

NetBios .

21,

387

. : ? : , .
CODE SEGMENT
ASSUME CS:CODE,DS:CODE

ORG 10OH
BEGIN:
;
MOV AX,7AOOH
INT 2FH

CMP AL,OFFH
JZ

OKI

LEA DX,TEXT2
JMP SHORT _END
OKI:

LEA DX,TEXT1
CALL WRITE
;
MOV POINT,DI
MOV
POINT+2,ES
MOV AX,0
MOV BX,10H
; SPX
/ SPX
CALL DWORD PTR POINT
CMP AL,OFFH
JZ
OK2
LEA
DX,TEXT4
JMP SHORT _END
OK2:
LEA DX,TEXTS
_END:
CALL WRITE
RET
/
WRITE PROC
MOV AH, 9
INT 21H
RET
WRITE ENDP
;
TEXT1 DB ' IPX .', 13,10,'$'
TEXT2 DB ' IPX .', 13,10,'$'
13'

388

ASSEMBLER.

DB ' SPX .', 13,10, ' $ '


4 DB ' SPX .',13,10, '$'
;
POINT DW ?
DW ?
CODE ENDS
END BEGIN

. 21.2. ,
IPX SPX.

. IPX. IPX.
IPX (, , )
. .
-
-
-
-
-
-
-
-
-
-
- (0-546 )

- 2 : , .
- 2 , .
30 . .
-1 , , ,
1.
-1 , IPX 4.
- 4 , .
- 6 , .

21.

389

- 2 , ,
. .
- 4 , .
- 6 . - 2 . -
546 .
: ( ), ( ), , 59
(SOCKET) . . , 0 FFFFH. 0-
XEROX, IPX. , NOVEL
,
4000 8000.
, (), ,
(), . , .
EVENT
CONTROL BLOCK (ECB) - . , . .


LINK -
ESRADDRESS - ESR
INUSE .
CCODE -
SOCKET -
IPXWORKSPACE . IPX
DRIVERWORKSPACE -
12
IMMADDRESS -
FRAGNENTCNT -
ADDRESS -
SIZE -
ADDRESS -
SIZE -

..

59

"" . - "", "".

390

ASSEMBLER.

.
LINK - . .
ESRADDRES - , .
ESR - EVENT SERVICE ROUTINE.
INUSE - . ,
, .
:
FF - ,
FE - ,
FD - ,
FB - , IPX.
CCODE - ,
:
00 - ,
FF - ,
FD - ,
FC - ;
:
00 - ,
FF - ,
FE - ,
FD - ,
FC - .
SOCKET - ,
IPXWORKSPACE - ,
DRIVER WORKSPACE - ,
IMMADDRES - , ( ).
FRAGMENTCNT - ,
, 2 (. ).
, ,
(. ).

III. IPX.
,
IPX.
.
:
=0 AL=0 - ( ),
OFFH - .
:
AL=0 - ,

21.

391

FFH - ,
FEH - .
DX - .
.
:
=1,
DX - .
, .
.
.
=2
ES:SI - 12 ,
, .
ES:DI - 6 , ( , ).
:
- ,
AL - 0 - ,
FEH - .
.
=9
ES:DI - 10 , ,
( ).
:
DEST_NUMBER DB 4 DUP(?)
DEST_NODE DB 6 DUP(?)
.
BX=4
ES:DI - . :
ESRADDRES;
SOCKET;
FRAGMENTCNT;
,
.
:
AL - 0 - ,
FFH - .
.

ES:DI - . :
ESRADDRES;
SOCKET;
IMMADDRES;

392

ASSEMBLER.

FRAGMENTCNT;
ADDRES;
.
:
PAKETTYPE;
DESTNETWORK;
DESTNODE;
DESTSOCKET.
.

ES:SI - , .
,
. ESR.
INUSE.
=5,
- ,
ES:SI - .
, INUSE, ESR ( ).
.
:
=8
:
- .
.
, ( 1 . . 18.2 ).
. , . , ,
.
.
:
=6,
ES:SI - .
:
AL=00 - ,
F9H - ,
FFH - .
. ESR . CCODE FCH.
.
=
(. ).

21.

393

. 1 - 2. , 2 1. , , 1. , . FR AGNENTCNT=2.
, , 30 . . 32 (SIZ=32). - 540 .
INUSE - , .
,
INUSE. 0.
. , - IPX . , , ,
, . .
.
; 1
; - ()
; - 4001, 1004
DATA SEGMENT
TEXT DB ' .', 13,10,'$'
1 DB ' ', 13,10,'$'
/ (30 )
CHECKSUM
DB 2 DUP(?)
LEN
DB 2 DUP(?)
TRANSPORTCONTROL DB ?
PACKETTYPE
DB ?
DESTNETWORK
DB 4 DUP(?)
DESTNODE
DB 6 DUP(?)
DESTSOCKET
DB 2 DUP(?)
SOURCENETWORK
DB 4 DUP(?)
SOURCENODE
DB 6 DUP(?)
SOURCESOCKET
DB 2 DUP(?)
;
STROKA DB 32 DUP(?)
;
LINK
DB 4 DUP(?)
ESRADDRES
DB 4 DUP(O)
INUSE
DB ?
CCODE
DB ?
SOCKET
DW 1004H
IPXWORKSPACE
DB 4 DUP(?)
DRIVERWORKSPACE
DB 12 DUP(?)

394

IMMADDRESS
FRAGNENTCNT
ADDRESS1

ADDRESS 2

ASSEMBLER.

DB
DW
DW
DW
DW
DW
DW
DW

6 DUP(?)
2
OFFSET CHECKSUM
SEG CHECKSUM
30
OFFSET STROKA
SEG STROKA
32

SIZ
DATA ENDS
ST1 SEGMENT STACK 'STACK1
DW 100 DUP(?)
ST1 ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:ST1
BEGIN:
MOV AX,DATA
MOV DS,AX
CALL WHAT_POINT
CMP AL,OFFH
JZ
OKI
JMP _END
OKI:
;
MOV ,
MOV AL,OFFH
MOV DX,1004H
CALL DWORD PTR CS:NET_POINT
CMP AL,0
JZ OKJDPEN
;
MOV ,9
LEA DX,TEXT
INT 21H
JMP SHORT _END
OKJDPEN:
;
PUSH DS
POP ES
LEA SI,LINK
MOV BX,04H
;
CALL DWORD PTR CS:NET_POINT
CMP AL,OFFH
JNZ WAI
MOV AH, 9

21.

LEA

DX,TEXT1

INT

21H

JMP SHORT _CLOSE


;
WAI:
MOV AH, 1
INT
16H .

JNZ _CLOSE
CALL FOR_WAIT
CMP DS:INUSE,0
JNZ WAI
; ,
MOV , 9
LEA DX,STROKA
INT 21H
,-
_CLOSE:
MOV BX,1
MOV DX,1004H
CALL DWORD PTR CS:NET_POINT
;
_END:
MOV AH,4CH
INT 21H
;
;
WHAT_POINT PROC
MOV AX,7
INT 2FH
CMP AL,OFFH
JNZ NO_IPX
MOV CS:NET_POINT,DI
MOV CS:NET_POINT+2,ES
NO_IPX:
RET
WHAT_POINT ENDP
/,
FOR_WAIT PROC
PUSH BX
MOV BX,OAH
CALL DWORD PTR CS:NET_POINT
POP BX
RET
FOR WAIT ENDP

395

396

ASSEMBLER.

;
NET_POINT DW ?
DW ?
CODE ENDS
END BEGIN
; 2
/ - ()
; - 4002, 2004
DATA SEGMENT
TEXT DB ' .',13,10, '$'
1 DB ' .',13,10,'$'
;
CHECKSUM
DB 2 DUP(?)
LEN
DB 2 DUP(?)
TRANSPORTCONTROL DB ?
PACKETTYPE
DB 4
; 00001958H
DESTNETWORK
DB 0
DB 0
DB 19H
DB 58H
; 6235427,
; 1
DESTNODE
DB
DB OCHH
DB 6CH
DB 23H
DB 54H
DB 27H
; 4001H - 1
DESTSOCKET
DW 1004H
SOURCENETWORK
DB 4 DUP(?)
SOURCENODE
DB 6 DUP(?)
SOURCESOCKET
DB 2 DUP(?)
/ - 32
STROKA
DB ' ',13,10,'$'
;
LINK
DB 4 DUP(?)
ESRADDRES
DB 4 DUP(O)
INUSE
DB 1
CCODE
DB ?
SOCKET
DW 2004H
IPXWORKSPACE
DB 4 DUP(?)

21.

DRIVERWORKSPACE
DB 12 D U P ( ? )
IMMADDRESS
DB
DB OCOH
DB 6CH
DB 23H
DB 54H
DB 27H
FRAGNENTCNT
DW
ADORESSI
DW
OFFSET CHECKSUM
DW SEG CHECKSUM
DW 30
ADDRESS2
DW OFFSET STROKA
DW SEG STROKA
SIZ
DW 32
DATA ENDS
ST1 SEGMENT STACK 'STACK1
DW 100 DUP(?)
ST1 ENDS
CODE SEGMENT
ASSUME CS:CODE, DSrDATA, SS:ST1
BEGIN:
MOV AX,DATA
MOV DS,AX
CALL WHAT_POINT
CMP AL,OFFH
JZ
OKI

JMP

_END

OKI:
;

MOV ,0
MOV AL,OFFH
MOV DX,2004H
CALL DWORD PTR CS:NET_POINT
CMP AL,0
JZ OK_OPEN
;
MOV ,9
LEA DX,TEXT
INT 21H
JMP SHORT _END
OKJDPEN:
;
MOV ,3
PUSH DS

397

398

ASSEMBLER.

POP ES
LEA SI,DS:LINK
;
CALL DWORD PTR CS:NET_POINT
;
WAI:
MOV AH, 1
INT 16H
JNZ _CLOSE
CALL FOR_WAIT
CMP DS:INUSE,0
JNZ WAI
/
MOV AH,9
LEA DX,TEXT1
INT 21H
;
_CLOSE:
MOV BX,1
MOV DX,2004H
CALL DWORD PTR CS:NET_POINT
/
_END:
MOV AH,4CH
INT 21H
/
/
WHATJPOINT PROC
MOV AX,7AOOH
INT 2FH
CMP AL,OFFH
JNZ NO_IPX
MOV CS:NET_POINT,DI
MOV CS:NET_POINT+2,ES
NO_IPX:
RET
WHAT_POINT ENDP
/,
FOR_WAIT PROC
PUSH BX
MOV BX,OAH
CALL DWORD PTR CS:NET_POINT
POP BX
RET
FOR WAIT ENDP

21.

399

;
NET_POINT DW ?
DW ?

CODE ENDS
END BEGIN
. 21.3. ,
IPX.
IPX. NETS NETW. NET W , - FFFFFFFFFFFFH. , . NETS . ESR
, . , NETS
NETW. NETS
. NETS . , NETW
. ,
NETW . ,
: , .. NETS ,
NETW . , , ,
.
, NETW - PROCJNT. .
/ NETS
; NETW
;
; - 4001, 1004
DATA

SEGMENT

TEXT DB ' . ' , 13,10,'$'


1 DB ' 1 ,13,10,'$'
2 DB ' .',13,10,'$'
;
STROK DB ', ',13,10,'$'
;
CHECKSUM
DB 2 DUP(?)
LEN
DB 2 D U P ( ? )
TRANSPORTCONTROL DB ?
PACKETTYPE
DB 4
DESTNETWORK
DB 0
DB 0

400

ASSEMBLER.

DB 19H
DB 58H
DESTNODE
DB 6 DUP(?)
DESTSOCKET
DW 2004H
SOURCENETWORK
DB 4 DUP(?)
SOURCENODE
DB 6 DUP(?)
DW 1004H
SOURCESOCKET
;
STROKA DB 32 DUP(?)
;
LINK
DB 4 DUP(?)
DB 4 DUP(O)
ESRADDRES
INUSE
DB ?
CCODE
DB 9
SOCKET
DW 1004H
IPXWORKSPACE
DB 4 DUP(?)
DRIVERWORKSPACE
DB 12 DUP(?)
IMMADDRESS
DB 6 DUP(?)
FRAGNENTCNT
DW 2
ADORESSI
DW OFFSET
DW SEG CHECKSUM
DW 30
ADDRESS2
DW OFFSET STROKA
DW SEG STROKA
SIZ
DW 32
DATA ENDS
ST1 SEGMENT STACK 'STACK1
DW 100 DUP(?)
ST1 ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:ST1
BEGIN:
MOV AX,DATA
MOV DS,AX
CALL WHAT_POINT
CMP AL,OFFH
JZ
OKI
JMP _END

OKI:
;
MOV ,
MOV AL,OFFH
MOV DX,1004H
CALL DWORD PTR CS:NET "POINT

21.

CMP AL,
JZ OK_OPEN
;
MOV ,9
LEA DX,TEXT
INT 21H
JMP _END
OK_OPEN:
;
PUSH DS
POP ES
LEA SI,LINK
MOV BX,04H
;
CALL DWORD PTR CS:NET_POINT
CMP AL,OFFH
JNZ WAI
MOV AH, 9
LEA DX,TEXT1
INT 21H
JMP
SHORT _CLOSE
;
WAI:
MOV AH, I
INT 16H
JNZ _CLOSE
CALL FOR_WAIT
CMP DS:INUSE,0
JNZ WAI
/ ,
MOV ,9
LEA DX,STROKA
INT 21H
;
LEA DI,DESTNODE
LEA SI,IMMADDRESS
MOV CX,
LOOQ:
LODSB
STOSB
LOOP LOOQ
MOV DESTSOCKET,2004H
MOV SOCKET,1004H
MOV SOURCESOCKET,1004H

401

402

ASSEMBLER.

/ ,
LEA
LEA

SI,STROK
DI,STROKA

KLL:
LODSB
CMP AL, '$'
JZ
PAU
STOSB
JMP SHORT KLL
; , NETW
PAU:
CALL PAUSE
;
MOV ,3
PUSH DS
POP ES
LEA
SI,DS:LINK
;
CALL DWORD PTR CS:NET_POINT
;
WAI1:
MOV AH,1
INT 16H
JNZ _CLOSE
CALL FOR_WAIT
CMP DS:INUSE,0
JNZ WAI1
;
MOV AH,9
LEA DX,TEXT2
INT 21H
;
_CLOSE:
MOV BX,1
MOV DX,1004H
CALL DWORD PTR CS:NET_POINT
;
_END:
MOV ,4
INT 21H
;
/
WHAT_POINT PROC
MOV AX,7
INT 2FH

21.

CMP
JNZ
MOV
MOV
NO_IPX:

403

AL,OFFH
NO_IPX
CS:NET_POINT,DI
CS:NET_POINT+2,ES

RET

WHAT_POINT ENDP
/,
FOR_WAIT PROC
PUSH BX
MOV BX,OAH
CALL DWORD PTR CS:NET_POINT
POP BX
RET
FOR_WAIT ENDP
PAUSE PROC
PUSH CX
MOV CX,20
DAL:
PUSH CX
MOV CX,OFFFFH
PA:
LOOP PA
POP CX
LOOP DAL
POP CX
RET
PAUSE ENDP
;
NET_POINT DW ?
DW ?
CODE ENDS
END BEGIN
/ NETW,
/ ,
/ NETS
/
/ - 4002, 2004
DATA SEGMENT
TEXT DB ' . ', 13,10, '$'
1 DB ' .', 13,10,'$'
2 DB ' ', 13,10,'$'
/
CHECKSUM
DB 2 DUP(?)
LEN
DB 2 DUP(?)

ASSEMBLER.

404

TRANS PORTCONTROL DB
PACKETTYPE
DB
DB
DESTNETWORK
DB 19H
DB 0
DB 0
/
DESTNODE
DB
DB O'FFH
DB OFFH
DB OFFH
DB OFFH
DB OFFH
DESTSOCKET
DW
SOURCENETWORK
DB
SOURCENODE
DB
SOURCESOCKET
DW
/
STROKA
DB
/
LINK
DB
ESRADDRES
DB
INUSE
DB
CCODE
DB
SOCKET
DW
IPXWORKSPACE
DB
DB
DRIVERWORKSPACE
IMMADDRESS
DB
DB OFFH
DB OFFH
DB OFFH
DB OFFH
DB OFFH
FRAGNENTCNT
DW
ADDRESS1
DW
DW SEG CHECKSUM
DW 30
ADDRESS2
DW
DW SEG STROKA
SIZ
DW
DATA ENDS
ST1 SEGMENT STACK 'STACK
DW 100 DUP(?)
ST1 ENDS

p
4
58H

OFFH

1004H
4 DUP(?)
6 DUP(?)
2004H
' ',13,10,'$'
4 DUP(?)
4 DUP(O)
1
7
2004
4 DUP(?)
12 DUP(?)
OFFH

OFFSET CHECKSUM

OFFSET STROKA
32

21.

CODE SEGMENT
ASSUME C S r C O D E , DS:DATA,
BEGIN:
MOV AX,DATA
MOV DS,AX
CALL WHAT_POINT
CMP A L , O F F H
JZ
OKI
JMP _END
OKI:

SS:ST1

;
;
MOV ,0
MOV A L , O F F H
MOV D X , 2 0 0 4 H
CALL DWORD PTR CS:NET_POINT
CMP A L , 0

JZ OKJDPEN
;
MOV , 9
LEA DX,TEXT
INT 21H
JMP SHORT _END
OK_OPEN:
,-
;
MOV ,3
PUSH DS
POP ES
LEA SI,DS:LINK
;
CALL DWORD PTR CS:NET_POINT
;
WAI:
MOV AH, 1
INT 16H JNZ _CLOSE
CALL FOR_WAIT
CMP DS:INUSE,0
JNZ WAI
;
MOV AH,9
LEA DX,TEXT1
INT 21H

405

406

ASSEMBLER.

/ ,
;.. ,
;
PUSH CS
POP
MOV WORD PTR ESRADDRES+2,BX
LEA BX,PROC_INT
MOV WORD PTR ESRADDRES,BX
;
PUSH DS
POP ES
LEA SI,LINK
MOV BX,04H
;
CALL DWORD PTR CS:NET_POINT
CMP AL,OFFH
JNZ WAI1
MOV AH, 9
LEA DX,TEX.T1
INT 21H
JMP SHORT _CLOSE
;
WAI1:
;
MOV ,
INT 16H
;
_CLOSE:
MOV ,1
MOV DX,2004H
CALL DWORD PTR CS:NET_POINT
;
_END:
MOV AH,4CH
INT 21H
;
/
WHAT_POINT PROC
MOV AX,7AOOH
INT 2FH
CMP AL,OFFH
JNZ NO_IPX
MOV CS:NET_POINT,DI
MOV CS:NET POINT+2,ES

21.

NO_IPX:
RET
WHAT_POINT ENDP
;,
FOR_WAIT PROC
PUSH
MOV BX,OAH
CALL DWORD PTR CS:NET_POINT
POP BX
RET
FOR_WAIT ENDP
;
PROC_INT PROC
; ,
MOV ,9
LEA DX,STROKA
INT 21H
;
MOV ,5
MOV CL,32
INT 16H
RETF
PROC_INT ENDP
;
NET_POINT DW ?
CODE

407

'

,,

DW ?
ENDS
END BEGIN

. 21.4. , .

.
. , . - 456. : (FFFFFFFFFFFFH),
. , .
, . , .
30 .
:

408

ASSEMBLER.

Exclusions db ?
listl
db 6 d u p ( ? )
listSO

db 6 d u p ( ? )

.
. , , .
ImmAddres ,
. 456 . . .
. .
:
DB
DB
DW
DB

?
?
?
?

;
;
;
;



SPX-

; ,
;

.
. -. , :
. .
:
- IPX/SPX,
1 - ,
2 - ,
3 - ,
4 - VAP-.
: .
:
DB ? ;
DB ? ; , (.=5)
: 5 - , 6 - - , 7 - -
, (.=5). ,
:

DB ? ;
DB 4 DUP(?) ;
DB 6 DUP(?) /

21.

409

:
0 - ,
1 - ( -)
2 - ( ).
, ,
[31].
, IPX
, .
, ,
. , . ,
, .. , .. .

IV. SPX.
SPX (Sequenced Packet Exchange) , IPX. IPX. SPX
, , . , SPX ( IPX).
SPX IPX,
12 , 42 . 12 .

CONNCDNTROL

01-08 -
20 SPX 40H - SPX
80 - SPX

DATASTREAMTYPE

OOH-FDH - IPX,
FEH -
, FFH -
,

SOURCECONNID

DESTCONNID

SEQNUMBER

ACKNUMBER

,
SPX

ALUXMJMBER

, .

, SPX , IPX.

410

ASSEMBLER.

SPX.
.
:
=14
DX - .
SPX.
:
=10
AL=0
:
AL=0 SPX
=FFH SPX
- SPX
BL- SPX
-
DX- .
.
:
=11
AL-
-
ES:SI -
:
AL -
- (SPX )
EFH -
FDH-
FFH -
:
00 -
EDH-
EFH-
FCH-
FDH-
FFH- .
.
:
=15
DX-
ES:SI -
:
AL-00

21.

.
:
=12
AL-
- .
ES:SI -
:

00 -
EFH -
FCH -
FFH -
.
:
=17
ES:SI - .
:

00 -
EDH -
FCH -
FDH -
FFH -
.
:
=16
DX-
ES:SI -
:

00 -
-
EDH -
-
FCH -
FDH -
.
:
=13
DX -
ES:SI -
:

00 -

411

412

ASSEMBLER.

ECH -
EDH -
-
FCH -
FDH -
, SPX . - , .
( 17) .
.
SPX, [30,31] [30]:
" 5 17, SPX
. SPX
."
/, SPX (1)
/ 7001 (1007)
;
DATA SEGMENT

;
;
.******************************************
; 1
CHECKSUM
DB 2 DUP(?)
LEN
DB 2 DUP(?)
TRANSPORTCONTROL DB 0
PACKETTYPE
DB 5
DESTNETWORK
DB 4 DUP(?)
DESTNODE
DB 6 DUP(?)
DESTSOCKET
DB 2 DUP(?)
SOURCENETWORK
DB 4 DUP(?)
SOURCENODE
DB 6 DUP(?)
SOURCESOCKET
DW 1007H
;SPX
CONNCONTROL
DB ?
DATASTREAMTYPE
DB ?
SOURCECONNID
DW ?
DESTCONNID
DW ?
SEQNUMBER
DW ?
ACKNUMBER
DW ?
ALLOCNUMBER
DW ?

21.

;
STROKA DB 534 DUP(?)
/ 1
LINK1
DB 4 DUP(?)
DB 4 DUP(O)
ESRADDRES1
INUSE1
DB p
CCODE1
DB 7
SOCKET1
DW 1007H
IPXWORKSPACE1
DB 4 DUP(?)
DRIVERWORKSPACE1 DB 12 DUP(?)
IMMADDRESS1
DB 6 DUP(?)
FRAGNENTCNT1
DW 2
ADDRESS11
DW OFFSET CHECKSUM
DW SEG CHECKSUM
DW 42
ADDRESS21
DW OFFSET STROKA
DW SEG STROKA
SIZ1
DW 534
I. ********************

;
CHECKSUMS
LEN3
TRANSPORTCONTROL3
PACKETTYPE3
DESTNETWORK3
DESTNODE3
DESTSOCKET3
SOURCENETWORK3
SOURCENODE3
SOURCESOCKET3
;SPX
CONNCONTROL3
DATASTREAMTYPE3
SOURCECONNID3
DESTCONNID3
SEQNUMBER3
ACKNUMBER3
ALLOCNUMBER3
/
STROKA3 DB 534 DUP(?)
/
LINK3
ESRADDRES3
INUSE3

DB
DB
DB
DB
DB
DB
DB
DB
DB
DW

2 DUP(?)
2 DUP(?)
0
5
4 DUP(?)
6 DUP(?)
2 DUP(?)
4 DUP(?)
6 DUP(?)
1007H

DB
DB
DW
DW
DW
DW
DW

DB
DB
DB

4 DUP(?)
4 DUP(O)
?

413

ASSEMBLER.

414

CCODE3
SOCKETS
IPXWORKSPACE3
DRIVERWORKS PACE 3
IMMADDRESS3
FRAGNENTCNT3
ADDRESS13
DW SEG CHECKSUMS
DW 42
ADDRESS23
DW SEG STROKA3
SIZ3
; 4
CHECKSUM4
LEN4
TRANSPORTCONTROL4
4
DESTNETWORK4
DESTNODE4
DESTSOCKET4
SOqRCENETWORK4
SOURCENODE4
SOURCESOCKET4
;SPX
CONNCONTROL4
DATASTREAMTYPE4
SOURCECONNID4
.DESTCONNID4
SEQNUMBER4
ACKNUMBER4
ALLOCNUMBER4
;
STROKA4 DB 534 DUP(?)
; 4
LINK4
ESRADDRES4
INUSE4
CCODE4
SOCKET4
IPXWORKSPACE4
DRIVERWORKSPACE4
IMMADDRESS4
FRAGNENTCNT4

DB ?
DW 1007H
DB 4 DUP(?)
DB 12 DUP(?)
DB 6 DUP(?)
DW 2
DW OFFSET CHECKSUMS

DW

OFFSET STROKA3

DW

534

DB
DB
DB
DB
DB
DB
DB
DB
DB
DW

2 DUP(?)
2 DUP(?)
0
5
4 DUP(?)
6 DUP(?)
2 DUP(?)
4 DUP(?)
6 DUP(?)
1007H

DB
DB
DW
DW
DW
DW
DW

?
?
?
?
?
?
?

DB 4 DUP{?)
DB 4 DUP(O)
DB ?
DB ?
DW 1007H
DB 4 DUP(?)
DB 12 DUP{?)
DB 6 DUP(?)
DW 2

21.

ADDRESS14
DW
DW
SEG CHECKSUM4
DW

OFFSET CHECKSUM4

42

ADDRESS24
DW OFFSET STROKA4
DW SEG STROKA4
SIZ4
DW 534
i.********************* *i ******************
; 5
CHECKSUMS
DB 2 DUP(?)
LENS
DB 2 DUP(?)
TRANSPORTCONTROL5 DB 0
PACKETTYPE5
DB 5
DESTNETWORK5
DB 4 DUP(?)
DESTNODE5
DB 6 DUP(?)
DESTSOCKET5
DB 2 DUP(?)
SOURCENETWORK5
DB 4 DUP(?)
DB 6 DUP(?)
SOURCENODE5
DW 1007H
SOURCESOCKET5
;SPX
CONNCONTROL5
DB ?
DATASTREAMTYPE5
DB ?
DW ?
SOURCECONNID5
DESTCONNID5
DW ?
DW ?
SEQNUMBER5
ACKNUMBER5
DW ?
DW ?
ALLOCNUMBER5
;
STROKA5 DB 534 DUP(?)
; 5
LINK5
DB 4 DUP(?)
ESRADDRES5
DB 4 DUP(O)
INUSE5
DB ?
CCODE5
DB ?
DW 1007H
SOCKETS
DB 4 DUP(?)
IPXWORKSPACE5
DRIVERWORKSPACE5 DB 12 DUP(?)
IMMADDRESS5
DB 6 DUP(?)
DW 2
FRAGNENTCNT5
DW OFFSET CHECKSUMS
ADDRESS15
DW SEG CHECKSUMS
DW 42
ADDRESS25
DW OFFSET STROKA5
DW SEG STROKA5
DW 534
SIZ5

415

ASSEMBLER.

416

.******************************************

; 6
CHECKSUM6
LEN6
TRANSPORTCONTROL6
PACKETTYPE6
DESTNETWORK6
DESTNODE6
DESTSOCKET6
SOURCENETWORK6
SOURCENODE6
SOURCESOCKET6
;SPX
CONNCONTROL6
DATASTREAMTYPE6
SOURCECONNID6
DESTCONNID6
SEQNUMBER6
ACKNUMBER6
ALLOCNUMBER6
;
STROKA6 DB 534 DUP(?)
;
LINK6
ESRADDRES6
INUSE6
CCODE6
SOCKET6
IPXWORKSPACE6
DRIVERWORKSPACE6
IMMADDRESS6
FRAGNENTCNT6
ADDRESS 16
DW SEG CHECKSUM6
DW 42
ADDRESS26
DW SEG STROKA6

DB
DB
DB
DB
DB
DB
DB
DB
DB
DW

2 DUP(?)
2 DUP(?)
0
5
4 DUP(?)
6 DUP(?)
2 DUP(?)
4 DUP(?)
6 DUP(?)
1007H

DB
DB
DW
DW
DW
DW
DW

7
?
7
7

7
7
7

DB 4 DUP(?)
DB 4 DUP(O)
DB 7
DB 7
DW 1007H
DB 4 DUP(?)
DB 12 DUP(?)
DB 6 DUP(?)
DW 2
DW OFFSET CHECKSUM6

DW

OFFSET STROKA6

size
DW 534
;
. *////***********.******;*** vt********\\\************
; 2
CHECKSUM2
DB 2 DUP(?)
LEN2
DB 2 DUP(?)
TRANSPORTCONTROL2 DB 0

21.

PACKETTYPE2
DESTNETWORK2
DESTNODE2
DESTSOCKET2
SOURCENETWORK2
SOURCENODE2
SOURCESOCKET2

DB
DB
DB
DB
DB

5
4 DUP (?)
6 DUP (?)
2 DUP (?)
4 DUP (?)
DB 6 DUP (?)
DW 1007H

;SPX
CONNCONTROL2
DB
DATASTREAMTYPE2
DB
SOURCECONNID2
DW
DW
DESTCONNID2
SEQNUMBER2
DW
ACKNUMBER2
DW
ALLOCNUMBER2
DW
;
STROKA2
DB 534 DUP(?)
; 1
LINK
DB 4 DUP(? )
ESRADDRES
DB 4 DUP(O)
INUSE
DB ?
DB ?
CCODE
DW 1007H
SOCKET
IPXWORKSPACE
DB 4 DUP(? )
DRIVERWORKS PACE
DB 12 DUP(? )
IMMADDRESS
DB 6 DUP(? )
FRAGNENTCNT
DW 1
ADDRESS1
DW OFFSET CHECKSUM2
DW SEG CHECKSUM2
DW 42
ADDRESS2
DW OFFSET STROKA2
DW SEG STROKA2
SIZ
DW 534
;
TEXT1 DB " .",13,10,'$'
TEXT2 DB " .",13,10,'$'
DB " .",13,10,'$'
_DX DW ?
DATA ENDS
STAC SEGMENT STACK
DW 100 DUP(?)
STAC ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:STAC, ES:DATA
14-4072

417

418

ASSEMBLER.

BEGIN:
MOV A X , D A T A
MOV DS, AX
CALL WHAT_POINT
CMP A L , O F F H
JZ
_OK1
LEA DX,TEXT1
MOV A H , 9
INT 21H
JMP _END
_OK1:

/ SPX
/
XOR BX,BX
MOV AL,OH
MOV DX,1007H
CALL DWORD PTR CS:NET_POINT
CMP A L , 0

JZ
OK_OPEN
;
LEA DX,TEXT2
MOV AH,9
INT 21H
JMP _END
OK_OPEN:
;
PUSH DS
POP ES
;
LEA SI,DS:LINK1
MOV BX,17H
CALL DWORD PTR CS:NET_POINT
LEA SI,DS:LINK3
MOV BX,17H
CALL DWORD PTR CS:NET_POINT
LEA SI,DS:LINK4
MOV BX,17H
CALL DWORD PTR CS:NET_POINT
LEA SI,DS:LINKS
MOV BX,17H
CALL DWORD PTR CS:NET_POINT
LEA SI,DS:LINK6
MOV BX,17H
CALL DWORD PTR CS:NET POINT

(17)

21..

;
MOV BX,12H
MOV A L , 0
MOV ,
LEA SI,ES:LINK
CALL DWORD PTR CS:NET_POINT
;
WAI:
MOV AH, 1
INT
16H
JNZ _CLOSE
CALL FOR_WAIT
CMP D S : I N U S E , 0
JNZ WAI

MOV _DX,DX
;
LEA DX,TEXT3
MOV AH,9
INT 21H
_ABORT:
MOV DX,_DX
MOV BX,14H
CALL DWORD PTR CS:NET_POINT
;
_CLOSE:
MOV BX,1
MOV DX,1007H
CALL DWORD PTR CS:NET_POINT
_END:
MOV AX,4COOH
INT 21H
/
;
/
WHAT__POINT PROC
MOV AX,7AOOH
INT 2FH
CMP AL,OFFH
JNZ NO_IPX_SPX
MOV CS:NET_POINT,DI
MOV CS:NET_POINT+2,ES
/ SPX
XOR AL,AL
MOV BX,10H
CALL DWORD PTR CS:NET POINT

14*

419

420

ASSEMBLER.

NO_IPX_SPX:
RETN
WHAT_POINT ENDP
/,
FOR_WAIT PROC
PUSH BX
MOV BX,OAH
CALL DWORD PTR CS:NET_POINT
POP BX
RET
FOR_WAIT ENDP
PAUSE PROC
PUSH CX
MOV CX,20
DAL:
PUSH CX
MOV CX,OFFFFH
PA:
LOOP PA
POP CX
LOOP DAL
POP CX
RET
PAUSE ENDP
;
NET_POINT DW ?
DW ?
CODE ENDS
END BEGIN

/, SPX (2)/
;7002 (2007)
/
DATA SEGMENT
/
/
.************************************
/ 1
CHECKSUM
DB 2 DUP(?)
LEN
DB 2 DUP(?)
TRANSPORTCONTROL DB 0
PACKETTYPE
DB 5
DESTNETWORK
DB 4 DUP(O)
DESTNODE
DB 6 DUP(O)

21.

DW 0
DESTSOCKET
DB 4 DUP(?)
SOURCENETWORK
DB 6 DUP(?)
SOURCENODE
DB 2 DUP(?)
SOURCESOCKET
; SPX
DB 7
CONNCONTROL
DB 7
DATASTREAMTYPE
DW 7
SOURCECONNID
DW 7
DESTCONNID
DW 7
SEQNUMBER
ACKNUMBER
DW 7
DW 7
ALLOCNUMBER
;
DB 534 DUP(?)
STROKA
.************************************

; 1
LINK1
DB 4 DUP(?)
DB 4 DUP(O)
ESRADDRES1
DB 1
INUSE1
DB 7
CCODE1
DW 2007H
SOCKET1
DB 4 DUP(?)
IPXWORKSPACE1
DRI VERWORKS PACE 1 DB 12 DUP(?)
DB 6 DUP(O)
IMMADDRESS1
DW 2
FRAGNENTCNT1
DW OFFSET CHECKSUM
ADDRESS11
DW SEG CHECKSUM
DW 42
DW OFFSET STROKA
ADDRESS21
DW SEG STROKA
SIZ1
DW 534
. ************************************
/ 3
DB 2 DUP(?)
CHECKSUMS
DB 2 DUP(?)
LEN3
TRANS PORTCONTROL3 DB 0
DB 5
PACKETTYPE3
DB 4 DUP(O)
DESTNETWORK3
DB 6 DUP(O)
DESTNODE3
DW 0
DESTSOCKET3
DB 4 DUP(?)
SOURCENETWORK3
DB 6 DUP(?)
SOURCENODE3
DB 2 DUP(?)
SOURCESOCKET3
;SPX

421

422
CONNCONTROL3
DATASTREAMTYPE3
SOURCECONNID3
DESTCONNID3
SEQNUMBER3
ACKNUMBER3
ALLOCNUMBER3
;
STROKA3

ASSEMBLER.

7
7

7
7
DW 7
DW 7
DB
DB
DW
DW
DW

DB 534 DUP(?)

/.************************************

; 3
DB 4 DUP(?)
LINK3
ESRADDRES3
DB 4 DUP(O)
INUSE3
DB 1
CCODE3
DB 7
SOCKETS
DW 2007H
DB 4 DUP(?)
IPXWORKSPACE3
DRIVERWORKSPACE3
DB 12 DUP(? )
IMMADDRESS3
DB 6 DUP (0)
DW 2
FRAGNENTCNT3
ADDRESS31
DW OFFSET CHECKSUMS
DW
SEG CHECKSUMS
42
DW
ADDRESS32
DW OFFSET STROKA3
DW
SEG STROKA3
DW 534
SIZ3
/**

' * if -i *

;
CHECKSUM4
LEN4
TRANS PORTCONTROL4
PACKETTYPE4
DESTNETWORK4
DESTNODE4
DESTSOCKET4
SOURCENETWORK4
SOURCENODE4
SOURCESOCKET4
;SPX
CONNCONTROL4
DATASTREAMTYPE4
SOURCECONNID4
DESTCONNID4
SEQNUMBER4

4
DB 2 DUP (?)
DB 2 DUP (?)
DB 0
DB 5
DB 4 DUP (0)
DB 6 DUP (0)
DW 0
DB 4 DUP (?)
DB 6 DUP (?)
DB 2 DUP (?)
DB
DB
DW
DW
DW

7
7
7
9

21.

ACKNUMBER4
ALLOCNUMBER4

DW
DW

?
?

;
STROKA4

DB 534

DUP(?)

. *************************** * * *******

; 4
LINK4
DB 4 DUP(?)
ESRADDRES4
DB 4 DUP(O)
INUSE4
DB 1
CCODE4
DB ?
SOCKET4
DW 2007H
IPXWORKSPACE4
DB 4 DUP(?)
DRIVERWORKSPACE4 DB 12 DUP(?)
IMMADDRESS4
DB 6 DUP(O)
FRAGNENTCNT4
DW 2
ADDRESS41
DW OFFSET CHECKSUM4
DW SEG CHECKSUM4
DW 42
ADDRESS42
DW OFFSET STROKA4
DW SEG STROKA4
SIZ4
DW 534
/*************************************
; 5
CHECKSUMS
DB 2 DUP(?)
LENS
DB 2 DUP(?)
TRANSPORTCONTROL5 DB 0
PACKETTYPE5
DB 5
DESTNETWORK5
DB 4 DUP(O)
DESTNODE5
DB 6 DUP(O)
DESTSOCKET5
DW 0
SOURCENETWORK5
DB 4 DUP(?)
SOURCENODE5
DB 6 DUP(?)
SOURCESOCKET5
DB 2 DUP(?)
;SPX
CONNCONTROL5
DB ?
DATASTREAMTYPE5
DB ?
SOURCECONNID5
DW ?
DESTCONNID5
DW ?
SEQNUMBER5
DW ?
ACKNUMBER5
DW ?
ALLOCNUMBER5
DW ?
;
STROKA5
DB 534 DUP(?)
. ****************>

423

424

; 5
DB 4 DUP(? )
LINKS
DB 4 DUP(O)
ESRADDRES5
DB 1
INUSE5
DB ?
CCODE5
SOCKETS
DW 2007H
DB 4 DUP(? )
IPXWORKSPACE5
DRIVERWORKS PACES DB 12 DUP(?)
DB 6 DUP(O)
IMMADDRESS5
DW 2
FRAGNENTCNT5
DW OFFSET CHECKSUMS
ADDRESS51
DW
SEG CHECKSUMS
DW 42
ADDRESS52
DW OFFSET STROKA5
DW SEG STROKA5
SIZ5
DW 534
; t 6
CHECKSUMS
DB 2 DUP(?)
LEN6
DB 2 DUP(?)
TRANSPORTCONTROL6 DB 0
DB 5
. PACKETTYPE6
DB 4 DUP(O)
DESTNETWORK6
DESTNODE6
DB 6 DUP(O)
DW 0
DESTSOCKET6
DB 4 DUP(?)
SOURCENETWORK6
DB 6 DUP(?)
SOURCENODE6
SOURCESOCKET6
DB 2 DUP(?)
;SPX
CONNCONTROL6
DB
DB
DATASTREAMTYPE6
DW
SOURCECONNID6
DESTCONNID6
DW
SEQNUMBER6
DW
ACKNUMBER6
DW
ALLOCNUMBER6
DW
;
STROKA6
DB 534 DUP(?)
.************************************
;
LINK6
DB 4 DUP(?)
ESRADDRES6
DB 4 DUP(O)
INUSE6
DB 1
CCODE6
DB ?

ASSEMBLER.

21.

SOCKET
IPXWORKSPACE6
DRIVERWORKSPACE6
IMMADDRESS6
FRAGNENTCNT6
ADDRESS 61

DW 2007H
DB 4 DUP(?)
DB 12 DUP(?)
DB 6 DUP(O)
DW 2
DW OFFSET CHECKSUM6
DW SEG CHECKSUMS
DW 42
ADDRESS 62
DW OFFSET STROKA6
DW SEG STROKA6
size
DW 534
;
.**/////**********************************\\\\\******
;
CHECKSUM2
LEN2
TRANS PORTCONTROL2
PACKETTYPE2
DESTNETWORK2

DESTNODE2

DESTSOCKET2
SOURCENETWORK2
SOURCENODE2
SOURCESOCKET2
;SPX
CONNCONTROL2
DATASTREAMTYPE2
SOURCECONNID2
DESTCONNID2
SEQNUMBER2
ACKNUMBER2
ALLOCNUMBER2

2
DB 2 DUP(O)
DB 2 DUP(O)
DB 0
DB 5
DB 00
DB 00
DB 19H
DB 58H
DB
DB 40H
DB 95H
DB OEOH
DB 9FH
DB 67H
DW 1007H
DB 4 DUP(?)
DB 6 DUP(?)
DB 2 DUP(?)

DB
DB
DW
DW
DW
DW
DW

0
0
0
0
0
0
0

/. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

; 2
LINK
DB
ESRADDRES
DB

4 DUP(O)
4 DUP(O)

425

ASSEMBLER.

426

INUSE
CCODE
SOCKET
IPXWORKSPACE
DRIVERWORKSPACE
IMMADDRESS

FRAGNENTCNT
ADORES SI

;
TEXT1 DB
TEXT2 DB
DB
4 DB

DB
DB
DW
DB
DB
DB
DB
DB
DB
DB
DB
DW
DW
DW
DW

0
0
2007H
4 DUP(? )
12 DUP(? )

40H
95H
OEOH
9FH
67H
1
OFFSET CHECKSUM2
SEG CHECKSUM2
42

" .",13,10,'$'
" ",13,10,'$'
" .",13,10,'$'
" .",13,10,"$"
_DX DW ?

DATA ENDS
STAC SEGMENT STACK
DW 100 DUP(?)
STAC ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SSrSTAC, ES:DATA
BEGIN:
MOV AX,DATA
MOV DS,AX
CALL WHAT_POINT
CMP AL,OFFH
JZ __OK1
LEA DX,TEXT1
MOV AH,9
INT 21H
JMP _END
_OK1:
; SPX
;
XOR BX,BX
MOV AL, OH
MOV DX,2007H
CALL DWORD PTR CS:NET POINT

21.

CMP AL,0
JZ
OKJDPEN
;
LEA DX,TEXT2
MOV ,9
INT 21H
JMP _END
OKJDPEN:
;
PUSH DS
POP ES
; (17)
LEA SI,ES:LINK1
MOV BX,17H
CALL DWORD PTR CS:NET_POINT
LEA SI,ES:LINKS
MOV BX,17H
CALL DWORD PTR CS:NET_POINT
LEA SI,ES:LINK4
MOV BX,17H
CALL DWORD PTR CS:NET_POINT
LEA SI,ES:LINKS
MOV BX,17H
CALL DWORD PTR CS:NET_POINT
LEA SI,ES:LINK6
MOV BX,17H
CALL DWORD PTR CS:NET POINT

; .
MOV 1
MOV AL,0
MOV AH,0
LEA SI,ES:LINK
CALL DWORD PTR CS:NET_POINT
/,
CMP AL, 0
JZ
WAI
LEA
DX,TEXT4
MOV AH,9
INT 21H
JMP SHORT _CLOSE
;
WAI:
MOV AH,1
INT 16H

427

428

ASSEMBLER.

JNZ _CLOSE
CALL FOR_WAIT
CMP DS:INUSE,0
JNZ WAI
MOV _DX,DX .
;
LEA DX,TEXT3
MOV AH,9
INT 21H
_ABORT:
MOV DX,_DX
MOV BX,14H
CALL DWORD PTR CS:NET_POINT
_CLOSE:
MOV BX,1
MOV DX,2007H
CALL DWORD PTR CS:NET_POINT
_END:
MOV AX,4COOH
INT 21H
;
;
;
WHAT_POINT PROC
MOV AX,7
INT 2FH
CMP AL,OFFH
JNZ NO_IPX_SPX
MOV CS:NET_POINT,DI
MOV CS:NET_POINT+2,ES
; SPX
XOR AL,AL
MOV BX,10H
CALL DWORD PTR CS:NET_POINT
NO_IPX_SPX:
RETN
WHAT_POINT ENDP
;,
FOR_WAIT PROC
PUSH BX
MOV BX,OAH
CALL DWORD PTR CS:NET_POINT
POP BX
RET

21.

429

FOR_WAIT ENDP
PAUSE PROC
PUSH CX
MOV C X , 2 0
DAL:

PA:

PUSH CX
MOV CX,OFFFFH
LOOP PA
POP

CX

LOOP DAL
POP
RET

CX

PAUSE ENDP
/
NET_POINT DW ?
DW ?
CODE ENDS
END BEGIN
. 21.5 , SPX
.

V. ( 21- ).
.
, ,
, .
21- . ,
,
. ,
.
DOS- . , , .
21- , ,
:
1. DOS- ,
. , ,
.. ,
, .
2. , .
3. ,
.

430

ASSEMBLER.

, 2- 3- , .
. .

2
3
4
5
6
7
8
9

26
8000
FFFFH

.
- , 4 ,
-.
- , 47 . , MS DOS.
- . - , 1 , .. .
- , - , - .
:
0 - .
1 - .
2 - - .
3 - .
4 - .
, : 0 , FFH - .
: -
15 , - - . :

21.

'

431

- ,
xl -
-
1 - .
, .
- ,
(, )
- .
128- .
. ,
.

.
1. -.
.
:
=01
ES:DI= 40 ,
. 4 :
- ,
- ,
- ,
- - .
:
= 0,
2.1,
= ,
= .
-.
:
AH=F1H
AL= 0 - -, DL.
= 1 - , DL.
= 2 - -, DL.
:
AL=0, .
.
:
AH=OFH,
AL=0 - -, DL,
= 1 - , AL,
= 2 - AL ,
= 4 - -, DL,
= 5 - AL -

432

ASSEMBLER.

-.
:
AH = OF1H
AL=1
DL = .
:
AL -
= 0
= FFH
.
.
:
=
DS:SI -
ES :DI - .
:
AL = 0 .
:
DW ? ;
DB?;type-16H
DB ? ;
:
DW ? ;
DD ? ; .
DW ? ; . .
DB 48 dup(?) ;
DB 7 dup(?) ;
:
1- 0 99 (0 =1980)
2- (1-12)
3- (1-31)
4 - (0-24)
5 - (0 - 59)
6 - (0-59)
7 - , 0-6 (0 - )
.
:
AH=DCH
:
AL =
CL =
= .
.
, ,
.

21.

433

=
DS:SI -
ES:DI -
:
DW ? ;
DB?;type-13H
DB ? ;
:
DW ?
DB 4 dup(?) ;
DB 6 dup(?) ;
DB 2 dup(?) ;
.
, .
:
=
DS:SI -
ES:DI -
:
AL = 0 - .
:
DW ? ;
DB?;type=15H
DW ? ; ( )
DB ? ;
DB 48 dup(?) ;
:
DW ?
DB ? ;
DB 100 dup(?) ;
.
:

=
DS:SI -
ES:DI -
:
AL = 0
= FFH
:
DW ? ;
DB?;type-14H
DW ? ; ( )
DB ? ;

434

ASSEMBLER.

DB 48 dup(?) ; ( )
DB ? ;
DB 128 dup(?) ; ( )
:
DW ? ;
.
:
AH = D7H
.
:
AH = F1H
AL = 2
DL = (1-8)
.
:
= 7
DS:DX - , 7 .
:
:
0 0 99, 80 XXI
1 (1-12)
2 (1-31)
3 (0-23)
4 (0-59)
5 (0-59)
6 (0-6,0 - )
.
:
= 1
DS:SI - ,
ES:DI - .
:
AL - 0 .
:
DW ? ;
DB ? ;type = 202
?;
DB ? ;
DB ? ;
DB ? ;
DB ? ;
DB ? ;
:
DW ? ;

21.

435

-.
:
=
DS:SI -
ES:DI -
:
AL 0 .
:
DW ? ;
DB?;type = 211
DB ? ;FFH -
00 - ,
:
DW ? ;
.
:
=
DS:SI -
ES:DI -
:
AL 0 .
:
DW ? ;
DB ? ;type = 203 - , 204 - .
:
DW ? ;

2. .
( MS
DOS) .
( ).
:
= 2
DS:SI -
ES:DI -
:
DW ?
DB ? ;type - 6
DB ? ;
:
DW ? ;
DB ? ;
DB 16 dup(?) ;
, .

436

ASSEMBLER.

( ).
:
= 2
DS:SI -
ES:DI -
:
DW ? ;
DB ? ;type - 5
DB ? ;
DB 16 dup(?) ;
:
DW ?
DB ? ; .
.
:
= 2
DL = .
ES:DI -
:
1 = 0 .
:
DW ?,'
DW? ;
DW ? ;
DW ? ;
DW ? ; ,
d b l 6 dup(?) ;
DW ?
.
:
= 2
DS:SI -
ES:DI -
:
AL - 0 .
:
DW ? ;
DB ? ;type -18
DB ? ;
DB ?
DB ? ;
DB ? ;
:
DW ? ;

21.

437

DB ? ;
DB ? ;
, type=19.
,
:
DW ? ;
DB ? ;type - 20
DB ? ;
.
:
AH=EFH
AL = 0 - (32 ),
1 - (32 ),
:
0 - ,
1 - ,
2 - ,
80 - ,
81 - ,
82 - .
2 - (32 ),
3 - ,
4 - (48 ).
:
ES:SI - .
.
:
= 2
DS:SI -
ES:DI -
:
DW ? ;
DB?;type-2
DB ? ; 0,
; ,
DW ?
DB ? ;
?;
:
DW ? ;
DB 16 DUP(?) ;
DB 2 DUP(?) ;
DB 2 DUP(?) ;
DB 4 DUP(?) ; , .

438

ASSEMBLER.

DB ?;
DB ?;
DW ?;
.
:
= 2
DS:SI -
ES:DI -
:
AL - 0 .
:
DW ? ;

DB?;type-10

DB ? ;
DB ? ;
DB ? ;
DB ? ;
.
:
DW ? ;
DB ? ;type - 11
DB ? ;
DB ? ;
DB ? ;
DB ? ;
.
:
DW ? ;
DB?;type-15
DB ? ;
DB ? ;
DB ? ;
DB ? ;
DB ? ;
.
:
= 2
2
DS:SI -
ES:DI -
:
AL - 0 .
:
DW ? ;

21.

DB ? ;type - 3
DB ? ;
DB ? ;
DB ? ;
.
:
= 2
DS:SI -
ES:DI -
:
AL - 0 .
:
DW ? ;
DB ? ;type - 3
DB ? ;
DB 4 DUP(?) ;
DB 4 dup(?) ;
DB ? ;
DB ? ;
DB ? ;

.
:
DW ? ;
DB ? ;type - 4
DB ? ;
DB ?
DB ?
DB ? ;
DB ? ;
CODE SEGMENT
ORG 100

ASSUME CS.-CODE, DS:CODE, SS:CODE, ES:CODE


BEGIN:
LEA SI,BUF_IN
LEA DI,BUF_OUT
MOV BYTE PTR N_VOL, OFFH
;
;
MOV WORD PTR BUF_IN,4
MOV WORD PTR BUF_OUT,19 ;
CON:
INC BYTE PTR N_VOL
MOV AH,OE2H

439

ASSEMBLER.

440
INT
CMP
JZ
LEA
MOV
INT
JMP

21H
AL,0
OK
DX,MES_ER
AH, 9
21H
SHORT _END

OK:
;
CMP LEN,0

/ -
JZ _END
;
MOV BL,LEN
XOR BH,BH
MOV BYTE PTR NAM+[BX],13
MOV BYTE PTR NAM+[BX]+1,10
MOV BYTE PTR NAM+[BX]+2, '$'
LEA DX,NAM
MOV AH,9
INT 21H
JMP SHORT CON
_END:
RET
;
BUF_IN DW ?
DB 6

N_VOL
DB 0
BUF_OUT DW ?
LEN
DB ?
NAM
DB 16 DUP{?)
MES_ER DB ' !',13,10,'$'
CODE ENDS
END BEGIN
Puc. 21.6. .
CODE SEGMENT
ORG 100H
ASSUME CS:CODE, DSrCODE, ES:CODE, SS.'CODE
BEGIN:
MOV BUF_IN,17 ;
MOV BUF_OUT, 4 ;
LEA SI,BUF_IN
LEA DI,BUF OUT

21.

MOV ,2
INT 21H
CMP AL,0
JZ _END
;
LEA DX,MES
MOV ,9
INT 21H
_END:
RET
;
;
BUF_IN
DW ?
;17
DB 18
DB 0
/
DISK
DB 'G1 ;
DB 11
DB 'SYS:PUBLIC1,0 /
;
BUF_OUT DW ?
;4
IND_NEW DB ?
DB ?
MES
DB ' .', 13,10, '$'
CODE ENDS
END BEGIN

441

Puc. 21.7. , G:
SYS:PUBUC.

3. .
, 21 - , . , , , .
.
:
=
DS:SI -
ES:DI -
:
AL = 0 .
:
DW ? ;
DB?;type=15

442

ASSEMBLER.

DW ? ; FFFFH,
DB ? ;
DB ? ;
DB ? ;
DB ? ;
:
DW ? ;
DW ? ;
DB 15 dup(?) ;
DB ? ;
DB ?
DB 4 dup(?) ;
DB 2 dup(?)
DB 2 dup(?)
DB 4 dup(?)
DB 4 dup(?)
DB 60 dup(?) ;
:
- ,
2 - ,
4 - ,
6 - , .
.
:
=
DS:SI -
ES:DI -
:
AL = 0 .
:
DW ? ;

DB?;type=16

DB ? ;
DB ?
DB 4 dup(?) ;
DB 2 dup(?)
DB 2 dup(?)
DB 4 dup(?)
DB 4 dup(?)
DB 60 dup(?) ;
DB ? ;
DB ? ;
DB ? ;
DB ? ;

21.

443

.
:
AL = 0 -
1 - .
DS:DX -
CL -
:
AL - 0
CL - .
.
:
AH = F3H
ES:DI -
:
AL - 0
DX:CX - .
:
DW ?
DW ?
DB 4 dup(?) ;
DB 4 dup(?) ;
DB 4 dup(?) ;
DOS.
, .
CODE SEGMENT
ORG 10

ASSUME CS:CODE, DS:CODE, SS:CODE, ES:CODE


BEGIN:
MOV AH,OE3H
LEA SI,BUF_IN
LEA DI,BUF_OUT
INT 21H
CMP AL, 0
JNZ _END /,
;
MOV CX, 12
LEA BX,NAM
MOV , 2

444

ASSEMBLER.

LOO:

MOV D L , [ B X ]
INT 21H
INC BX

LOOP LOO
MOV
INT
MOV
INT

DL,13
21H
DL,10
21H

/
MOV DX,NOMJDU
MOV NOM_IN,DX
JMP BEGIN
_END:
RET
/
/
BUF_IN
DW 23 /
DB 15
NOM_IN
DW OFFFFH /
DB
DB /, -
^
DB 14 /
DB 'SYS:PUBLIC\*.*',0
;
BUF_OUT DW 97 /
NOM_OU
DW ?
NAM
DB 15 DUP(?)
ATR
DB ?
ATR_EX
DB ?
LEN
DB 4 DUP(?)
DAT1
DB 2 DUP(?)
DAT2
DB 2 DUP(?)
DATS
DB 4 DUP(?)
DAT4
DB 4 DUP(?)
RES
DB 60 DUP(?)
CODE ENDS
END BEGIN
Puc. 21.8. SYS:PUBLIC,
.

21.

445

4. .
.
:
AH=DEH
DL = 4
:
AL - (0,1,2,3)
0 - . , (
).
1 - , ,
.
2 -
, .
3 - , .
.
:
AH=DEH
DL = .
.
:
= 1
DS:SI - ,
ES:DI - .
:
AL - 0 .
:
DW ?;
DB ?; type = 0
DB ?; ( )
DB ?;
DB ?;
DB ?;
:
DW ?;
DB ?;
DB ?; -
.
:
= 1

446

ASSEMBLER.

DS:SI - ,
ES:DI - .
:
AL - 0 .
:
DW ?;
DB ?; type = 1
:
DW ?;
DB ?;
DB ?;
.
:
= 1
DS:SI - ,
:
AL - 0 .
:
DW ?;
DB ?; type = 9
DB ?;
DB ?;

CODE SEGMENT
ASSUME CSrCODE, DS:CODE, ES:CODE
ORG 10OH
BEGIN:

; / RUFAT
MOV
LEA
LEA
INT
CMP
JZ
LEA
MOV
INT
JMP

OK:

,
SI,BUF_IN
DI,BUF_OUT
21H
AL,0
OK
DX,MES
AH, 9
21H
SHORT _END

21.

447

/
XOR ,
.MOV CL,N_CON
LEA SI,N_CON
INC SI

LEA DI,MAS
CLD
LOO:

LODSB
STOSB
LOOP LOO
;
LEA SI,BUF_IN_SEND
LEA DI,BUF_OUT_SEND
MOV AH,OE1H
INT 21H
_END:
RET
BUF_IN DW 11
DB 15H
DW 0100H
; - (1)
DB 5
;
DB 'RUFAT'
;
BUFJDUT DW 103
N_CON
DB ?
; ( )
DB 100 DUP(?) ;
BUF_IN_SEND DW 120
DB 0
N_SEND
DB 100 ; N_CON
MAS
DB 100 DUP(?)
DB 15 ;
DB ' !' ;
BUF_OUT_SEND DW 103
DB 100
DB 100 DUP(?)
MES
DB '!',13,10, '$'
CODE ENDS
END BEGIN
Puc. 21.9. ,
R UFA .

448

ASSEMBLER.

DATA SEGMENT
; LEN_BUF DW 4
DB 09H
LEN
DB ?
MES
DB 60 DUP(?)
/
MAX
DB 60
LENS
DB ?
STROKA
DB 61 DUP(?)
DATA ENDS
ST1 SEGMENT STACK
DB 100 DUP(?)
ST1 ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:ST1
BEGIN:
MOV AX,DATA
MOV DS,AX
MOV ES,AX
; (-> STROKA)
MOV AH,OAH
LEA DX,MAX
INT 21H
/ (STROKA -> MES)
CLD
LEA SI,STROKA
LEA DI,MES
MOV CL,LENS
MOV LEN,CL
XOR CH,CH
REP MOVSB
/ (MES -> CONSOLE)
LEA SI,LEN_BUF
MOV AH,OE1H / 1
INT 21H
_END:
MOV AH,4CH
INT 21H
CODE ENDS
END BEGIN
Puc. 21. . .

21.

5. .
.
:
=
DS:SI -
ES:DI - .
:
AL - 0 .
:
DW ? ;
DB?;type-41h
DW ? ; ( )
DB ? ; (48)
DB ? ;
DB ? ; (16)
DB ? ;
DW ? ;
DB ? ; (48)
DB ? ;
:
DW ? ;
.
:
=
DS:SI -
ES:DI - .
:
AL - 0 .
:
DW ? ;
DB ? ;type - 40h
DW ? ; ( )
DB ? ; (48)
DB ? ;
DB ? ; (127)
DB ? ;
DB ? ; (127)
DB ? ;
:
DW ? ;
15-4072

449

450

ASSEMBLER.

.
:

=
DS:SI -
ES:DI - .
:
AL - 0 .
:
DW ? ;
DB ? ;type - 38h
DB ? ;
DW ? ; ( )
DB ? ;
DB ? ;
:
DW ? ;
.
:
=
DS:SI -
ES:DI - .
:
AL - 0 .
:
DW ? ;
DB ? ;type - 3Bh
DW ? ; ( )
DB ? ;
DB ? ;
DB ? ;
DB ? ; (6)
DB ? ;
:
DW ? ;
.
:

=
DS:SI -
ES:DI - .
:
AL - 0 .

21.

:
DW ? ;
DB ? ;type - 44h
:
DW ? ;
.
:
=
DS:SI -
ES:DI - .
:
AL - 0 .
:
DW ? ;
DB?;type-32h
DB ? ;
DB ? ;
D W ? ; ( )
DB ? ;
DB ? ;
:
DW ?
.
:
=
DS:SI -
ES:DI - .
:
AL - 0 .
:
DW ? ;
DB ? ;type - 39h
DW ? ; ( )
DB ? ;
DB ? ;
DB ? ;
DB ? ;
DB ? ; (16)
DB ? ;
:
DW ? ;

15'

451

452

ASSEMBLER,

.
:
=
DS:SI -
ES:DI - .
:
AL - 0 .
:
DW ? ;
DB ? ;type - 33h
DW ? ; ( )
DB ? ;
DB ? ;
:
DW ? ;
.
:
=
DS:SI -
ES:DI - .
:
AL - 0 .
:
DW ? ;
DB ? ;type - 42h
DW ? ; ( )
DB ? ;
DB ? ;
DB ? ; (16)
DB ? ;
DW ? ( )
DB ? ;
DB ? ;
:
DW ? ;
.
:
=
DS:SI -
ES:DI - .
:
AL - 0 .

21.

:
DW ? ;
DB ? ;type - 3Ah
DW ? ;
DB ? ;
DB ? ;
DB ? ; (16)
DB ? ;
:
DW ? ;
.
:
=
DS:SI -
ES:DI - .
:
AL - 0 .
:
D W ? ;
DB ? ;type - 46h
:
DW ? ;
DB ? ;
DD ? ;
.
:
=
DS:SI -
ES:DI - .
:
AL - 0 .
:
DW ? ;
DB ? ;type - 35h
DW ? ; ( )
DB ? ;
DB ? ;
:
DW ? ;
.
:
=
DS:SI -
ES:DI - .

453

454

ASSEMBLER.

:
AL - 0 .
:
DW ? ;
DB ? ;type - 36h
DD ? ; ( )
:
DW ? ;
DD ? ( )
DW ? ; ( )
DB ? ;
,
.
:
=
DS:SI -
ES:DI - .
:
AL - 0 .
:
DW ? ;
DB ? ;type - 43h
DW ? ;
DB ? ;
DB ? ;
DB ? ;
DB ? ;
DW ? ; ( )
DB ? ;
DB ? ;
:
DW ? ;
.
:
=
DS:SI -
ES:DI - .
:
AL - 0 .
:
DW ? ;
DB ? ;type - 45h
:
DW ? ;

21.


128- .
:
=
DS:SI -
ES:DI - .
:
AL - 0 .
:
DW ?
DB ? ;type - 3Dh
DB ? ;
DB ?
DB ? ;
DB ? ; ( 1)
DB ? ;
DB ? ;
:
DW ? ;
DB ? ; ()
DB ? ;
DB ? ;
.
:
=
DS:SI -
ES:DI - .
:
AL - 0 .
:
DW ? ;
DB ? ;type - 34h
DB ? ;
DB ? ;
DB ? ;
DB ? ;
DB ? ;
:
DW ? ;
.
:
=
DS:SI -
ES:DI - .

455

456

ASSEMBLER.

:
AL - 0 .
:
DW ? ;
DB ? ;type - 37h
DW ? ;
DD ? ; ( FFFFFFFFh)
DW ? ;
DB ? ;
DB ? ;
:
DW ? ;
DD ?
DW ? ;
DB ? ; (48)
DB ? ;
DB ? ;
DB ? ;
FFFFFFFFh, , AL FCh.
.
:
=
DS:SI -
ES:DI - .
:
AL - 0 .
:
D W ? ;
DB ? ;type - 3Ch
DW ? ;
DB ? ;
DB ? ;
DD ? ; ( FFFFFFFFH)
DB ? ;
DB ? ;
:
D W ? ;
DB ? ;
DB ? ;
DB ? ;
DD ? .'
DB ? ;
DB ? ;

21.

457

, , , , , , .
:
=
DS:SI -
ES:DI - .
:
AL - 0 .
:
DW ? ;
DB ? ;type - 3Fh
DW ? ;
DB ? ;
DB ? ;
DB ? ; (128)
DB ? ;
:
DW ? ;

128- .
:
=
DS:SI -
ES:DI - .
:
AL - 0 .
:
DW ? ;
DB?;type-3Fh
DW ? ;
DB ? ;
DB ? ;
DB ? ;
DB ?
DB ? ;
DB ? ;
:
DW ? ;
CODE SEGMENT
ASSUME CS:CODE, DS:CODE, ES:CODE, SS:CODE
ORG 10OH

ASSEMBLER.

458

BEGIN:
MOV AH,OE3H
LEA SI,BUF_IN
LEA DI,BUF_OUT
INT 21H
CMP A L , 0
JNZ _END

MOV AL,ACCES
MOV DL,AL
MOV CL,4

SHR AL,CL
AND DL,00001111B
ADD DL,48
MOV AH, 2

PUSH AX
INT 21H
POP AX

MOV DL,AL
ADD DL,48
INT 21H

_END:
RET

BUF_IN

DW 3
DB 46H

BUF_OUT DW 7
ACCES
DB ?
DD ?

CODE ENDS
END BEGIN
. 21.11.
.
CODE SEGMENT
ASSUME CS:CODE, DS:CODE, ES:CODE, SS:CODE
ORG 100H
BEGIN:
MOV AH,OE3H
LEA SI,BUF_IN
LEA DI,BUF_OUT
INT 21H
CMP AL,0
JZ OKI
CMP AL,OFCH
JZ
END ;

21,

459

-
MOV DL,7
MOV ,2
INT 21H
JMP _END
OKI:
LEA BX,NAME2
MOV AH,2
;
LOO:
MOV DL, [BX]
CMP DL,0
JZ L001
INT 21H
INC BX
JMP SHORT LOO
L001:
MOV DL, 13
INT 21H
MOV DL,10
INT 21H
; ID1
MOV AX,WORD PTR ID2
MOV BX,WORD PTR ID2+2
MOV WORD PTR ID1,AX
MOV WORD PTR ID1+2,BX
JMP BEGIN
_END:
RET
BUF_IN DW 57
DB 37H
ID1
DD OFFFFFFFFH
DW 100H
LEN1
DB 47
NAME1
DB '*'
DB 46 DUP(O)
BUF_OUT DW 59
ID2
DD ?
DW ?
NAME2
DB 48 DUP(?)
FLAG
DB ?
SEC
DB ?
DB ?
CODE ENDS
END BEGIN
. 21.12. , .

460

ASSEMBLER.

6. .
,
. ,
( )
. , ..
.
:
AH=EDH
DS:DX -
:
AL - 0
:
BUF_IN db 255 dup(?) ;

.
:
AH=CFH

.
:
=
-
CX:DX -
SI:DI -
:
AL - 0
.
:
= 4
.
:
= 6
AL = 2
:
AL -
, - .
.
:
=
- - 1/18 .

21.

:
AL - 0 -
FEH - -
FFH - .
.
:
= 2
AL -
0 - ,
1 - Read-Only.
-- 1/18 .
:
AL - 0 -
FEH - -
FFH - .
.
:
=
AL -
0 -
1 - .
-- 1/18.( AL=1)
DS:DX - .
:
AL - 0 -
96 -
FEH - -
FFH-.
.
:
=
AL-
0 -
1 -
3 - Read-Only
-
- -
: DX -
SLDI -
:
AL - 0 -
96 -
FEH - -
FFH - .

461

462

ASSEMBLER.

.
:
-
DS:DX -
:
AL - 0 .
.
:
AH=CDH
, .
:
AH=BDH
-
CX:DX -
SLDI -
:
AL - 0 .
, .
:
=

.
:
= 6
AL -
CODE SEGMENT
ASSUME CSrCODE, DSrCODE, ES:CODE, SS:CODE
ORG 10OH
BEGIN:
;
MOV AH,OEBH
MOV AL,0
LEA DX,PATH
INT 21H
CMP AL,0
JNZ _END
; -
;
MOV ,
MOV ,10
INT 21H
CMP AL,
JNZ END
; -

21.

463

;
MOV ,
MOV A L , 2

LEA DX,PATH
INT 21H
JC _END

MOV BX,AX
;
/
;

MOV ,
INT 16H
;
MOV ,
INT 21H
/
MOV AH,OEDH
LEA DX,PATH

INT 21H
_END:
RET
PATH DB 'USER:SOFT\ME\STATUS.ME',0
CODE ENDS
END BEGIN
Puc. 21.13. .

7. .
Novel
- TTS - Transaction Tracking Service. ,
.
TTS "" "" .
:
- ,
- ,
- .
"" ,
. "" .

464

ASSEMBLER.

, ,
, .
:
= 7
AL = 3
:
AL = 0 .
.
:
= 7
AL = 0
:
AL = 0 .
.

:
= 7
AL=1
:
=
AL = 0
FDH
FEH
CX:DX -
= 1
AL = FFH -

.

:
= 7
AL = 5
:
AL = 0
CL - (0-255)
- .

.
:
= 7
AL = 7
:
AL = 0
CL - (0-255)
- .

21.

465

,
.
:
= 7
AL = 2
:
AL = 0 -
1 -
FDH - .

.
:
= 7
AL = 6
CL - (0-255)
- .
:
AL = 0

.
:
= 7
AL = 8
CL - (0-255)
- .
:
AL = 0
, .
:
= 7
AL = 4
CX:DX - .
:
AL = 0

8. .
,
, ,
,
.
:
AH = D6H
= 0 -
FFFFH - .
=0 DOS.

466

ASSEMBLER.

.
:
=
AL=1
= 0
ES:DI - .
:
- (0 - PC DOS)
AL -
-
BL -
CL -
ES:SI - .
:
40 .
. .
. . .

.
:
=
AL = 0 -
1 - .
:
AL = 0
, .
:
AH=DDH
DL = 0 - Abort, Retry, Fail?
1 - 24, NetWare
2 - 24, DOS .
:
AL - .

9. .
.

PRINT_CONTROL_DATA.
status db ?
print_flags db ?
tab_size db ?
server printer db ?

21.

467

number_copies db ?
form_type db ?
reservl db ?
banner_text db 13 dup(?)
reserv2 db ?
local_lpt_device db ?
flush_timeout_count dw ?
flush_on_close db ?
maximum_lines dw ?
maximum_chars dw ?
form_name db 13 dup(?)
lpt_flag db ?
file_flag db ?
timeout_flag db ?
setup_string_ptr dd ?
reset_string_ptr dd ?
connect_id_queue_print_job db ?
in_progres db ?
print_queue_flag db ?
print_job_valid db ?
print_queue_id dd ?
print_job_number dw ?
.
.
:
AH=DFH
DL = 2
:
AL - 0 .
.
.
:
AH=DFH
DL = 6
DH - LPT (0 - LPT1,1 - LPT2,2 - LPT3)
:
AL - 0 .

.
:
AH=DFH
DL=1
:
AL - 0 .

468

ASSEMBLER.


.
:
AH=DFH
DL = 5
DH - LPT (0 - LPT 1 , 1 - LPT2, 2 - LPT3)
:
AL - 0 .
,
.
:
AH=DFH
DL = 3
:
AL - 0 .
,
.
:
AH=DFH
DL = 7
DH - LPT (0 - LPT1 , 1 - LPT2, 2 - LPT3)
:
AL - 0 .
, .
:
= 8
ES:BX - (12 )
:
AL - 0 .
PRINT_CONTROLJDATA.
:
= 8
AL = 0
-
ES:BX -
:
AL - 0 .
, ,
.
:
= 8
AL = 4
:
DH - LPT.

21.

469

.
:
=
DS:SI -
ES:DI -
:
AL - 0 .
:
DW ? ;
DB ? ;type = 6
DB ? ; (0 - 4)
:
DW ? ;
DB ? ;0 - , FFH -
DB ?; 1 -
DB ? ;(0-255) - form_type
DB ? ;
PRINT_CONTROL_DATA,
, .
:
= 8
AL = 2
ES:BX -
DH - LPT
:
AL - 0 .
, .
:
= 8
AL = 9
ES:BX - (12 )
DH - LPT
:
AL - 0 .
.
:
= 8
AL = 6
: -
DH - LPT
:
AL - 0 .

470

ASSEMBLER.

PRINT_CONTROL_DATA
.
FORM_NAME, STATUS.
:
= 8
AL=1
- ( PRINT_CONTROL_DATA 42 )
ES:BX - .
:
AL - 0 .
.
.
:
= 8
AL = 5
DH - LPT
:
AL - 0 .
PRINT_CONTROL_DATA
.
:
= 8
AL = 3
- ( PRINT_CONTROL_DATA 42 )
ES:BX - .
DH - LPT.
:
AL - 0 .

.

=
AL = 9
DS:SI -
ES:DI -
:
AL - 0 .
:
DW ? ;
DB ? ;type = 9
DB ? ;0
DB ? ;
DB ? ;
:
DW ? ;

21.

471


.
:
AH=DFH
AL = 0
:
AL - 0 .
.
:
AH=DFH
AL = 4
DH = LPT.
:
AL - 0 .

10. .
- . 60
. :
- , , , ..
- , ;
- -127 - + 121,
;
- 1,
, , , 0, .
: , ,
1. 0,
, , ,
( ).
.
:
= 5
AL = 0
DS:DX - ( 127 0 )
CL - ( 1).
:
AL - 0 .
60

, .

472

ASSEMBLER.

.
:
= 5
AL=1
CX,DX -
:
AL - 0
-
DL - .
.
:

AL = 2
CX,DX -
-
:
AL - 0 .
.
:
= 5
AL = 3
CX,DX -
:
AL - 0 .
.
:
= 5
AL = 4
CX,DX -
:
AL - 0 .

11. .
01 - DOS,
02 -
03 -
04 -
05 -
06 -
07 -
08 -
09 -
- MS DOS
-

21.

473

-
ODH -
OFH -
-
11 - ,
12 -
20 -
21 -
80 -
81 -
82 -
83 - /
84 -
85 -
86 - , " "
87 -
88 -
89 -
8 -
8 -
8 -
8DH -
8 -
8FH - , " "
90 - , " "
91 - ,
92 - ,
93 -
94 - , " "
95 -
96 -
97 -
98 -
99 -
9 -
9 -
9 -
9DH -
9 -
9FH -
-
1 - /
2 -
-
1 -

474

ASSEMBLER.

2 -
5 -
6 -
-
D1 -
D2H -
D3H -
D4H -
D5H -
D6H -
D7H -
D8H -
D9H -
DAH -
DBH -
DCH -
DEH -
DFH -
EFH -
FOH -
F1H -
F2H -
F3H -
F4H -
F5H -
F6H -
F7H - ,
F8H - ,
,
F9H - ,
-
FBH - , ,
FCH - -, ,

FDH -
FEH - , ,
,
FFH - , , , , , , , , -, , , , ,
, .

22. , MS DOS
.
- , !

. .
MS DOS
, , . 61. , , . , Intel .


(EXTENDED MEMORY)

- 64 .
1 .

ROM


(EXPANDED
MEMORY)


UMB
640 .

640 .
.

. 22.1. .
61

MS DOS UNIX.
Microsoft.

476

ASSEMBLER.

. 22.1 , IBM- MS DOS. . 2.3 ( 2). : , , ,


, , , - High Memory
Area - - 64 .

I. .
286- , 640 . 1985 : LOTUS, INTEL, MICROSOFT - , XT .
LIM EMS (LIM - , .. LotusIBM-Microsoft, EMS - EXPANDED MEMORY SPECIFICATION). 4.0, 32
.
.
.
EMM. EMM
16 , .
64 640 1,
16 . 64
.
, :
1. EMM .
2. , EMM
.
.
3. - .
4. , , 1 ,
.
,
.
62 .
, 80286-, (. ).
. 386 , EMM386.EXE
QEMM, , MS DOS,
.
, , .

22. , MS DOS

477

. EMM. (EXPANDED
MEMORY MANAGER)
67.
. . 0, .
, .
1. EMM.
:
-40
:
- ,
80 ,
81 .
2. .
:
-41
:
- ,
- ,
- 80 ,
- 81 .
3. EMS .
:
-42
:
- ,
- ,
DX - EMS ,
- 80 ,
- 81 .
4. EMS .
:
-43
- .
:
- ,
DX - ,
- 80 ,
- 81 ,
- 85 ,
- 87 ,
- 88 .

478

ASSEMBLER.

5. .
:
-44
AL - (0-3),
- ( 0),
DX - .
:
- ,
- 80 ,
- 81 ,
- 83 ,
- 8 ,
- 8 .
6. EMS.
:
-45
DX - .
:
- ,
- 80 ,
- 81 ,
- 83 ,
- 85 .
7. EMM.
:
-46
:
- ,
AL - EMM,
- 80 ,
- 81 .
8. .
:
-47
DX - .
:
- ,
- 80 ,
- 81 ,
- 83 ,
- 8 .
9. .
:
-48
DX-.

22. , MS DOS

479

:
- ,
- 80 ,
- 81 ,
- 83 ,
- 8 .
10. .
:
-4.
:
- ,
- ,
- 80 ,
- 81 .
11. .
:
-4
DX - .
:
- ,
- ,
- 80 ,
- 81 .
- 83 .
12. .
:
AH-4DH
ES - ,
DI - .
:
- ,
- ,
- 80 ,
- 81 .
. . - ,
- , - .
, .
DATA

SEGMENT

1 DB ' E M M ! ' , 1 3 , 1 0 , '$ '


2 DB ' . ' , 1 3 , 1 0 , ' $ '

480

ASSEMBLER.

STRING DB ' '


DB ' EMS.',13,10, ' $ '
DATA ENDS
_ST SEGMENT STACK
DB 100 DUP(?)
_ST ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:_ST
BEG:
/
MOV AX,DATA
MOV DS,AX
/
CLD
/ EMM
MOV ,4
INT 67H
OR ,
JZ OKI
CALL ERR
JMP DOS
OKI:
/
MOV ,41
INT 67H
OR
,
JZ
OK2
CALL ERR
JMP DOS
OK2:
MOV ES,BX / EMS
/ EMS
MOV AH,42H
INT 67H
OR
,
JZ

CALL ERR
JMP DOS
:
CMP BX,2
JNB OK4
LEA DX,TEXT2
CALL PRINT
JMP DOS

22. , MS DOS

4:
;
MOV ,43
MOV , 1
INT 67
OR
,
JZ
5
CALL ERR
JMP DOS
5:
MOV
BP,DX /
/
MOV ,44
MOV AL,
MOV ,
INT 67H
OR
,
JZ
0
CALL ERR
JMP DOS
0:
; STRING
LEA
SI,STRING
XOR DI,DI
LOO:
MOV AL,DS:[SI]
MOV ES:[DI],AL
INC SI
INC DI
CMP AL, ' $ '
JNZ LOO
;
MOV AH,43H

MOV ,1
INT 67H
OR ,
JZ OK7
CALL ERR
JMP DOS
OK7:
;
MOV AH,44H
MOV AL,1
MOV BX,0
16-4072

481

482

ASSEMBLER,

INT 67H
JZ OK8
CALL ERR
JMP DOS
OK8:
;
;- 1, DS-
MOV AX,ES
MOV DS,AX
ADD AX,1024 ; 1
MOV ES,AX
XOR SI,SI
XOR DI,DI
MOV CX,16*1024
L001:
MOV AL,DS:[SI]
MOV ES:[DI],AL
INC SI
INC DI
LOOP L001
/ ( )
XCHG DX,BP
MOV AH,45H
INT 67H
OR
,
JZ
OK9
CALL ERR
JMP DOS
OK9:
MOV DX,BP
;
MOV ,44
MOV AL,2
MOV ,0
INT 67H
JZ
OKI
CALL ERR
JMP DOS
OK10:
;
PUSH DX
MOV DX,32*1024
CALL PRINT
POP DX

22. , MS DOS

483

;
CLOSE:
MOV AH,45H
INT 67H
; DOS
DOS:
MOV AH,4CH
INT 21H
/
/
ERR
PROC
PUSH DS
PUSH AX
LEA DX,TEXT1
MOV AX,DATA
MOV DS,AX
CALL PRINT
POP AX
POP DS
RET
ERR
ENDP
;
PRINT PROC
MOV , 9
. INT 21H
RET
PRINT ENDP
CODE ENDS
END BEG
PMC. 22.2. .
. 22.2 : , EMM. , .
EMM , ,
"".
3DH. , ,
. DOS 44H - 0. , , .
7 44. (. 22.3)
, EMM.
CODE SEGMENT
ASSUME CS:CODE,DS:CODE
ORG 10OH

16'

484

ASSEMBLER.

BEGIN:
;
MOV ,
MOV AL,
LEA DX,STR_EMM
INT 21H
JC NO_EMM1
;,
MOV ,
MOV ,4400
INT 21H
JC NO_EMM
/ 7- ,
TEST DX,80H
JZ NO_EMM
/
MOV AX,4407H
INT 21H
JC NO_EMM
CMP AL,0
JZ NO_EMM
LEA DX,STR2
JMP SHORT KONEC
NO_EMM:
LEA DX,STR1
KONEC:
MOV AH,9
INT 21H
;
CALL CLOSE
RET
NO_EMM1:
LEA DX,STR1
MOV AH,9
INT 21H
RET
;
STR_EMM DB "",
STR1
DB " EMM ", 13,10,'$'
STR2
DB " EMM ", 13,10, '$'
/
CLOSE PROC
MOV ,
INT 21H
RET

22. , MS DOS

485

CLOSE ENDP
CODE
ENDS
END BEGIN
. 22.3 , EMM.
EMM ,
67 . , 10
, ,
''.
. ,
- .

III. .
- . 5 20 (. . 5.2 20.2). 5
15, 20
. HIMEM.SYS . , .
15 . HIMEM.SYS . INT15=N, N -
, 15,
.

IV. .
(HIGH MEMORY AREA) ROM BIOS
( 1 ) 64 . 80286 8088. , 8088, FFFF:OOOF, 20 . 1, , 0000:0000. , 8088
FFFF:0010 - FFFF:FFFF ( 64 16 ) . 80286 20. , , 80286 ( 80386 ..)
( 20) , 8088.
. , HIMEM.SYS (. ). 5.0, MS DOS (DOS=HIGH).

V. (UMB).
UMB - UPPER MEMORY BLOKS, ..
. ? 640
1 .

486

ASSEMBLER.

. , .
, EMM386.EXE, QEMM ., . ( , 386- )

. , UMB, .

VI. HIMEM.SYS.
HIMEM.SYS : , UMB. ,
:
1. . 2FH:
MOV , 4 3 0 0

INT 2FH
CMP A L , 8 0 H

; AL 80H,

JNE NO_HIM

2. 32- :
ADR_HIM_OFF DW ?
ADR_HIM_SEG DW ?
MOV
INT
MOV
MOV

AX,4310H
2FH
WORD PTR CS:ADR_HIM_OFF,BX
WORD PTR CS:ADR HIM SEG,ES

:
MOV , 8 ;
CALL DWORD PTR CS:ADR_HIM_OFF /
,
2FH. , , , , .
3. 18 , 8
, 2 -
UMB, 6 . .

22. , MS DOS

.
: -
: - ,
- ,
DX - , .
.
: -1,
DX -
: -1,
.
:
-2
: -1,
20
:
-
: -1,
20
:
-4
:
20.
:
-5
: - 1 ,
20.
:
-6
:
20.
:
-7
: - ,
BL-
.
:
-8
: -
DX - .
.
:
-9
DX - .
: DX-
.
:
-
DX -
:

487

488

ASSEMBLER.

.
:
-
DX -
: DS:SI -

DWORD

WORD

DWORD

10

WORD

12

DWORD

.
:
-
DX -
: DX:BX - 32-
.
:
-
DX -
:
.
:
-
DX -
: DX - ,
- ,
BL -
.
:
AH-OFH
DX -
: - ,
DX -
UMB.
:
-
DX - .
: - ,
DX - .
UMB.
:
-11
- .
:

22. , MS DOS

489

.
, 1, , 0.
QEMM .
. (
MS DOS), , , .
DATA SEGMENT
1 DB ' .',13,10, '$'
2 DB ' ',13,10,'$'
TEXTS DB '!',13,, '$'
DATA ENDS
STT SEGMENT STACK
DB 100 DUP(?)
STT ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:STT
BEGIN:
;--
MOV AX,DATA
MOV DS,AX
;
MOV AX,4300H
INT 2FH
CMP AL,80H
JNE NO_HIM
JMP SHORT YES
NO_HIM:
LEA DX,TEXT1
MOV AH,9
INT 21H
JMP RON
YES:
;
MOV AX,4310H
INT 2FH
MOV WORD PTR CS:ADR_HIM_OFF,BX
MOV WORD PTR CS:ADR_HIM_SEG,ES
;
MOV AH,1
MOV DX,20 ; 20
CALL DWORD PTR CS:ADR_HIM_OFF
CMP AX, 1
.JNZ
NO OK

490

ASSEMBLER.

; 20
MOV , 3

CALL DWORD PTR CS:ADR_HIM_OFF


CMP AX, 1
JNZ NO_OK
JMP SHORT OK
NO_OK:
;
LEA DX,TEXT2
MOV AH,9
INT 21H
; .
MOV AH,2H
CALL DWORD PTR CS:ADR_HIM_OFF
; 20
MOV AH, 4
CALL DWORD PTR CS:ADR_HIM_OFF
JMP KON
OK:
; DATA 1MB
MOV AX,OFFFFH
MOV ES,AX
LEA SI,TEXT3
MOV DI,010H
LOO:
MOV AL, [SI]
MOV ES:[DI],AL
CMP AL,'$'
JZ
ALL
INC DI
INC SI
JMP SHORT LOO
ALL:
;
MOV DX, 010H
MOV AX,ES
MOV DS,AX
;DS:DX 1MB
MOV ,9
INT 21H
;
MOV BX,ES
MOV AH,2H
CALL DWORD PTR CS:ADR HIM OFF

22. , MS DOS

491

; 20
MOV

, 4

CALL DWORD PTR CS:ADR_HIM_OFF


KON:

MOV AH,4CH
INT 21H
ADR_HIM_OFF DW ?
ADR_HIM_SEG DW ?
CODE ENDS
END BEGIN
Puc. 22.4 .
. 22.4 ,
.
, Windows 95 ( 98)
, , MS DOS.

23. .
, .
.

. ,
. , . , MS DOS. , ( ) . .
, ,
. Windows. ( MS DOS) , ,
,
.
, , ,
.

I. .
4 , INTEL . ,
.
[15].
; TEST
.8086
EXTRN TO_386:FAR .
PUBLIC TEXT
PUBLIC TX_80386
PUBLIC TX_80486
PUBLIC TX_80586
PUBLIC VIRT
DATA SEGMENT PARA
;
TX_8088 DB ' 8088',13,10,'$'
_8086 DB ' 8086',13,10, ' $ '
TX_NEC20 DB ' NEC20',13,10,'$'
TX_NEC30 DB ' NEC30',13,10, ' $ '
_80188 DB ' 80188',13,10, ' $ '

23.

_80186 DB ' 80186',13,10,'$'


_8028 DB ' 80286',13,10,'$'
_80386 DB ' 80386',13,10,'$'
_80486 DB ' 80486',13,10,'$'
_ 80586 DB ' Pentium',13,10,'$'
VIRT DB ' .',13,10, '$ '
DATA ENDS
1
ST1 SEGMENT PARA STACK 'STACK
DW 50 DUP(?)
ST1 ENDS
CODE SEGMENT PARA PUBLIC
ASSUME CS:CODE, DS:DATA, SS:ST1
BEGIN:
MOV AX,DATA
MOV DS,AX
PUSH SP
POP AX
CMP SP,AX
JNZ BELOW_286
; 286
MOV AX,7000H
PUSH AX
POPF
PUSHF
POP AX
TEST AX,7000H
JNZ N0_286
;286-
LEA DX,TX_80286
CALL FAR PTR TEXT
JMP _END
N0_2 8 6:
JMP T0_386
; 8086,8088,80186,80188,NEC20,NEC30
BELOW_2 8 6:
CALL TBUFFER
MOV BP,CX
MOV CL,33
MOV AX,OFFFFH
SHL AX,CL
JZ
N0_186
CMP BP,0
JNZ
_188
LEA DX,TX 80186

493

494

ASSEMBLER.

CALL FAR PTR TEXT


JMP SHORT _END
_188:

LEA DX,TX_80188
CALL FAR PTR TEXT
JMP SHORT _END
N0_186:
MOV CX,OFFFFH
JMP SHORT $+2
DB OF3H,026H,OACH ;REP LODSB E:
JCXZ NEC
,-8088/8086
CMP BP,0
JNZ _88
LEA DX,TX_8086
CALL FAR PTR TEXT
JMP SHORT END
88:
LEA DX,TX_8088
CALL FAR PTR TEXT
JMP SHORT _END
NEC:
CMP BP,0
JNZ NEC20
LEA DX,TX_NEC30
CALL FAR PTR TEXT
JMP SHORT _END
NEC20;
LEA DX,TX_NEC20
CALL FAR PTR TEXT
END:
MOV AH,4CH
INT 21H
/
;
; - 0,
TBUFFER PROC NEAR
PUSH ES
PUSH DI
STD
PUSH CS
POP ES
LEA DI,CS:MET2
MOV AL,BYTE PTR CS:METl

23.

MOV ,3
CLI
REP STOSB

CLD
NOP
NOP
NOP
INC CX
1: STI
2:

STI

POP DI
POP ES
RETN
TBUFFER ENDP
TEXT PROC FAR

MOV AH,9
INT 21H
RETF
TEXT ENDP
CODE ENDS
END BEGIN
; TEST1
.386P
PUBLIC T0_386
EXTRN TEXT:FAR
EXTRN VIRT:BYTE
EXTRN TX_80386:BYTE
EXTRN TX_80486:BYTE
EXTRN TX_80586:BYTE
CODE1 SEGMENT PARA USE16
ASSUME CS:CODE1
T0_386:
MOV EAX,CRO
TEST AL,1
JZ NO_VIRT
LEA DX,VIRT
CALL
FAR PTR TEXT
NO_VIRT:
AND AX,1H1110001111111B
PUSH AX
. POPF
CALL M486_386
CMP A L , 0

495

496

ASSEMBLER.

JNZ
_48
LEA DX,TX_80386
CALL FAR PTR TEXT
JMP _END
_486:
; 486
CALL PENT_486
CMP AL,0
JNZ _PENT
LEA DX,TX_80486
CALL FAR PTR TEXT
JMP _END
_PENT:
;
LEA DX,TX_80586
CALL FAR PTR TEXT
_END:
MOV AH,4CH
INT 21H
/ 386- 486-
/ 18-
486_386 PROC
CLI
PUSHFD
POP
AND
,11111111111110111111111111111111
PUSH
POPFD
PUSHFD
POP
TEST ,00000000000001000000000000000000
JNZ N0_486
OR
,00000000000001000000000000000000
PUSH
POPFD
PUSHFD
POP
TEST ,00000000000001000000000000000000
JZ
N0_4 8 6
MOV AL,1
STI
RETN
N0_486:
MOV AL,0

23.

497

STI
RETN
48_386 ENDP
;, Pentium,
;
PENT_486 PROC
MOV AL,1
JMP $+2
;
MOV byte ptr $+6,Oc3h ; C3h <-> RET
NOP
NO_PENT:
MOV AL,0
; 80486
RETN
PENT_486 ENDP
CODE1 ENDS
END T0_386
Puc. 23.1. , .
. . ,
386- . TEST1.

Pentium'a. Pentium'a Intel
(. 4). ,
. 13.
.
1. : , 286- ( ), . , , 286- , -. ,
SP- PUSH .
PUSH SP. 286- SP
PUSH.
2. . : TBUFFER CL 0,
63
6 .
80186/80188. ,
186- 188-, .. 186- 6 .
64
3. - NEC.
LODSB. NEC30 NEC20 , NEC30 6 .
63
64

[15].
80186/80188
NEC.

498

ASSEMBLER.

4. : 8086
8088. : 8086 6 .
5. . 80286 , , ,
12,13,14 (. 20), .
6. 386-
CRO.
7. 486- 386- 18- .
8. Pentium .

II. .
7 (. 7.7) .
.

III. .
,
. , . , 486- ,
,
.
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
ORG 100H
BEGIN:
;
MOV TEST1,7890H
MOV TEST2,0

;
;
FILD TEST1
/
FIST TEST2
;
MOV AX,TEST1
CMP AX,TEST2
JZ
YES
;
LEA
DX,MES2
JMP SHORT _END
YES:

23.

499

;
LEA DX,MES1
_END:
MOV , 9
INT 21H
RET
/
TEST1 DW ?
TEST2 DW ?
MES1 DB ' .', 13,10,'$'
MES2 DB ' .', 13,10,'$'
CODE ENDS
END BEGIN
Puc. 23.2. .

IV. CMOS-.
AT (RTC Real-Time Clock) CMOS- (64 ).
. CMOS-
70, 71 . 70 ,
71 .
, " ".

( 1 - )

( )

RTC BCD ; ,
31 31 .

ASSEMBLER.

500

RTC -
3-0

6-4

L tc ( )

+22- ( 010)
>
d
" " ( U I P ) .
- .

RTC -
7 6 S 4 3 2 1 0

. 0= (. 0)
12 24- . 0=12- (. !)
. 1=, 0-BCD. (.)
1-. . , (. )
. , (. )
. .(. 0) INT 1
. .(. 0)
" " (1). - .

RTC - . .
:
0-3 - ,
4,5,6 - ( , . 9),
7 - (1).
, .
RTC - D. 7=1: CMOS-RAM
=0: .

POST

7 5 4 3 2
'

(1: 30- ..)


>

* . 1:
RAM . 1: POST RAH
. 1: .
+ 1: CMOS RAH .
<

. 1:

OFH
CPU, ,
80286.
0 = (CTRL-ALT-DEL) ( ). POST
1 =

501

23.

2 =
3 = ( 1 2)
4 =
5 - FAR JMP ( . JMP 0:[0467])
6,7,8 =
9 = . . INT 15 . 87
= FAR JMP ( JMP 0:[0467])

-
3--0

7-4

0000 = = .
0001 = 1 =
0010 = 2 = 1.2

11
12 ( : D:, 1
7-4

1111

3-0

L
!
(. :)
(. D : )
=..19/1

0000 =.
=10 ()

. AT BIOS , BIOS.
1
14
7-6

5-4

3-2

! = - .
1 = 80287
00 = _EGA_
01 = 40- CGA
10 = 80- CGA
11 = TTL MONOCHROME
11 = TTL MOHOCHROHE
- 1 (00=1, 01=2, 10=3, 11=4)

15 () > 0100=256, 0200=512, 0280=640


16 ()
17 1 ()
>( -. 0-)
18 ()
> . INT 15 . 88
19 0 (. :) , (CMOS ADDR 12H & OFH) = OFH
1 1 (. D:) , (CMOS ADDR 12H & FOH) = FOH
1BH-2DH
2EH , CMOS 10H..2DH ( )
2FH ( )
1 () > ( -. 0-)

502

ASSEMBLER.

31 ()
> . INT 15H . 88
32 BCD (, 19)
. 7=IBM 128K
6= "SETUP" 34H-3FH .
CMOS. , 10-20.
10H-2DH. 212DH .
. 23.3 AT.
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
ORG 100H
BEGIN:
; DX
MOV AL,2EH
OUT 70H,AL
JMP $+2
IN AL,71H
MOV DH,AL
MOV AL,2FH
OUT 70H,AL
JMP $+2
IN AL,71H
MOV DL,AL
MOV SI,DX ; SI
;
MOV CX,30 /
MOV BL,10H ;
XOR DX,DX
;
XOR ,
LOO:
MOV AL,BL
OUT
70H,AL
JMP $+2
IN
AL,71H
ADD DX,AX
INC BL
LOOP LOO
;
CMP DX,SI
JZ
YES
LEA DX,MES2
JMP SHORT END

23.

503

YES:
LEA

DX,MES1

MOV
INT
RET

AH,9
21H

_END:

/
MES1 DB ' CMOS .', 13,10,'$'
MES2 DB ' .', 13,10,'$'
CODE ENDS
END BEGIN

. 23.3. CMOS.

V. .
, .
, 9.
. , 9. .
CODE SEGMENT
ASSUME CS:CODE,
ORG 100H
BEGIN:

DSrCODE

CLI

CALL WAIT_OUT_BUF / ?
CALL WAIT_IN_BUF
/ ?
/
MOV AL,20H
OUT 64H,AL
CALL WAIT_IN_BUF
/ ?
CALL WAITJDUT
/ ?
. IN
AL,60H
/
MOV _AL,AL
;,

/.**********************

/,
CALL WAIT_OUT_BUF
/ ?
CALL WAIT_IN_BUF
/ ?
/
MOV AL,OAAH
OUT
64H,AL

504

ASSEMBLER.

CALL WAIT_OUT
; ?
IN
AL,60H
MOV _TEST_K,AL
/
CALL WAIT_IN_BUF
MOV AL,60H
OUT 64H,AL
/
CALL WAIT_IN_BUF
MOV AL,_AL
OUT 60H,AL
;
CMP _TEST_K,55H
JNZ
ERR1
; ''
CALL WAIT_IN_BUF
MOV AL,OEEH
OUT
60H,AL
CALL WAIT_OUT
IN
AL,60H
CMP AL,OEEH
JNZ ERR2
/ ()
CALL WAIT_IN_BUF
MOV AL,OFFH
OUT 60H,AL
CALL WAIT_OUT
IN
AL,60H
CMP AL,OFAH
?
JNZ ERR2
CALL WAIT OUT
IN
AL,60H
CMP AL,OAAH ; ?
JNZ ERR2
JMP
END
ERR1:
STI
POP AX
LEA DX,MES_1
MOV AH, 9
INT 21H
MOV ,4
MOV AL,2
INT 21H
ERR2;
STI
POP AX
LEA DX,MES 2

23.

MOV
INT
MOV
MOV
INT

,9
21H
,4
AL,3
21H

ERR:
STI
POP AX
LEA DX,MES_0
MOV A H , 9
. I N T 21H
MOV AH,4CH
MOV AL,1
INT 21H

_END:
STI
LEA DX,MES
MOV A H , 9
INT 21H
MOV AH,4CH
MOV A L , 0
INT 21H
;,
WAIT_IN_BUF PROC
XOR CX,CX
Tl:
IN A L , 6 4 H
TEST A L , 2
LOOPNZ Tl
JNZ ERR
RETN
WAIT_IN_BUF ENDP
;,
WAIT_OUT_BUF PROC
XOR CX,CX
T2:
IN A L , 6 4 H
TEST AL,1
LOOPNZ T2
JNZ ERR
RETN
WAIT_OUT_BUF ENDP
;,
WAIT_OUT PROC
:
IN A L , 6 4 H
TEST A L , 1

505

506

ASSEMBLER,

JZ
RETN
WAIT_OUT ENDP
_AL DB ?
_TEST_K DB ?
MES_0 DB ' !',13,10,'$'
MES_1
DB ' !',13,10,'$'
MES_2
DB ' !',13,10,'$'
MES DB ' !', 13,10, '$'
CODE ENDS
END BEGIN
. 23.4. .

VI. .
MS DOS
( XT ). , 08.
. . ,
, . . ,
.
.286

CODE SEGMENT
ASSUME CS:CODE, DS:CODE
ORG 100H
BEGIN:
;ES -
MOV ,800
MOV ES,AX
;
MOV CX,4000
XOR SI,SI
_CLS:
MOV ES:[SI],0700H
ADD SI,2
LOOP _CLS
MOV CX,23
/ 1
LEA SI,TEXT1
MOV DI,2000-80

23.

_1:
MOV AL, [SI]
MOV E S : [ D I ] , A L
INC SI
ADD DI,2

LOOP _TEX1
MOV CX,23
LEA SI,TEXT2
MOV 01,2320-80
_TEX2:
; 2
MOV AL, [SI]
MOV E S : [ D I ] , A L
INC SI
ADD DI,2
LOOP _TEX2
LOOP1:
/
MOV ,
INT 1AH
/
CALL _COUNT
;
MOV 01,2320
CALL PRINT
;
MOV ,2
INT 1AH
/ BCD
CALL _BCD
;
MOV 01,2000
CALL PRINT
/,
MOV , 1
INT 16H
JZ LOOP1
;
MOV ,

MOV DL,OFFH
INT 21H
;
RETN

507

508

ASSEMBLER.

;
PRINT PROC
MOV CX,8
LEA SI,SHABL
LOO1:
MOV AL,[SI]
MOV ES:[DI],AL
MOV BYTE PTR ES:[DI]+1,12
INC SI
ADD DI,2
LOOP LO01
RETN
PRINT ENDP
/ BCD-
/
_BCD PROC
/
MOV AL,CH
SHR AL,4
ADD AL,48
AND CH,00001111B
CMP ,
JB _OK1
ADD AL,1
SUB CH,10
_OK1:
ADD CH,48
MOV BYTE PTR SHABL,AL
MOV BYTE PTR SHABL+1,CH
;
MOV AL,CL
SHR AL,4
ADD AL,48
AND CL,00001111B
CMP CL,10
JB _OK2
ADD AL,1
SUB CL,10
_OK2:
ADD CL,48
MOV BYTE PTR SHABL+3,AL
MOV BYTE PTR SHABL+4,CL
;
MOV AL,DH
SHR AL,4

23.

ADD
AND
CMP
JB
. ADD
SUB

AL,48
DH,00001111
DH,10
_OK3
AL,1
DH,10

_OK3 :

ADD DH,48
MOV BYTE PTR SHABL+6,AL
MOV BYTE PTR SHABL+7,DH
RETN
_BCD ENDP
;
;
_COUNT PROC
MOV AX,DX
MOV DX,CX
MOV CX,65520
DIV CX
/
PUSH DX
MOV CL,10
DIV CL
ADD AL,48
ADD AH,48
MOV BYTE PTR SHABL,AL
MOV BYTE PTR SHABL+1,AH
POP AX
XOR DX,DX
MOV CX,1092
DIV CX
;
PUSH DX
MOV CL,10
DIV CL
ADD AL,48
ADD AH,48
MOV BYTE PTR SHABL+3,AL
MOV BYTE PTR SHABL+4,AH
POP AX
XOR DX,DX
MOV CX,18
DIV CX
/
MOV CL,10
DIV CL
ADD AL,48

509

510

ASSEMBLER.

ADD ,48
MOV BYTE PTR SHABL+6,AL
MOV BYTE PTR SHABL+7,AH
RETN
_COUNT ENDP
;
SHABL DB 48,48, ':',48,48, ':',48,48
TEXT1 DB ' :'
TEXT2 DB ' :
'
CODE ENDS
END BEGIN
Puc. 23.5. .

1 (. 8).
BCD- .

24.
WINDOWS.
...

..
- .
. , . - .
, .
, , WINDOWS. .
,
WINDOWS . WINDOWS. .
, WINDOWS
. , , , - , . , , , WINDOWS
,
( API - APLICATION PROGRAMM INTERFACE). . , WINDOWS , .
, 15.
, , -
. . , WINDOWS, MS DOS. , WINDOWS . , MS DOS ,
. ? , . . , , . , . , . ,
, , .
.
: "
,
". ? , ,
. , !

512

ASSEMBLER.

I. .
, , , . .
1. WINDOWS API (APPLICATION PROGRAM INTERFACE).
. .
2. API .
, .
3. () WINDOWS ''.
. '' , .
4. (,
.). ( ) .
, , , , .
5. WINDOWS 95-98 WINDOWS 3.1. :
- WINDOWS 95 32- ,
, API-
,
- WINDOWS 95 , ,
- WINDOWS 95 (), ( ), (Thread),
,
- WINDOWS 95 ,
, ,
- WINDOWS 95
, , MS DOS,
- WINDOWS 95 ,
WINDOWS 3,1 ,
- WINDOWS 95 , .
32- ( 25),
.

. API-.
MS DOS,
-. -

24. WINDOWS

513

, .. . WINDOWS API-. , , .
, ,
WINDOWS, ,
. : LIBW.LIB. 14 (-), WINDOWS. ,
. , .
LIB W
LINK,
WINDOWS. (. . 24.1),
. . INITTASK , .
DOSSEG, DGOUP, INl'1'l'ASK .
. . ,
MICROSOFT 6.1
5.0. :
ML - PROG.ASM;
LINK PROG.OBJ

65

LIBW. :
LINK PROG,PROG,,LIBW;
LINK.EXE 5.0:
LINK OBJFILE,EXEFILE,MAPFILE,LIBFILE,DEFFILE;
.
.DOSSEG

DGROUP GROUP
DATA, STA
ASSUME CS:CODE, DS:DGROUP
EXTRN INITTASK:FAR
EXTRN DOS3CALL:FAR
;
STA SEGMENT STACK 'STACK'
DW 2000 DUP(?)
STA ENDS

65

Windows, system.ini
[386Enh] device=\nyrb\DOSXNT.386.

17-4072

514

ASSEMBLER.

;
DATA SEGMENT WORD
DATA ENDS

'DATA'

;
.CODE SEGMENT WORD
'CODE1
_BEGIN:
;
PUSH AX
CALL INITTASK
;
MOV AH,4CH
CALL DOS3CALL
; INT 21H
CODE ENDS
END _BEGIN
. 24.1. .
, 16-
Windows. Windows 95-98, Windows
3.1, , , .
API , , .
1. API ( HELPER). API -.
2. ,
. "" . ( ) (
) .
3. , , - . , ( ).
4. 15 , ,
, . API ,
API .
.
, . :
. ,
. (
, ). :
BOOL GETMESSAGE(LPMSG,

HWND,

UMSGFILTERMIN,

UMSGFILTERMAX)

BOOL. , - . . ,
0 - , ( 1) - . ,

24. WINDOWS

515

( ) . . :
LPMSG - MSG (
),
HWND - WORD,
UMSGFILTERMIN - WORD,
UMSGFILTERMAX - WORD.
.
.
, MES. :
PUSH DS
;
LEA AX,MES
;
PUSH AX
/
PUSH
PUSH
PUSH
CALL GETMESSAGE
CMP AX,0 ; ?

JZ _1
. , ,
, , .. . :
LONG DISPATCHMESSAGE(LPMSG);
CONST MSG FAR* LPMSG;
(. ). LONG. , DX:AX ( 15). ,
. , , MSG, . :
PUSH DS
LEA AX,MSG
PUSH AX
CALL
DISPATCHMESSAGE
.
1. . -
.
2. , ,
, .

17'

516

ASSEMBLER.

, , , . WINDOWS -
. MESSA.
MESSA
HWND
MESSAGE
WPARAM
LPARAM
TIME

STRUCT
DW
DW
DW
DD
DD

?
?
?
?
?

DW
DW

X
Y
MESSA

?
?

ENDS

( ), , , .
:
MSG

MESSA

.
TYPEDEF STRUCT TAGMSG {
HWND
HWND;
UINT
MESSAGE;
WPARAM WPARAM;
LPARAM LPARAM;
DWORD TIME;
POINT
PT;
} MSG;

/* MSG */

PT - , X, Y. ,
HWND, UINT, WOARAM, WORD. , , .
.
WNDCLASS
STYLE

DW ?

STRUCT

LPFNWNDPROC
CBCLSEXTRA
CBWNDEXTRA
HINSTANCE
HICON
HCURSOR

DD
DW
DW
DW
DW
DW

?
?
?
?
?
?

517

24. WINDOWS

HBRBACKGROUND
LPSZMENUNAME
LPSZCLASSNAME
WNDCLASS

DW ?
DD ?
DD ?
ENDS

/
;

. -

:
TYPEDEF STRUCT TAGWNDCLASS {
STYLE;
UINT
WNDPROC
LPFNWNDPROC;
INT
CBCLSEXTRA;
INT
CBWNDEXTRA;
HINSTANCE HINSTANCE;
HI CON
HICON;
HCURSOR
HCURSOR;
HBRUSH
HBRBACKGROUND;
LPCSTR
LPSZMENUNAME;
LPCSTR
LPSZCLASSNAME;
} WNDCLASS;

/* WC */

III. .
, . SMALL - . .
. 24.2 .
a API
WINDOWS


ISSaum.

xoga

r>f*nf9*tf*rrrf*If9

Koucmaumft

tl



oSpaSoMKU

. 24.2. .

518

ASSEMBLER.

.
1. . API. , , .
. :
INITTASK - , . . . : = 1
( - ), - , DI - , DX - NCMDSHOW (. ), ES - () PSP, ES:BX -
, SI - . WINDOWS 3.1 ,
, .
. WINDOWS 95 . . WINDOWS 95 SI
0. ,
.
INITAPP - . :
PUSH DI
CALL INITAPP

0, .
WAITEVENT - . , .
PUSH

; - , 0 .

CALL WAITEVENT

, .
CALL INITTASK
'
/
OR AX,AX
; -
JZ TO_OS
MOV HPREV,SI
; .
MOV HINST,DI
;
MOV WORD PTR LPSZCMD,BX
;ES:BX -
MOV WORD PTR LPSZCMD+2,ES ;
MOV CMDSHOW,DX
/
PUSH 0
;
CALL WAITEVENT
/
PUSH HINST
CALL INITAPP
/
OR AX,AX
JZ TO OS

24. WINDOWS

CALL MAIN
_TO_OS:
MOV AH,4CH
CALL DOS3CALL

519

, .
.
EXTRN
EXTRN
EXTRN
EXTRN

INITTASK:FAR
INITAPP:FAR
WAITEVENT:FAR
DOS3CALL:FAR

2. . ,
, . - . . . -
. , ,
. , , .
. , ,
, CTRL+ALT+DEL, .
LEA DI,WNDCLASS
; STYLE
MOV
AX, STYLE
MOV
WNDCLASS.STYLE, AX ; .
;
MOV
BX,OFFSET WNDPROC
MOV
WORD PTR WNDCLASS.LPFNWNDPROC, BX
MOV
BX,SEG WNDPROC
MOV
WORD PTR WNDCLASS.LPFNWNDPROC+2, BX
XOR
AX,AX
;
MOV
WNDCLASS.CBCLSEXTRA,
;
MOV
WNDCLASS.CBWNDEXTRA,
/
MOV
WNDCLASS.HICON,
;
MOV
AX,HINST
MOV
WNDCLASS.HINSTANCE,
;
PUSH

ASSEMBLER.

520

PUSH
DS
PUSH
CURSOR
CALL
LOADCURSOR
MOV
WNDCLASS.HCURSOR, AX
;
PUSH
0
;WHITE_BRUSH
CALL
GETSTOCKOBJECT
;
MOV
WNDCLASS.HBRBACKGROUND, AX
; ( = NULL)
XOR
,
MOV
MOV

WORD PTR WNDCLASS.LPSZMENUNAME,AX


WORD PTR WNDCLASS.LPSZMENUNAME+2,AX

/ ,
MOV
MOV

BX,OFFSET CLAS_NAME
WORD PTR WNDCLASS.LPSZCLASSNAME,BX

MOV

WORD PTR WNDCLASS.LPSZCLASSNAME+2,DS

;
PUSH DS
/
PUSH DI
; WNDCLASS
CALL REGISTERCLASS
, WNDCLASS . ,
. ,
, . .
API CREATEWINDOW CREATEWINDOWEX. ( ) . . - :
HWND CREATEWINDOWEX(DWEXSTYLE,
DWSTYLE, X, Y, NWIDTH, NHEIGHT,
LPVCREATEPARAMS)

LPSZCLASSNAME,
LPSZWINDOWNAME,
HWNDPARENT, HMENU, HINST,

, ,
. :
;
MOV
BX,HIGHWORD EX_STYLE
PUSH BX
MOV
BX,LOWWORD EX_STYLE
PUSH BX

24. WINDOWS

521

; -
PUSH DS
LEA

BX,RNAME

PUSH BX
; -
PUSH DS
LEA BX,SZAPPNAME
PUSH BX
;
MOV BX,HIGHWORD STYLE
PUSH BX
MOV BX,LOWWORD STYLE
PUSH BX
;
PUSH XSTART
/ Y
PUSH YSTART
;
PUSH DXCLIENT
;
PUSH DYCLIENT
; -
PUSH
; ()
PUSH
;
PUSH HINST
; ()
PUSH
PUSH
CALL

CREATEWINDOWEX

, , . , , MS DOS. , WINDOWS DOS . , CALL DOS3CALL INT


21. . ,
, ( ) WINDOWS, .
3. . , .
LOOP1:

;
PUSH DS
LEA BX,MSG ;
PUSH BX
;

522

ASSEMBLER.

PUSH
PUSH
PUSH
CALL GETMESSAGE
; - ""
,
JZ
NO_LOOP1
/ ANSI
PUSH DS
LEA BX,MSG
PUSH BX
CALL TRANSLATEMESSAGE
/ WINDOWS

PUSH DS
LEA BX,MSG
PUSH BX
CALL
DISPATCHMESSAGE
; ()
JMP SHORT LOOP1
4. " ". . . , , ,
. , , . 11,13,15,
. , :
VOID FUN_WIND(UNSIGNED INT HWND,
LONG LPARAM).

UNSIGNED INT MES,

INT WPARAM,

He :
FUN_WIND PROC
PUSH
MOV ,SP

MOV AX,[BP+OEH]
MOV AX,[BP+OCH]
MOV ,[+]
MOV AX, [BP+8]
MOV AX,[BP+6]

;HWND -
;MES -
;WPARAM -
; LPARAM
/ LPARAM

24. WINDOWS

523

POP

RET 10

FUN_WIND ENDP

, .
WINDOWS. , ,
, .

IV. .
(. 23.4).
: , , , .
( , , ..) - :
WINDOWS.H, WIN.INC , . , : OOOCFOOOOH.
:
OOOCFOOOOH - WS_OVERLAPPEDWINDOW - :
1) - ,
2) - ,
3) - ( ),
4) - ,
5) - .
Borland ,
. , 4- . .286, , 16- .

.286
.DOSSEG

DGROUP GROUP

DATA, STA
ASSUME CS:CODE, DS:DGROUP
;
EXTRN INITTASK:FAR
EXTRN INITAPP:FAR
EXTRN WAITEVENT:FAR
EXTRN DOS3CALL:FAR
.EXTRN REGISTERCLASSrFAR
EXTRN LOADCURSOR:FAR
EXTRN GETSTOCKOBJECT:FAR
EXTRN GETMESSAGE:FAR
EXTRN TRANSLATEMESSAGE:FAR
EXTRN DISPATCHMESSAGE:FAR
EXTRN CREATEWINDOW:FAR

524

ASSEMBLER.

EXTRN CREATEWINDOWEX:FAR
EXTRN UPDATEWINDOW:FAR
EXTRN SHOWWINDOW:FAR
EXTRN POSTQUITMESSAGE:FAR
EXTRN DEFWINDOWPROC:FAR
/
STRUCT
WNDCL
STYLE
DW 0 /
LPFNWNDPROC
DD 0
/
CBCLSEXTRA
DW
CBWNDEXTRA
DW
HINSTANCE
DW
DW
HICON
HCURSOR
DW
DW
HBRBACKGROUND
LPSZMENUNAME
DD /
DD /
LPSZCLASSNAME
WNDCL
ENDS
STRUCT
MESSA
HWND
DW
MESSAGE
DW
DW
WPARAM
DD
LPARAM
TIME
DW
X
DW
Y
DW
MESSA
ENDS
;
STA SEGMENT STACK 'STACK'
DW 2000 DUP(?)
STA ENDS
;
DATA SEGMENT WORD 'DATA'
/ 16 - , 16-
/ Windows
DWORD
WORD
5
WORD
5 DUP (0)
HPREV
DW ?
HINST
DW ?
LPSZCMD DD ?
CMDSHOW DW ?
/
WNDCLASS WNDCL <>

24. WINDOWS

525

;
MSG MESSA
/
CLAS_NAME DB 'PRIVET',
;
APP_NAME DB 'FIRST PROGRAM.', 0
;
CURSOR EQU 00007FOOH
;
STYLE EQU OOOCFOOOOH
;
XSTART DW 100
YSTART DW 100
DXCLIENT DW 300
DYCLIENT DW 200
DATA ENDS
;
CODE SEGMENT WORD
'CODE1
_BEGIN:
; I.
CALL INITTASK
;
OR AX,AX
;CX -
JZ _ERR
MOV HPREV,SI
/ .
MOV HINST,DI
;
MOV WORD PTR LPSZCMD,BX
;ES:BX -

MOV WORD PTR LPSZCMD+2,ES ;


MOV CMDSHOW,DX
;
PUSH 0
;
CALL WAITEVENT
,-
PUSH HINST
CALL INITAPP
/
OR AX,AX
JZ _ERR
CALL MAIN
;
_TO_OS:
. '
MOV AH,4CH
CALL DOS3CALL
;
_ERR:
CALL BEEP
JMP SHORT _TO_OS
/
.****************************************************

526

ASSEMBLER.

MAIN PROC
/II. -
; NULL -
MOV
WNDCLASS.STYLE,
;
LEA
BX,WNDPROC
MOV
WORD PTR WNDCLASS.LPFNWNDPROC, BX
MOV
BX,CS
MOV
WORD PTR WNDCLASS.LPFNWNDPROC+2,BX
;
MOV
WNDCLASS.CBCLSEXTRA,
;
MOV
WNDCLASS.CBWNDEXTRA,
/
MOV
WNDCLAS S.ICON,
/
MOV
AX,HINST
MOV
WNDCLASS.HINSTANCE,AX
;
PUSH

PUSH
DS
PUSH
CURSOR
CALL
LOADCURSOR
MOV
WNDCLASS.HCURSOR, AX
/
PUSH
0
/WHITEJ3RUSH
CALL
GETSTOCKOBJECT
;
MOV
WNDCLASS.HBRBACKGROUND, AX
/ ( = NULL)
MOV
WORD PTR WNDCLASS.LPSZMENUNAME,
MOV
WORD PTR WNDCLASS.LPSZMENUNAME+2, 0
/ ,
LEA
BX,CLAS_NAME
MOV
WORD PTR WNDCLASS.LPSZCLASSNAME, BX
MOV
WORD PTR WNDCLASS.LPSZCLASSNAME+2, DS
/
PUSH DS
/
LEA DI,WNDCLASS
PUSH DI
/ WNDCLASS
CALL REGISTERCLASS
CMP AX,0
JNZ OKI

24. WINDOWS

;
CALL BEEP
RET
;
_1:
/III.
; -
PUSH DS
LEA BX,CLAS_NAME
PUSH BX
; -
PUSH DS
LEA BX,APP_NAME
PUSH BX
;
MOV BX,HIGHWORD STYLE
PUSH BX
MOV BX,LOWWORD STYLE
PUSH BX
;
PUSH XSTART
; Y
PUSH YSTART
;
PUSH DXCLIENT
;
PUSH DYCLIENT
; -
PUSH
; ()
PUSH /NULL
;
PUSH HINST
; ()
PUSH
PUSH
CALL CREATEWINDOW
CMP AX,0
JNZ NO_NULL
CALL BEEP
RET
;

527

528

ASSEMBLER.

/ (
/) CMDSHOW
NO_NULL:
MOV SI,AX
PUSH SI
PUSH CMDSHOW
CALL SHOWWINDOW
; ( WM_PAINT)
;
PUSH SI
CALL UPDATEWINDOW
;IV.
LOOP1:
/
PUSH DS
LEA BX,MSG ;
PUSH BX
;
PUSH
PUSH
PUSH
CALL GETMESSAGE
; - ""
,
JZ NO_LOOP1
; ANSI
PUSH DS
LEA BX,MSG
PUSH BX
CALL TRANSLATEMESSAGE
/ WINDOWS

PUSH DS
LEA BX,MSG
PUSH BX
CALL DISPATCHMESSAGE
; ()
JMP SHORT LOOP1
NO_LOOP1:
RET
MAIN ENDP
/
/WINDOWS :
/HWND - () , WORD
/MES - , WORD

24. WINDOWS

529

;WPARAM - , WORD
;LPARAM - , DWORD
WNDPROC PROC
PUSH
MOV BP,SP
MOV AX, [BP+OCH]
;MES -
CMP AX, 2 ; (2-
)
JNZ NEXT
; ,
/ , ..

PUSH
CALL POSTQUITMESSAGE
JMP _QUIT
NEXT:
; WINDOWS
/ - ,
; ,
/WINDOWS
PUSH [BP+OEH]
;HWND
PUSH [BP+OCH]
;MES -
PUSH [BP+OAH]
;WPARAM
PUSH [BP+8]
,-HIGHWORD LPARAM
PUSH [BP+6]
;LOWWORD LPARAM
CALL DEFWINDOWPROC
/

_QUIT:

POP BP
; , RETF
RETF 10
/
WNDPROC ENDP
'
;
PROC
MOV , 2
MOV DL,7
CALL DOS3CALL ;INT 21H
RET
BEEP ENDP
CODE ENDS
END _BEGIN
Puc. 24.3. , .

530

ASSEMBLER.

V. .
. , - . ! ( ) (, ). , , ,
.
, , .
, LPARAM
WPARAM. , ! " "
, - . , .
.286
.DOSSEG
DGROUP GROUP
DATA, STA
ASSUME CS.-CODE, DS: DGROUP
;
EXTRN INITTASK:FAR
EXTRN INITAPP:FAR
EXTRN WAI VENT: FAR
EXTRN DOS3CALL:FAR
EXTRN REGISTERCLASS:FAR
EXTRN LOADCURSOR:FAR
EXTRN GETSTOCKOBJECT:FAR
EXTRN GETMESSAGE:FAR
EXTRN TRANSLATEMESSAGE:FAR
EXTRN DIS PATCHME S SAGE:FAR
EXTRN CREATEWINDOW:FAR
EXTRN CREATEWINDOWEX:FAR
EXTRN UPDATEWINDOW:FAR
EXTRN SHOWWINDOW:FAR
EXTRN POSTQUITMESSAGE:FAR
EXTRN DEFWINDOWPROC:FAR
/
WNDCL
STRUCT
STYLE
DW 0
;

LPFNWNDPROC
CBCLSEXTRA
CBWNDEXTRA
HINSTANCE
HICON
HCURSOR
HBRBACKGROUND
LPSZMENUNAME
LPSZCLASSNAME

DD 0
DW
DW
DW
DW
DW
DW
DD 0
DD 0

;
;

24. WINDOWS
WNDCL
ENDS
MESS A
STRUCT
DW 7
HWND
MESSAGE
DW 7
WPARAM
DW 7
LPARAM
DD 9
DW 7
TIME
DW 7
X
. DW 7
Y
MESSA
ENDS
;
STA SEGMENT STACK 'STACK1
DW 2000 DUP(?)
STA ENDS
;
DATA SEGMENT WORD 'DATA'
;16 -
DWORD 0
WORD
5
WORD
5 DUP (0)
HPREV
DW ?
HINST
DW ?
LPSZCMD DD ?
CMDSHOW DW ?
;
WNDCLASS WNDCL <>
;
MSG MESSA
;
CLAS_NAME DB 'PRIVET',
;
PRED_CLAS DB 'BUTTON',
;
APP_NAME DB 0 ;
;
BUT_NAME DB 'QUIT',0
;
CURSOR EQU 00007FOOH
;
STYLE EQU
080000000H OR 000400000H
;
STYLE_BUT EQU 040000000H OR 010000000H
;
XSTART DW 100
YSTART DW 100
DXCLIENT DW 300

531

552

ASSEMBLER.

DYCLIENT DW 200
DATA ENDS

;
CODE SEGMENT WORD
CODE'
_BEGIN:
;
/
CALL INITTASK
OR AX,AX
;CX -
JZ _ERR

MOV HPREV,SI
; .
MOV HINST,DI
;
MOV WORD PTR LPSZCMD,BX
;ES:BX -

MOV WORD PTR LPSZCMD+2,ES


MOV CMDSHOW,DX
;
PUSH 0
;
CALL WAITEVENT
;
PUSH HINST
CALL INITAPP
;
OR AX,AX
JZ _ERR
CALL MAIN
;
_TO_OS :
MOV AH,4CH
CALL DOS3CALL

_ERR:
CALL BEEP
JMP SHORT _TO_OS
;
t.****************************************************
MAIN PROC
;
; NULL -
MOV
WNDCLASS.STYLE,
;
LEA
BX,WNDPROC
MOV
WORD PTR WNDCLASS.LPFNWNDPROC, BX
MOV
BX,CS
MOV
WORD PTR WNDCLASS.LPFNWNDPROC+2, BX
;
MOV
WNDCLASS.CBCLSEXTRA,
;
MOV
WNDCLASS.CBWNDEXTRA,

24. WINDOWS

MOV

WNDCLASS.HICON,

;
MOV
AX,HINST
MOV
WNDCLASS.HINSTANCE,AX
;
PUSH

PUSH
DS
PUSH
CURSOR
CALL
LOADCURSOR
MOV
WNDCLASS.HCURSOR, AX
;
PUSH
0
;WHITE_BRUSH
CALL
GETSTOCKOBJECT
;
MOV
WNDCLASS.HBRBACKGROUND, AX
; ( = NULL)
MOV
WORD PTR WNDCLASS.LPSZMENUNAME,
MOV
WORD PTR WNDCLASS.LPSZMENUNAME+2, 0
; ,
LEA
BX,CLAS_NAME
MOV
WORD PTR WNDCLASS.LPSZCLASSNAME,BX
MOV
WORD PTR WNDCLASS.LPSZCLASSNAME+2, DS
;
PUSH DS
/
LEA DI,WNDCLASS
PUSH DI
/ WNDCLASS
CALL REGISTERCLASS
CMP AX,0
JNZ _OK1
;
CALL BEEP
RET
;
_1:
;
; -
PUSH DS
LEA BX,CLAS_NAME
PUSH BX
/ -
PUSH DS
LEA BX,APP_NAME
PUSH BX
/
MOV BX,HIGHWORD STYLE
PUSH BX

533

534

ASSEMBLER.

MOV BX,LOWWORD STYLE


PUSH BX
;
PUSH XSTART
; Y
PUSH YSTART
;
PUSH DXCLIENT
;
PUSH DYCLIENT
; -
PUSH
; ()
PUSH
;
PUSH HINST
; ()
PUSH
PUSH
CALL CREATEWINDOW
CMP AX,0
JNZ NO_NULL
CALL BEEP
RET
/
; (
;) CMDSHOW
NO_NULL:
MOV SI,AX
PUSH SI
PUSH CMDSHOW
CALL SHOWWINDOW
/ ( WM_PAINT)
;
PUSH SI
CALL UPDATEWINDOW
;
LOOP1:
;
PUSH DS
LEA BX,MSG . ;
PUSH BX
;
PUSH
PUSH
PUSH
CALL GETMESSAGE

14. WINDOWS

535

; - ""
,
JZ NO_LOOP1
/ ANSI
PUSH DS
LEA BX,MSG
PUSH BX
CALL TRANSLATEMESSAGE
; WINDOWS
;
PUSH DS
LEA BX,MSG
PUSH BX
CALL
DISPATCHMESSAGE
; ()
JMP SHORT LOOP1
NO_LOOP1:
RET
MAIN ENDP
;
;WINDOWS :
;HWND - () , WORD
;MES - , WORD
;WPARAM - , WORD
;LPARAM - , DWORD
WNDPROC PROC
PUSH
MOV BP,SP
MOV AX,[BP+OCH]
;MES -
CMP AX,2 ; (2 -
)
JNZ NEXT1
/ ,
; , ..
;
PUSH
CALL POSTQUITMESSAGE
JMP _QUIT
NEXT1:
CMP AX, 1
;WM_CREATE
JNZ NEXT2
;
; -
PUSH DS
LEA BX,PRED_CLAS
PUSH BX

536

ASSEMBLER.

; -
PUSH DS

LEA BX,BUT_NAME
PUSH BX
;
MOV BX,HIGHWORD STYLE_BUT
PUSH BX
MOV BX,LOWWORD STYLE_BUT
PUSH BX
,-
PUSH 20
;
PUSH 20
;
PUSH 60
;
PUSH 20
; -
PUSH [BP+OEH]
; ()
PUSH 1
;
PUSH HINST
; ()
PUSH
PUSH
CALL CREATEWINDOW
NEXT2:
CMP AX,111H
;WM_COMMAND
JNZ NEXT
CMP WORD PTR [BP+OAH],! /
JNZ NEXT
;
PUSH
CALL POSTQUITMESSAGE
NEXT:
; WINDOWS
; - ,
/
/WINDOWS
PUSH [BP+OEH]
;HWND
PUSH [BP+OCH]
;MES -
PUSH [BP+OAH]
;WPARAM
PUSH [BP+8]
,-HIGHWORD LPARAM

24. WINDOWS

537

PUSH [+]
;LOWWORD LPARAM
CALL DEFWINDOWPROC
_QUIT:

POP BP
/ , RETF
RETF 10
/
WNDPROC ENDP
; .
PROC
MOV ,2
MOV DL,7
CALL DOS3CALL
RET
ENDP
CODE ENDS
END _BEGIN
Puc. 24.4. .
. 24.3, -,
, -, - . , :
1. , ,
;
2. WM_CREATE,
;
3. , , ;
4. (1);
5. opxoypoeypyoaax)eWMJCOMMANDIpoe\VPARAM,
, .. 1.
, , , .
- DOS- ,
. .
: - ,
WINDOWS, , ++, .

VI. -.
, , , : ::. , WINDOS. , MS DOS ( ), . ,
, .

538

.286
.DOSSEG
DGROUP GROUP
DATA, STA
ASSUME CS:CODE, DS:DGROUP
;
EXTRN CREATEFONTINDIRECT:FAR
EXTRN SELECTOBJECT:FAR
EXTRN DELETEOBJECT:FAR
EXTRN INVALIDATERECT:FAR
EXTRN BEGINPAINT:FAR
EXTRN ENDPAINTrFAR
EXTRN TEXTOUT:FAR
EXTRN SETTIMER:FAR
EXTRN INITTASK:FAR
EXTRN INITAPP:FAR
EXTRN WAITEVENT:FAR
EXTRN DOS3CALL:FAR
EXTRN REGISTERCLASS:FAR
EXTRN LOADCURSOR:FAR
EXTRN GETSTOCKOBJECT:FAR
EXTRN GETMESSAGErFAR
EXTRN TRANSLATEMESSAGE:FAR
EXTRN DISPATCHMESSAGE:FAR
EXTRN CREATEWINDOWEX:FAR
EXTRN UPDATEWINDOW:FAR
EXTRN SHOWWINDOW:FAR
EXTRN POSTQUITMESSAGE:FAR
EXTRN DEFWINDOWPROC:FAR
/
/
LOGFON
STRUCT
_HEIGHT
DW
0
_WIDTH
DW
0
_ESCAPEMENT
DW
0
_ORIENTATION
DW
0
_WEIGHT
DW
0
_ITALIC
DB
0
_UNDERLINE
DB
0
_STRIKEOUT
DB
0
_CHARSET
DB
0
_OUTPRECISION
DB
0
_CLIPPRECISION
DB
0
QUALITY
DB
0

ASSEMBLER.

24. WINDOWS

_PITCHANDFAMILY
DB
32 DUP(O)
_FACENAME
DB
LOGFON
ENDS
;
WNDCL
STRUCT
DW 0 ;
STYLE
DD

LPFNWNDPROC
DW
CBCLSEXTRA
CBWNDEXTRA
DW
DW
HINSTANCE
DW
HICON
DW
HCURSOR
DW
HBRBACKGROUND

LPSZMENUNAME
DD
DD

LPSZCLASSNAME
WNDCL
ENDS

/,

RECT
STRUCT
LEFT
DW 0
TOP
DW 0
RIGHT
DW 0
BOTTOM
DW 0
RECT
ENDS
;
PAINTSTRUCT
STRUCT
7
DW
HDC
9
DW
FERASE
RECT
0
RCPAINT
DW
?
FRESTORE
DW
?
FINCUPDATE
RGBRESERVED
DB 16 DUP (?)
ENDS
PAINTSTRUCT
;
STRUCT
MESSA
DW 7
HWND
DW 7
MESSAGE
DW 7
WPARAM
DD 7
LPARAM
DW 7
TIME
DW
X
DW
Y
ENDS
MESSA
;
STA SEGMENT STACK 'STACK1
DW 2000 DUP(?)

539

540

ASSEMBLER.

STA ENDS
;
DATA SEGMENT WORD 'DATA'
DWORD 0
WORD
5
WORD
5 DUP (0)
HPREV
DW ?
HINST
DW ?
LPSZCMD DD ?
CMOSHOW DW ?
HWND DW ?
HOC DW ?
HFONT DW ?
;
BUFER DB ' : : ',0
;
LOGFONT LOGFON '
;
WNDCLASS WNDCL
;
MSG MESSA
;
RECTA RECT
; BEGINPAINT
PAINT PAINTSTRUCT
;
CLAS_NAME DB 'PRIVET' ,
;
APP_NAME DB 0 ;
;
CURSOR EQU 00007FOOH
;
STYLE EQU 000080000H
STYLE_EX
EQU 000000008H
;
XSTART DW 100
YSTART DW 100
DXCLIENT DW 210
DYCLIENT DW 90
DATA ENDS
;
CODE SEGMENT WORD
BEGIN:

'CODE'

24. WINDOWS

/
CALL INITTASK
OR AX,AX
JZ _ERR
MOV HPREV,SI
MOV HINST,DI
MOV WORD PTR LPSZCMD,BX

MOV WORD PTR LPSZCMD+2,ES


MOV CMDSHOW,DX
PUSH 0
CALL WAITEVENT
PUSH HINST
CALL INITAPP
OR AX,AX
JZ _ERR
CALL MAIN
_TO_OS:
MOV AH,4CH
CALL DOS3CALL
_ERR:
CALL BEEP
JMP SHORT _TO_OS
/

541

/
;CX -
t
; .
;
;ES:BX -

;
;
;
/

******************

MAIN PROC
/
/ NULL -
MOV
WNDCLASS. STYLE, 0
;
BX,WNDPROC
LEA
WORD PTR WNDCLASS .LPFNWNDPROC,BX
MOV
MOV
BX,CS
WORD PTR WNDCLASS . LPFNWNDPROC+2 , BX
MOV
/
MOV
WNDCLASS.CBCLSEXTRA,
/
MOV
WNDCLASS.CBWNDEXTRA,
/
MOV
WNDCLASS.HICON,
/
MOV
AX,HINST
MOV
WNDCLASS.HINSTANCE,AX

542

ASSEMBLER.

;
PUSH

PUSH
DS
PUSH
CURSOR
CALL
LOADCURSOR
MOV
WNDCLASS.HCURSOR, AX
;

;WHITE_BRUSH
PUSH
CALL
GETSTOCKOBJECT
;
MOV
WNDCLASS.HBRBACKGROUND, AX
; ( = NULL)
MOV
WORD PTR WNDCLASS.LPSZMENUNAME,
MOV
WORD PTR WNDCLASS.LPSZMENUNAME+2, 0
/ ,
LEA
BX,CLAS_NAME
MOV
WORD PTR WNDCLASS.LPSZCLASSNAME, BX
MOV
WORD PTR WNDCLASS.LPSZCLASSNAME+2,DS
;
PUSH DS
;
LEA DI, WNDCLASS
PUSH DI
,- WNDCLASS
CALL REGISTERCLASS
CMP AX,0
JNZ _OK1
;
CALL BEEP
RET
;
_1:
;
/ -
MOV
BX,HIGHWORD STY-LE_EX
PUSH BX
MOV
BX,LOWWORD STYLE_EX
PUSH BX
; -
PUSH DS
LEA BX,CLAS_NAME
PUSH BX
; -
PUSH DS
LEA BX,APP_NAME
PUSH BX

24. WINDOWS

543

;
MOV BX,HIGHWORD STYLE
PUSH
MOV BX,LOWWORD STYLE
PUSH BX
;
PUSH XSTART
; Y
PUSH YSTART
;
PUSH DXCLIENT
;
, - - . . .
PUSH DYCLIENT
; -
PUSH
/ ()
PUSH
;
PUSH HINST
; ()
PUSH 0
PUSH
CALL
CREATEWINDOWEX
CMP AX,0
JNZ NO_NULL
CALL BEEP
RET
;
; (
;) CMDSHOW
NO_NULL:
MOV HWND,AX
MOV SI,AX
PUSH SI
PUSH CMDSHOW
CALL SHOWWINDOW
; ( WM_PAINT,).
;
PUSH SI
CALL UPDATEWINDOW
/ ( )
MOV
LOGFONT._HEIGHT, 60
MOV
LOGFONT._WEIGHT,400
;FW_NORMAL
MOV
LOGFONT. PITCHANDFAMILY,20H
; FF SWISS

544

ASSEMBLER.

;
LOOP1:
;
PUSH DS
LEA BX/MSG /
PUSH BX
;
PUSH
PUSH
PUSH
CALL GETMES.SAGE
/ - ""
,
JZ NOJLOOP1
; ANSI
PUSH DS
LEA BX,MSG
PUSH BX
CALL TRANSLATEMESSAGE
/ WINDOWS
;
PUSH DS
LEA BX,MSG
PUSH BX
CALL
DISPATCHMESSAGE
/ ()
JMP SHORT LOOPI
NO_LOOP1:
RET
MAIN ENDP
/
/WINDOWS :
/HWND - () , WORD
/MES - , WORD
/WPARAM - , WORD
/LPARAM - , DWORD
WNDPROC PROC
PUSH
MOV
BP,SP
MOV AX,[BP+OCH]
/MES -
CMP AX, 2 / (2-
)
JNZ NEXT1
/ ,
/ , ..
PUSH
CALL POSTQUITMESSAGE
JMP QUIT

24. WINDOWS

NEXT1:

CMP AX,1
;WM CREATE -
JNZ NEXT2
;
PUSH [BP+OEH]
PUSH 1
PUSH 1000
; 1000
PUSH
PUSH
CALL SETTIMER
JMP _QUIT
NEXT2:
,111
;WM COMMAND - -
JNZ NEXT3
JMP _QUIT
NEXT3:
CMP AX,113H
;WM_TIMER -
JNZ NEXT4
/
; WM_PAINT
PUSH [BP+OEH]
~
PUSH
PUSH
PUSH 1
CALL INVALIDATERECT
JMP QUIT
NEXT4:
CMP AX,OFH
WM PAINT -
JNZ NEXT5
PUSH [BP+OEH]
PUSH DS
LEA BX,PAINT
PUSH BX
CALL BEGINPAINT
MOV HOC,AX
;

PUSH DS
LEA BX,LOGFONT
PUSH BX
CALL CREATEFONTINDIRECT
MOV HFONT,AX
PUSH HOC
PUSH AX
CALL SELECTOBJECT
18-4072

545

546

ASSEMBLER.

--
MOV , 2
INT 1AH

CALL _BCD
;--
PUSH HOC
PUSH 1
PUSH 1
PUSH DS
LEA BX,BUFER
PUSH BX
PUSH 8
/
CALL TEXTOUT
f

PUSH HOC
PUSH HFONT
CALL SELECTOBJECT
r

PUSH AX
CALL DELETEOBJECT
^

PUSH HOC
PUSH DS
LEA BX,PAINT
PUSH BX
CALL ENDPAINT
JMP _QUIT

NEXT5:
NEXT:
/ WINDOWS
/ - ,
/
/WINDOWS
PUSH [BP+OEH]
/HWND
PUSH [BP+OCH]
/MES -
PUSH [BP+OAH]
/WPARAM
PUSH [BP+8]
/HIGHWORD LPARAM
PUSH [BP+6]
/LOWWORD LPARAM
CALL DEFWINDOWPROC
.******************************************************
_QUIT:
POP BP
/ , RETF
RETF 10
/
WNDPROC ENDP

24. WINDOWS

;
PROC
MOV , 2
MOV D L , 7

CALL DOS3CALL
RET
ENDP
; BCD-
;
_BCD PROC
;
MOV AL,CH
SHR AL,4 :
ADD AL,48
AND CH,00001111B
CMP CH,10
JB _OK1
ADD AL,1
SUB CH,10
_OK1:
ADD CH,48
MOV BYTE PTR BUFER,AL
MOV BYTE PTR BUFER+1,CH
;
MOV AL,CL
SHR AL,4
ADD AL,48
AND CL,00001111B
CMP CL,10
JB _OK2
ADD AL,1
SUB CL,10
_OK2:
ADD CL,48
MOV BYTE PTR BUFER+3,AL
MOV BYTE PTR BUFER+4,CL
;
MOV AL,DH
SHR AL,4
ADD AL,48
AND DH,00001111B
CMP DH,10
JB _OK3
ADD AL,1
SUB DH,10

18'

547

548

ASSEMBLER.

_:
ADD DH,48
MOV BYTE PTR BUFER+6,AL
MOV BYTE PTR BUFER+7,DH
RETN
_BCD ENDP
CODE ENDS
END _BEGIN
Puc. 24.5. -.
. , , . ,
.
, :
1. (WM_CREATE) .
(\VM_TIMER) .
2. . - . (LOGFONT) .
3. \VM_TIMER .
WM_PAINT.

25. 32-
WINDOWS.
( WINDOWS 95-98.)
- , ,
.
, ,
!
.. .
.
Windows 3.1. Windows 95, . - Windows 95,
.. , 32- .
Windows 95 , , . .
. , Windows 95 (. 20), .
, .
.
, ,
Windows 95 Microsoft66, - (5.0) ++ (.5.0).
API ++.
,
( ).

I. .
, , Windows 95 , . ,
, MS DOS. , , 32- , ,
, API.
Windows 95. API-. , , , Far
.
66

ASM 6.14.

550

ASSEMBLER.

, API (
) .
: API
, . /ml.
(. 24.6) , . 32-
++(5.0): cOx32.obj, cw32.1ib, import32.1ib. - MASM 6.0, tlink32.exe.
++. consoll .asm,
consol I .exe :
masm /Ml consoll
tlink32 cOx32+consoll,consoll, ,cw32 imort32
cOx32.obj, import32.1ib cw32.1ib . , MS DOS,
15.
.386
/
.MODEL FLAT
EXTRN
AllocConsole:NEAR
EXTRN
FreeConsole:NEAR
EXTRN
_GETCH:NEAR
PUBLIC _MAIN
JTEXT
SEGMENT DWORD PUBLIC USE32 'CODE1
/, cOx32.obj
_MAIN
PROC
NEAR
;
CALL
FreeConsole
CALL
AllocConsole
;
CALL
_GETCH
;
CALL
FreeConsole
;
RET
_MAIN ENDP
_ ENDS
END
. 24.6. .

25. 32- WINDOWS

551

,
API ( ):
:
int SetConsoleTitle(str), str - , .
:
int GetStdHandle(param), param - :
STD_INPUT_HANDLE - -10 -
STD_OUTPUT_HANDLE - -11 -
STD_ERROR_HANDLE - -12 - .
:
int WriteConsole(handl, str, len, lenl, noused), handl - , str - , len , , lenl - , ,
noused - .
:
int ReadConsole(handl, buf, len, lenl, noused), handl - , buf - , len - , len 1 - , , noused .
:
int SetConsoleCursorPosition(handl, coord), handl - , coord - xdb?
ydb?
:
int SetConsoleTextAttribute(handl, color),
handl - , color - , , OR
FOREGROUND_BLUE 0x0001 - ,
FOREGROUND_GREEN 0x0002 - ,
FOREGROUND_RED 0x0004 - ,
FOREGROUNDJNTENSITY 0x0008 - ,
BACKGROUND_BLUE 0x0010 - ,
BACKGROUND_GREEN 0x0020 - ,
BACKGROUND_RED 0x0040 - ,
BACKGROUNDJNTENSITY 0x0080 - .
:
int ReadConsoleInput(handl, buf, num, numl),
handl - , buf- (. ), num - , numl -
. ReadMouselnputQ
. ( ):

552

ASSEMBLER.

typedef struct INPUT_RECORD


{
WORD EventType;
union
{
KEY_EVENT_RECORD KeyEvent;
&&
MOUSE_EVENT_RECORD MouseEvent; &&
WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent; &&
MENU_EVENT_RECORD MenuEvent;
&&
FOCUS_EVENT_RECORD FocusEvent; &&
} Event;
} INPUT_RECORD;

.
. .
, , :
1. API, ( , , ).
2. , ..
(. 15).
3. ,
.
4. . . ,
.
_. "".
. ,
Windows 95 (. 20).
, , .
, .
, .
.386
;
.MODEL FLAT
;
EXTRN
GetStdHandle:near
EXTRN
AllocConsolernear
EXTRN
FreeConsole:near
EXTRN
WriteConsoleA:near
EXTRN
_CLOSE:near
EXTRN
_OPEN:near
EXTRN
_READ:near
EXTRN
_GETCH:near
PUBLIC
MAIN

25. 32- WINDOWS

553

;
_
SEGMENT DWORD PUBLIC USE32 'CODE'
/,
_MAIN
PROC
NEAR
;
CALL
FreeConsole
CALL
AllocConsole
/
PUSH
-11
CALL
GetStdHandle
MOV
EDI,EAX
;
PUSH
8002 /0_BINARY OR O_RDVR
PUSH
OFFSET TEX
CALL
_OPEN
ADD
ESP,8
/
MOV
ESI,EAX /
CMP
EAX,-1
/
JNE
SHORT LOO
;
MOV
EAX,1
JMP
SHORT _END
LOO:
/
/
PUSH 100
PUSH
OFFSET MSG / (32-)
;
PUSH
ESI
_READ
CALL
/
ESP, 12
ADD
;
EBX,EAX
MOV
/
;
PUSH
0
OFFSET NUM ;
PUSH
/
EBX
PUSH
OFFSET MSG / ()
PUSH
/
PUSH
EDI
WriteConso;
CALL
,
EBX, 100 /
;<
CMP
JE
SHORT LOO
;
PUSH
ESI
_CLOSE
CALL
ECX
POP

554

ASSEMBLER.

;
CALL
_GETCH
;
CALL
FreeConsole
;
XOR
,
_END:
RET
_MAIN
ENDP
_TEXT
ENDS
;
_DATA
SEGMENT DWORD PUBLIC USE32
TEX
DB
"TEST.TXT",0
NUM
DD
?
MSG
DB
100 DUP(O)
_DATA
ENDS
END

'DATA'

Puc. 24.7. .
. 24.7 ,
"". _
, .
, , . (. ).

. 32- .
: MASM.EXE (Microsoft), tlink32.exe - 32- (Borland)
Ci++ Borland 5.O. MASM, . TASM 5.0,
tlink32.exe, , import32.1ib TASM.
- : include-, .
, , , , .
.
1,,
95. progS. :
TASM32 /ml
tlink32 prog8,prog8,prog8, import32
, . . -

25. 32- WINDOWS

555

: , ..
. , .
(. 24.7).
.386
/
;
.MODEL FLAT
;
EXTRN
Beep:NEAR
EXTRN
CreateWindowExA:NEAR
EXTRN
DefWindowProcA:NEAR
EXTRN
DispatchMessageA:NEAR
EXTRN
ExitProcess:NEAR
EXTRN
GetMessageA:NEAR
EXTRN
GetModuleHandleA:NEAR
EXTRN
LoadCursorA:NEAR
EXTRN
LoadIconA:NEAR
EXTRN
PostQuitMessagerNEAR
EXTRN
RegisterClassArNEAR
EXTRN
ShowWindow:NEAR
EXTRN
TranslateMessage:NEAR
UpdateWindow:NEAR
EXTRN
PUBLIC WNDPROC
;
MSGSTRUCT STRUG
MSHWND
MSMESSAGE
MSWPARAM
MSLPARAM
MSTIME
MSPT
MSGSTRUCT ENDS
WNDCLASS STRUG
CLSSTYLE
CLSLPFNWNDPROC
CLSCBCLSEXTRA
CLSCBWNDEXTRA
CLSHINSTANCE
CLSHICON

DD
DD
DD
DD
DD
DD

DD
DD
DD
DD
DD
DD

?
?
?
?
?
?

?
?
?
?
?
?

556

ASSEMBLER.

CLSHCURSOR
DD ?
CLSHBRBACKGROUND DD ?
CLSLPSZMENUNAME
DD ?
CLSLPSZCLASSNAME DD ?
WNDCLASS ENDS
;
DATA SEGMENT DWORD PUBLIC USE32 'DATA'
DD 0
NEWHWND
MSG
MSGSTRUCT
WC
WNDCLASS
HINST
DD 0
TITLENAME
DB 'WIN32, SIMPLE ASSEMBLY PROGRAM',0
CLASSNAME
DB 'CLASS32',0
_DATA ENDS

_TEXT SEGMENT DWORD PUBLIC USE32 'CODE1
START:
PUSH
0
CALL
GetModuleHandleA
MOV
[HINST], EAX
REG_CLASS:
/
; CS_HREDRAW + CS_VREDRAW + CS_GLOBALCLASS
MOV
[WC.CLSSTYLE] ,4003H
;
MOV
[WC.CLSLPFNWNDPROC], OFFSET WNDPROC
MOV
[WC.CLSCBCLSEXTRA], 0
MOV
[WC.CLSCBWNDEXTRA] , 0
MOV
EAX, [HINST]
MOV
[WC.CLSHINSTANCE], EAX
___

PUSH
PUSH
CALL
MOV

32512
;IDI_APPLICATION
0
LoadlconA
[WC.CLSHICON], EAX

PUSH
PUSH
CALL
MOV

32512
;IDC_ARROW
0
LoadCursorA
[WC.CLSHCURSOR], EAX

MOV
MOV
MOV

[WC.CLSHBRBACKGROUND], 17 ;
DWORD PTR [WC.CLSLPSZMENUNAME] , 0
DWORD PTR [WC.CLSLPSZCLASSNAME], OFFSET CLASSNAME

25. 32- WINDOWS

PUSH
OFFSET WC
CALL
RegisterClassA
;
PUSH
0
PUSH
[HINST]
PUSH
0
PUSH
0
PUSH
400
DY
PUSH
400
DX
PUSH
100
Y
PUSH
100
X
PUSH
OOOCFOOOOH
WSJDVERLAPPEDWINDOW
PUSH
OFFSET TITLENAME
;
PUSH
OFFSET CLASSNAME
;
PUSH
0
CreateWindowExA
CALL
;
CMP
EAX,0
JZ
_ERR
MOV
[NEWHWND], EAX
PUSH
1
;SW_SHOWNORMAL
PUSH
[NEWHWND]
CALL
ShowWindow
PUSH
[NEWHWND]
UpdateWindow
CALL
;
MSG_LOOP:
PUSH

PUSH

PUSH

PUSH
OFFSET MSG
CALL
GetMessageA
CMP
,
JE
END_LOOP
PUSH
OFFSET MSG
CALL
TranslateMessage
PUSH
OFFSET MSG
CALL
DispatchMessageA
JMP
MSG LOOP
END_LOOP:
[MSG.MSWPARAM]
PUSH
CALL
ExitProcess
_ERR:
CALL
BEE
JMP
END LOOP

557

558

ASSEMBLER.

;
/
; [+014]
;LPARAM
;WAPARAM
; [+10]
; [+]
;MES
;HWND
; [+8]
WNDPROC
PROC
PUSH EBP
MOV
EBP,ESP
PUSH EBX
PUSH ESI
PUSH EDI
DWORD PTR [EBP+OCH],2
DESTROY
CMP
JE
WMDESTROY
CMP
DWORD PTR [EBP+OCH],!
r W M CREATE
JE
WMCREATE
CMP
DWORD PTR [EBP+OCH],201H /
JE
LBUTTON
CMP
DWORD PTR [EBP+OCH] ,204H ,-
JE
RBUTTON
JMP
DEFWNDPROC
;
RBUTTON:
JMP
WMDESTROY
;
LBUTTON:
CALL BEE
MOV
,0
JMP
FINISH
WMCREATE:
MOV
EAX, 0
JMP
FINISH
DEFWNDPROC
PUSH
DWORD PTR [EBP+14H]
PUSH
DWORD PTR [EBP+10H]
PUSH
DWORD PTR [EBP+OCH]
PUSH
DWORD PTR [EBP+08H]
CALL
DefWindowProcA
JMP
FINISH
WMDESTROY:
PUSH
0
CALL
PostQuitMessage
MOV
EAX, 0

25. 32- WINDOWS

FINISH:
POP
POP
POP
POP
RET
WNDPROC

559

EDI
ESI
EBX
EBP
16
ENDP

BEE PROC
MOV
PUSH

ECX, 100
ECX

_:
PUSH
0
PUSH
0
/ ,
CALL
Beep
POP
ECX
DEC
ECX
PUSH
ECX
LOOPD
_OP
POP ECX
RET
BEE ENDP
_TEXT ENDS
END START
Puc. 24.8. WIN DO WS 95 32- .
.24.8 -
GetModuleHandleA. 16- ,
, . , ?

III. .
, , .. - .
, , - , -. :
1. ?
2. ?
3. ?
.
1. RC, .
. , , , -

560

ASSEMBLER.

, , Borland . .
. :
MENUP MENU
POPUP "&"
MENUITEM "& ", 101
MENUITEM "E&xit", 102

. MENUP.
.
.
. &.
2. . BRC.EXE. , R1 .RC, : BRC 32 - R1. RI .RES.
, tlik32. progl, : tlink32
prog I ,prog I ,prog 1 ,imort32, ,r 1 prog 1 . RI. RES.
3. ,
( MENUP).
WM_COMMAND.
WPARAM - .
. 24.9 , . 24.8 - .
MessageBox. .
.386
/
.MODEL FLAT
;
EXTRN
Beep:NEAR
EXTRN
CreateWindowExArNEAR
EXTRN
DefWindowProcA:NEAR
EXTRN
DispatchMessageArNEAR
EXTRN
ExitProcess:NEAR
EXTRN
GetMessageA:NEAR
EXTRN
GetModuleHandleA:NEAR
EXTRN
LoadCursorArNEAR

25. 32- WINDOWS

EXTRN
EXTRN
EXTRN
EXTRN
EXTRN
EXTRN
EXTRN
PUBLIC WNDPROC
;
MSGSTRUCT STRUG
MSHWND
MSMESSAGE
MSWPARAM
MSLPARAM
MSTIME
MSPT
MSGSTRUCT ENDS

LoadIconA:NEAR
PostQuitMessage:NEAR
RegisterClassArNEAR
ShowWindow:NEAR
TranslateMessage:NEAR
UpdateWindow:NEAR
MessageBoxA:NEAR

DD
DD
DD
DD
DD
DD

7
7
7
7
7
7

WNDCLASS STRUG
CLSSTYLE
DD 7
CLSLPFNWNDPROC
DD 7
CLSCBCLSEXTRA
DD 7
CLSCBWNDEXTRA
DD 7
CLSHINSTANCE
DD 7
CLSHICON

DD 7
CLSHCURSOR
DD 7
CLSHBRBACKGROUND DD 7
CLSLPSZMENUNAME
DD 7
CLSLPSZCLASSNAME
DD 7
WNDCLASS ENDS
;
DATA SEGMENT DWORD PUBLIC USE32 'DATA'
DD 0
NEWHWND
MSGSTRUCT
MSG
WNDCLASS
WC
DD 0
HINST
DB 'WIN32, ASSEMBLY PROGRAM WITH MENU',0
TITLENAME
CLASSNAME
DB 'CLASS32',0
DB 'MENUP',0
MENU
DB ' ',
TEXTM
DB '',
TEXTMC
_DATA ENDS
;
1
TEXT
SEGMENT DWORD PUBLIC USE32 CODE'

561

562

ASSEMBLER.

START:
PUSH
0
CALL
GetModuleHandleA
MOV
[HINST], EAX
REG_CLASS:
/
; CS_ HREDRAW + CS_VREDRAW + CS_GLOBALCLASS
MOV
[WC.CLSSTYLE],4003H
;
MOV
[WC.CLSLPFNWNDPROC] OFFSET WNDPROC
MOV
[WC.CLSCBCLSEXTRA], 0
MOV
[WC.CLSCBWNDEXTRA], 0
MOV
EAX, [HINST]
MOV
[WC.CLSHINSTANCE] , EAX
PUSH
PUSH
CALL
MOV

32512
;IDI_APPLICATION
0
LoadlconA
[WC.CLSHICON] , EAX

PUSH
PUSH
CALL
MOV

32512
;IDC_ARROW
0
LoadCursorA
[WC.CLSHCURSOR], EAX

MOV
[WC.CLSHBRBACKGROUND], 17 ,-
MOV
DWORD PTR [WC.CLSLPSZMENUNAME], OFFSET MENU
MOV
DWORD PTR [WC.CLSLPSZCLASSNAME], OFFSET CLASSNAME
PUSH
OFFSET WC
CALL
RegisterClassA
;
PUSH

PUSH
[HINST]
PUSH
0
PUSH
0
PUSH
400
; DY
PUSH
400
; DX
PUSH
100
; Y
PUSH
100
; X
PUSH
OOOCFOOOOH
WSJDVERLAPPEDWINDOW
PUSH
OFFSET TITLENAME
;
PUSH
OFFSET CLASSNAME
;
PUSH
0
CALL
CreateWindowExA

25. 32- WINDOWS

;
CMP
EAX,
JZ
_ERR
MOV
[NEWHWND], EAX
PUSH
1
;SW_SHOWNORMAL
PUSH
[NEWHWND]
CALL
ShowWindow
PUSH
[NEWHWND]
CALL
UpdateWindow
;
MSG LOOP:
PUSH
0
PUSH
0
PUSH
0
PUSH
OFFSET MSG
GetMessageA
CALL
CMP
AX, 0
JE
END_LOOP
PUSH
OFFSET MSG
CALL
TranslateMessage
PUSH
OFFSET MSG
. CALL
DispatchMessageA
JMP
MSG_LOOP
END_LOOP:
PUSH
[MSG.MSWPARAM]
ExitProcess
CALL
_ERR:
CALL
BEE
END LOOP
JMP


;LPARAM
[+014]
;WAPARAM
[+10]
;MES
[+]
; HWND
[+8]
PROC
WNDPROC
PUSH EBP
MOV
EBP,ESP
PUSH EBX
PUSH ESI
PUSH EDI
DWORD PTR [EBP+OCH],2
CMP
WMDESTROY
JE

;WM DESTROY

563

ASSEMBLER.

564
CMP
JE
CMP
JE
CMP
JE
CMP

DWORD PTR [EBP+OCH],!


;WM_CREATE
WMCREATE
DWORD PTR [EBP+OCH],201H ;
LBUTTON
DWORD PTR [EBP+OCH] , 204H ;
RBUTTON
DWORD PTR [EBP+OCH],111H ;WM_COMMAND
JE
WMCOMMAND
JMP
DEFWNDPROC
; WM_COMMAND
; ,
;
WMCOMMAND:
; ,
;
; 101 ( )
; WPARAM
CMP
WORD PTR [+10],102
;exit&
JE
WMDESTROY
CMP
WORD PTR [EBP+10H],101
;
JNE
NO_IT
;
PUSH
;_ -
PUSH OFFSET TEXTMC /
PUSH OFFSET TEXTM ;
PUSH DWORD PTR [EBP+08H]
,-
CALL
MessageBoxA
NO_IT:
JMP
DEFWNDPROC
;
RBUTTON:
JMP
WMDESTROY
;
LBUTTON:
CALL BEE
MOV
,0
JMP
FINISH
\
WMCREATE:
MOV
EAX, .0
\JMP
FINISH
DEFWNDPROC
PUSH
DWORD PTR [EBP+14H]
PUSH
DWORD PTR [EBP+10H]
PUSH
DWORD PTR [EBP+OCH]

25. 32- WINDOWS

DWORD PTR [EBP+08H]


DefWindowProcA
FINISH

PUSH
CALL
JMP
WMDESTROY:
PUSH
CALL
MOV
FINISH:

POP
POP
POP
POP
RET
WNDPROC

565

0
PostQuitMessage
EAX, 0 ;
EDI
ESI
EBX
EBP
16
ENDP

;
BEE PROC
MOV
ECX,100
PUSH
ECX
OP:
PUSH
PUSH
/ ,
CALL
Beep
POP
ECX
DEC
ECX
PUSH
ECX
LOOPD
_OP
POP ECX
RET
BEE ENDP
_TEXT ENDS
END START
. 24.9. .
. , (
). ,
, , . (CreateWindow), DialogBox.
, , , . ,
. , :

566

ASSEMBLER.

1. 0, 1 (
), .
2. . . , WM_CREATE WMJNTTDIALOG.
.
, DialogBox
. , ,
, , .
.
(, , ,
..). . . . 0, ,
1, , .
, , . . , , , WM_COMMAND.
wParam , - .
(. 24.11) . ,
. DialogBoxParamA
( , , ). .
24.10 .
#define IDC_BUTTON1 55
//
DIAL1 DIALOG , , 240, 120 //
STYLE DS_MODALFRAME | DS_3DLOOK I DS_CONTEXTHELP | WS_POPUP |
WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION " " //
FONT 8, "MS Sans Serif"
{
'
.
CONTROL "OK", IDC_BUTTON1, "button", BS_PUSHBUTTON | BS_CENTER
| WS_CHILD | WS_VISIBLE | WS_TABSTOP, 176, 13, 50, 14
}

. 24.10. . 24.11.
.386
;
;
.MODEL FLAT
/
EXTRN
EXTRN

DispatchMessageA:NEAR
ExitProcess-.NEAR

25. 32- WINDOWS

EXTRN
EXTRN
EXTRN
EXTRN
EXTRN
EXTRN
PUBLIC DLGPROC
;
MSGSTRUCT STRUG
MSHWND
MSMESSAGE
MSWPARAM
MSLPARAM
MSTIME
MSPT
MSGSTRUCT ENDS

567

GetModuleHandleA:NEAR
PostQuitMessage:NEAR
GetMessageA:NEAR
TranslateMessage:NEAR
DialogBoxParamA:NEAR
EndDialog:NEAR

DD
DD
DD
DD
DD
DD

;
DATA SEGMENT DWORD PUBLIC USE32 1 DATA'
NEWHWND
DD 0
MSG
MSGSTRUCT
HINST
DD 0
DIAL
DB 'DIAL1',0 / -
_DATA ENDS
;
_TEXT SEGMENT DWORD PUBLIC USE32 'CODE'
START:
PUSH
0
CALL
GetModuleHandleA
MOV
[HINST], EAX
;
PUSH 0
/
PUSH OFFSET DLGPROC /
PUSH 0
; ,
PUSH OFFSET DIAL ; -
PUSH [HINST]
CALL DialogBoxParamA
/
MSG_LOOP:
PUSH

PUSH

PUSH

PUSH
OFFSET MSG

ASSEMBLER.

56

CALL
CMP
JE
PUSH
CALL
PUSH
CALL
JMP
END_LOOP:
PUSH
CALL

GetMessageA
AX, 0
END_LOOP
OFFSET MSG
TranslateMessage
OFFSET MSG
DispatchMessageA
MSG_LOOP
[MSG.MSWPARAM]
ExitProcess




[+014]
;LPARAM
[+10]
;WAPARAM
[+]
;MES
[+8]
;HWND
DLGPROC
PROC
PUSH EBP
MOV
EBP,ESP
PUSH EBX
PUSH ESI
PUSH EDI
MOV
EAX, 0
CMP
DWORD PTR [EBP+OCH],110H ;WM_INITDIALOG
JE
WMINITDIALOG
CMP
DWORD PTR [EBP+OCH],111H ;WM_COMMAND
JE
WMCOMMAND
JMP
FINISH
; WM_COMMAND
; ,
WMCOMMAND:
CMP
WORD PTR [EBP+10H],55 ;
JNE
FINISH
;
PUSH

CALL
PostQuitMessage / ,
PUSH
PUSH

DWORD PTR

CALL
MOV
JMP

EndDialog
EAX,1
FINISH

[EBP+08H]

25. 32- WINDOWS

569

; ,
; ,
WMINITDIALOG:
JMP
FINISH
FINISH:
POP EDI
POP ESI
POP EBX
POP EBP
RET 16
DLGPROC
ENDP

___

_. _

-. _ _ _ . _ _ _ _ - . _

__

_.__

__

_TEXT ENDS
END START

Puc. 24.11. .

.
, , Windows (API ). Windows . . Windows , ,
. . Windows, .
Windows 95 (98)
Windows NT 4.0.
API-. .
.
1. .
, .
2. . , CreateFile dwShareMode
FILE_SHARE_DELETE, Windows NT.
3. , ,
, . . ,
NULL, . ,
- .

26.
.
- .
.
5. 5 , , . MASM.EXE 5.0. MASM.EXE :
1. MOV AX,CRO , MOV
EAX,CRO.
2. LIDT QWORD MET1 .
LIDT FWORD 1. FWORD - . DF.
, , . Windows . , . ,
, .

I.
, 5.
1. . , , - . - ,
, - ( ).
2. . .
3.
: (. 5), 13
, . 2 , (0 - ).
4. , , , 13 , . , 8 . , . DESCO - ,
DESC - , DESC-DESCO - 8 DESC, 13 .
.

26.

571

5. , . , ,
. , - .
(24-) DL:AX.
.
MOV
SHL
SHR
ADD
ADC

DL,AH
,4
DL,4
AX,BX
DL,0

6. .
.
. , - .
7. CMOS - ,
(. 23). CMOS
BIOS, , . CMOS
70 71.
CMOS:
MOV AL,XXH

OUT 70H,AL ; CMOS


JMP $+2
/
IN AL,71H ; CMOS
CMOS:
MOV AL,XXH
OUT 70H,AL ; CMOS
JMP $+2
/
MOV AL,YYH ; CMOS
OUT 71H,AL
70 CMOS, NMI ( ). 7 0,
NMI , .
. NMI .
AL 7- , OUT 70H,AL
CMOS, NMI. CMOS OOH-3FH. 3FH,
.

ASSEMBLER.

572

8. FH CMOS .
, ,
.
5,
JMP FAR PTR [ 0 : 4 6 7 ]
/
.286
;
; 10000000 -
; 00011000 -
; 00010000 -
; 00000100 -
/00000100 -
/00000010 -
/
DATA_AC
EQU 10010010
/
CODE_AC
EQU 10011100B
/
STACK_AC EQU 10010110B
DATA SEGMENT
BEG_DATA = $
;
MSG
DB 'HELLO! !',
MSG1
DB ' ! ! ' ,
/
/
COLUMNS DB ?
ROWS
DB ?
/
SEL_BUF DW ?
/
SEGBUF DW ?
;
/
DW
SS
DW
DS
DW
ES
SP
DW
;
/
GOTO
DQ
/ GDT
GDT_GDT DQ
/
GDT DS
DQ 0

26.

573

;
GDT_CS
DQ
/
GDT_SS
DQ
/
GDT_CRT DQ
/
GDT_MDA DQ
GDT_SIZE = $-GDTO
/
DSEG_SIZE = $-BEG_DATA /
DATA ENDS
/
ST1 SEGMENT STACK 'STACK1
DB 100 DUP(?)
ST1 ENDS
;
CODE SEGMENT
ASSUME CSrCODE, DS:DATA, SS:ST1
BEG:
/
MOV AX,DATA
MOV DS,AX
/
CALL WHAT_CRT
/
CALL INI_PROT
;
CALL SET_PROT
/
MOV ,77
CALL CLS
/
/
MOV ,0
/ Y
MOV ,15
/ X
/
MOV SI,OFFSET MSG
MOV AH,41H /
CALL WRITE
/
CALL PAUSE
/
CALL SET REAL

574

ASSEMBLER.

;
MOV , 7

CALL

CLS

;
;
MOV , 0
,- Y
MOV ,15 ; X
;
MOV SI,OFFSET MSG1
MOV ,13
/
CALL WRITE
;
CALL PAUSE
;
MOV ,4
INT 21H
;
;
PAUSE PROC
PUSH
MOV CX,50
PL:
PUSH
MOV CX,OFFFFH
PL1:
LOOP PL1
POP CX
LOOP PL
POP CX
RETN
PAUSE ENDP
;
WHAT_CRT PROC
MOV AX,4OH
MOV ES,AX
MOV BX,ES:[4AH]
MOV COLUMNS,BL
MOV BL,ES:[84H]
INC BL
MOV ROWS,BL
MOV BX,ES:[63H]
CMP BX,3D4H
JNE NO COLOR

26.

;
MOV SEL_BUF,(GDT_CRT-GDTO)
MOV SEG_BUF,OB800H
MOV ES,SEG_BUF
JMP SHORT EXIT
NO_COLOR:
; MDA
MOV SEL_BUF,(GDT_MDA-GDTO)
MOV SEG_BUF,OBOOOH
MOV ES,SEG_BUF
EXIT:
RETN
WHAT_CRT EN DP
;
; ES ,
; -
CLS PROC
MOV ,2000
MOV AL, 32
XOR DI,DI
L2:
STOSW
LOOP L2
RETN
CLS ENDP
;
; ES ,
;, - X,Y
;SI -
; -
WRITE PROC
/
PUSH AX
MOV DL,COLUMNS
MUL DL
ADD AX,BX
SHL AX,1
MOV DI,AX
POP AX
L01:
LODSB
CMP AL,0
JZ EN
STOSW
JMP SHORT L01

575

576

ASSEMBLER.

EN:

RETN
WRITE ENDP
;
INI_PROT PROC
; GOT
;

MOV AX,DATA
MOV DL,AH
SHR DL,4
SHL AX,4
MOV SI,AX
MOV DI,DX
.
GOT
ADD AX,OFFSET GOTO
ADC DL,0
MOV BX,OFFSET GDT_GDT
MOV WORD PTR [BX],GDT_SIZE-1
MOV [BX+2],AX
MOV [BX+4],DL
MOV BYTE PTR [BX+5],DATA_AC
;
MOV BX,OFFSET GDT_DS
MOV AX,SI
MOV DX,DI
MOV WORD PTR [BX],DSEG_SIZE-1
MOV [BX+2],AX
MOV [BX+4],DL
MOV BYTE PTR [BX+5],DATA_AC
;

MOV BX,OFFSET GDT_CS
MOV AX,CS
MOV DL,AH
SHR DL,4
SHL AX,4
MOV WORD PTR [BX],CSEG_SIZE-1
MOV [BX+2],AX
MOV [BX+4],DL
MOV BYTE PTR [BX+5],CODE_AC
;
MOV BX,OFFSET GDT_SS
MOV AX,SS
MOV DL,AH
SHR DL,4

26.

SHL ,4
MOV WORD PTR [],400-1
MOV [+2],
MOV [BX+4],DL
MOV BYTE PTR [BX+5],DATA_AC
;
CRT
MOV BX,OFFSET GDT_CRT
MOV WORD PTR [BX],3999
MOV WORD PTR [BX+2],8000H
MOV BYTE PTR [BX+4],OBH
MOV BYTE PTR [BX+5],DATA_AC
;
MDA
MOV BX,OFFSET GDT_MDA
MOV WORD PTR [BX],3999
MOV BYTE PTR [BX+4],OBH
MOV BYTE PTR [BX+5],DATA_AC
;

PUSH DS
MOV AX,4
MOV DS, AX
MOV word ptr DS: [67H],OFFSET SHUT_DOWN_RETURN
MOV DS:[69H],CS
POP DS
;

; OFH CMOS 5
;
; NMI
CLI
MOV AL,8FH
OUT 70H,AL
JMP NEXT1
/
NEXT1:
MOV AL,5
OUT 71H,AL
RETN
INI_PROT ENDP
;
SET_PROT PROC
MOV _SS,SS
MOV _ES,ES
/ GDTR
LGDT GDT_GDT
;
MOV AX, 1
LMSW AX
19-4072

577

578

ASSEMBLER.

jMp FAR FLUSH,


DB

DW
DW

OFFSET FLUSH
(GDT_CS-GDTO)

FLUSH:
;
MOV AX, (GDT_DS-GDTO)
MOV DS,AX
MOV AX,SEL_BUF
MOV ES,AX
MOV AX,(GDT_SS-GDTO)
MOV SS,AX
RETN
SET_PROT ENDP
/
SET_REAL PROC
/
MOV _SP,SP
;
MOV AL,OFEH
OUT 64H/AL
/ SHUT_DOWN_RETURN
_WAIT:
JMP _WAIT
;
/
SHUT_DOWN_RETURN:
/
MOV AX,DATA
MOV DS,AX
MOV SS,_SS
MOV SP,_SP
MOV ES,_ES
/
/
MOV ,
OUT 70H,AL
/
XOR AL,AL
OUT 21H,AL
/
STI
RETN
SET REAL ENDP

26.

579

CSEG_SIZE = $-BEG
CODE ENDS
END BEG

Puc. 20.1. .
. 20.1 , . ,
.
1. . .
.
2. ,
.
3. ,
.
,
, .
4. , , . .
- . . 20.2 , ,
. 1.
,
20, ENABLE. ,
. 5.2 5. 15.

;
.286
;
;10000000 -
;00011000 -
;00010000 -
;00000100 -
;00000100 -
;00000010 -
;
DATA_AC
EQU 10010010
;
CODE_AC
EQU 10011100B
;
STACK_AC EQU 10010110B
DATA SEGMENT
BEG DATA = $
19'

580

ASSEMBLER.

;
MSG
DB 'HELLO! !',
MSG1
DB '! !',
MSG2
DB ' ',
/
;
COLUMNS DB ?
;
ROWS
DB ?
SEL_BUF DW ?
;
;
SEG BUF DW ?
;
DW
_SS
DW
_DS
DW
_ES
SP
DW
/
;
GOTO
DQ
; GDT
GDT_GDT DQ
;
GDT_DS
DQ
;
GDT_CS
DQ
;
GDT_SS
DQ
;
GDT_CRT DQ
;
GDT_MDA DQ
; ,
GDT_MEM DQ
GDT_SIZE = $-GDTO
/
DSEG_SIZE = $-BEG_DATA /
DATA ENDS
;
ST1 SEGMENT STACK 'STACK'
DB 100 DUP(?)
ST1 ENDS
;
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:ST1
BEG:
;
MOV AX,DATA
MOV DS,AX

26.

;
CALL WHAT_CRT
;
CALL INI_PROT
/
CALL SET_PROT
;
MOV ,77
CALL CLS
;
;
MOV ,0
; Y
MOV ,15 / X
/
MOV SI,OFFSET MSG
MOV AH,41H /
CALL WRITE
/
CALL PAUSE
;
CALL TO_MEM
;
MOV ,39
CALL CLS
;
MOV ,0
/ Y
MOV ,15 / X
MOV SI,OFFSET MSG2
MOV AH,71H /
CALL WRITE
/
CALL PAUSE
/
CALL FROM_MEM
/
CALL PAUSE
/
CALL SET_REAL
/
MOV ,7
CALL CLS
/
MOV ,0
/ Y
MOV AX,15 / X

581

582

ASSEMBLER.

;
MOV SI,OFFSET MSG1
MOV ,13 ;
CALL WRITE
;
CALL PAUSE
;
MOV ,4

INT 21H
/
; ,
PAUSE PROC
PUSH
MOV ,50
PL:
PUSH
MOV CX,OFFFFH
PL1:
LOOP PL1
POP
CX
LOOP PL
POP
CX
RETN
PAUSE ENDP
;
WHAT_CRT PROC
MOV A X , 4 O H
MOV ES,AX
MOV B X , E S : [ 4 A H ]
MOV COLUMNS,BL
MOV B L , E S : [ 8 4 H ]
INC BL
MOV ROWS/BL
MOV BX,ES:[63H]
CMP BX,3D4H
JNE NO_COLOR
MOV SEL_BUF,(GDT_CRT-GDTO)
MOV SEG_BUF,OB800H
MOV ES,SEG_BUF
JMP SHORT EXIT
NO_COLOR:
; MDA
MOV SEL_BUF,(GDT_MDA-GDTO)
MOV SEG_BUF,OBOOOH
MOV ES,SEG BUF

26.

EXIT:
RETN
WHAT_CRT ENDP
;
; ES ,
; -
CLS PROC
MOV ,2000
MOV AL, 32
XOR DI,DI
L2:
STOSW
LOOP L2
RETN
CLS ENDP
;
; ES ,
;, - X,Y
;SI -
; -
WRITE PROC
;
PUSH AX
MOV DL,COLUMNS
MUL DL
ADD AX,BX
SHL ,1
MOV DI,AX
POP AX
L01:
LODSB
CMP AL,0
JZ EN
STOSW
JMP SHORT L01
EN:
RETN
WRITE ENDP
;
INI_PROT PROC
; GOT
MOV AX,DATA
MOV DL,AH
SHR DL,4

583

584

ASSEMBLER.

SHL A X , 4
MOV S I , A X
MOV D I , D X
ADD AX,OFFSET GOTO
ADC DL,0

MOV
MOV
MOV
MOV
MOV

BX,OFFSET GDT_GDT
WORD PTR [BX],GDT_SIZE-1
[BX+2],AX
[BX+4],DL
BYTE PTR [BX+5],DATA AC

MOV
MOV
MOV
MOV
MOV
MOV
MOV

BX,OFFSET GDT_DS
AX,SI
DX,DI
WORD PTR [BX],DSEG_SIZE-1
[BX+2],AX
[BX+4],DL
BYTE PTR [BX+5],DATA AC

MOV
MOV
MOV
SHR
SHL
MOV
MOV
MOV
MOV

BX,OFFSET GDT_CS
AX,CS
DL,AH
DL,4
AX,4
WORD PTR [BX],CSEG_SIZE-1
[BX+2],AX
[BX+4],DL
BYTE PTR [BX+5],CODE AC

MOV
MOV
MOV
SHR
SHL
MOV
MOV
MOV
MOV

BX,OFFSET GDT_SS
AX,SS
DL,AH
DL,4
AX,4
WORD PTR [BX],400-1
[BX+2],AX
[BX+4],DL
BYTE PTR [BX+5],DATA AC

MOV
MOV
MOV
MOV
MOV

BX,OFFSET
WORD PTR
WORD PTR
BYTE PTR
BYTE PTR

GDT_CRT
[BX],3999
[BX+2],8000H
[BX+4],OBH
[BX+5],DATA AC

26.

MOV BX,OFFSET GDT_MDA


MOV WORD PTR [BX],3999
MOV BYTE PTR [BX+4],OBH
MOV BYTE PTR [BX+5],DATA_AC
;
-MOV BX,OFFSET GDT_MEM
MOV WORD PTR [BX],3999
MOV WORD PTR [BX+2],OOOOH
MOV BYTE PTR [BX+4],15H
MOV BYTE PTR [BX+5],DATA_AC
;

PUSH DS
MOV AX,40H
MOV DS, AX
MOV word ptr DS: [67H],OFFSET SHUT_DOWN_RETURN
MOV DS: [69H],CS
POP DS
;


; OFH CMOS 5
/
CLI
MOV AL,8FH
OUT 70H,AL
JMP NEXT1
NEXT1:
MOV AL,5
OUT 71H,AL
RETN
INI_PROT ENDP
;
SET_PROT PROC
MOV _SS,SS
MOV _ES,ES
CALL ENABLE
; GDTR
LGDT GDT_GDT
/
MOV AX, 1
LMSW AX
;
JMP FAR FLUSH,
DB
OEAH
DW
OFFSET FLUSH
DW
(GDT_CS-GDTO)
FLUSH:

585

586

ASSEMBLER.

;
MOV
MOV

AX,(GDT_DS-GDTO)
DS,AX

MOV AX,SEL_BUF
MOV ES,AX
MOV AX,(GDT_SS-GDTO)
MOV SS,AX
RETN
SET_PROT ENDP
;
SET_REAL PROC
CALL DISABLE
;
MOV _SP,SP
;
MOV AL,OFEH
OUT 64H,AL
/ SHUT_DOWN_RETURN
_WAIT:
JMP _WAIT
;
;
SHUT_DOWN_RETURN:
/
MOV AX,DATA
MOV DS,AX
MOV SS,_SS
MOV SP,_SP
MOV ES,_ES
/
;
MOV AX,ODH
OUT
70H,AL
;
XOR AL,AL
OUT 21H,AL
;
STI
RETN
SET_REAL ENDP
;
; ES
_ PROC
PUSH DS
MOV ,(GOT MEM-GDTO)

26.

MOV
XOR
XOR
MOV

587

DS,AX
SI,SI
DI,DI
CX,4000

LL1:

MOV AL,ES:[SI]
MOV
[DI],AL
INC SI
INC DI
LOOP LL1
POP DS
RETN
TO_MEM ENDP
/
; ES
FROM_MEM PROC
PUSH DS
MOV AX,(GDT_MEM-GDTO)
MOV DS,AX
XOR SI,SI
XOR DI,DI
MOV CX,4000
LL2:
MOV AL, [SI]
MOV ES:[DI],AL
INC SI
INC DI
LOOP LL2
POP DS
RETN
FROM_MEM ENDP
; 20
; 20
ENABLE PROC NEAR
MOV AL,OD1H
; 20
OUT 64H,AL
;
MOV AL,ODFH
/ 20
OUT 60H,AL
/
RET
ENABLE ENDP
/ 20
DISABLE PROC NEAR
MOV AL,OD1H
OUT 64H,AL

588

ASSEMBLER.

MOV A L , O D D H
OUT 60H,AL
RET

; 20

DISABLE ENDP
CSEG_SIZE = $-BEG
CODE ENDS
END BEG
Puc. 20.2. , :
1 .
II.

.
.
.
. ( ). INT. ( ..).
, .
, - . . .
, . , .
.
IDTR. LIDT.
31- .
.
01 .
02 .
.
04 INTO.
05 BOUND, .
06 .
07 .
08 - .
09 .
TSS.
, .

26.

589

, , .
ODH , ,
.
3 86 .
OFH .
1 .
11-1 .
, INT.
, 16- .
.
- , .
1-2 - - 1 , 2
(0-, 1 -).
3-15- , .
: 08, , , , ODH.
, 01, 08, 09, ODH, 1 ,
. : ( 3 4)
, . IRET,
. , , ,
, ,
.
, , 0-7 .
. IRQOIRQ7 08 OFH (. 9). .
, ( PROGJNT).
9.
;
.286
;
;10000000 -
;00011000 -
;00010000 -
;00000100 -
;00000100 -
;00000010 -
;00000110 -

590

ASSEMBLER.

;00000111 -
;
DATA_AC EQU 10010010B
;
CODE_AC
EQU 10011100B
;
STACK_AC EQU 10010110B
; IDT
IDT_AC
EQU 10010010B
;
INT_AC
EQU 10000110B
;
TRAP_AC EQU 10000111B
;
ST1 SEGMENT STACK 'STACK1
DB 100 DUP(?)
ST1 ENDS
;
DATA SEGMENT
BEG_DATA=$
MSG DB ' .',
_DL DB 0
;
COLUMNS DB ?
/
ROWS
DB ?
/
SEL_BUF DW ?
/
SEG_BUF DW ?
;
/
_SS DW ?
_ES DW ?
_SP DW ?
;
TIME DW ?
/
/
GOTO
DQ
/ GDT
GDT_GDT DQ
/
GDT_CS
DQ
/
GDT_DS
DQ
/
GDT SS
DQ

26.

591

/
GDT_CRT

DQ

/
GDT_MDA DQ
/
GDT_IDT DQ
GDT_SIZE = $-GDTO
/
;
/
IDT BEG=$
_00
DQ 0
_01
DQ 0
DQ 0
02
DQ 0
_03
_04
DQ 0
DQ 0
05
_
DQ 0
_07
DQ 0
_08
DQ 0
DQ 0
_09
_
DQ 0
_
DQ 0
_
DQ 0 .
EXC_OD
DQ 0
_
DQ 0
EXC_OF
DQ 0
_10
DQ 0
DQ 0
_11
_12
DQ 0
DQ 0
13
_14
DQ 0
DQ 0
_15
DQ 0
_16
_17
DQ 0
_18
DQ 0
_19
DQ 0
_1
DQ 0
_1
DQ 0
DQ 0
_1
EXC_1D
DQ 0
_1
DQ 0
EXC_1F
DQ 0
;
DQ 0 ;
INT_20
DQ 0 ;
INT_21

592

INT 22
DQ 0
DQ 0
INT_23
DQ 0
INT_24
DQ 0
INT_25
INT_26
DQ 0
INT 27
DQ 0
DQ 0
INT_28
DQ 0
INT_29
INT_2A
DQ 0
INT 2B
DQ 0
INT 2C
DQ 0
INT_2D
DQ 0
INT_2E
DQ 0
INT_2F
DQ 0
IDT_SIZE= $-IDT BEG

ASSEMBLER.

DSEG_SIZE=$-BEG_DATA /
DATA ENDS
;
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:ST1
BEGIN:
MOV AX,DATA
MOV DS,AX
CALL WHAT_CRT
/
CALL INI_PROT
;
CALL SET_PROT
/
MOV BX, 0
/ Y
MOV ,15 / X
;
MOV SI,OFFSET MSG
MOV AH,41H
/
CALL WRITE
/ - ,
/ ,
/ ESC
_WAI: JMP SHORT _WAI
/
/
SET_PROT PROC NEAR
MOV _SS,SS
MOV ES,ES

26.

CALL ENABLE
CALL PROG_INT
;
LIDT QWORD PTR GDT_IDT
/
LGDT QWORD PTR GDT_GDT
/
MOV ' , 1
LMSW
;
JMP FAR FLUSH,
DB

DW
OFFSET FLUSH
DW
(GDT_CS-GDTO)
FLUSH:
;
MOV AX,(GDT_DS-GDTO)
MOV DS,AX
MOV AX,SEL_BUF
MOV ES,AX
MOV AX,(GDT_SS-GDTO)
MOV SS,AX
/
XOR AL,AL
OUT 21H/AL
OUT OA1H,AL
XOR DL,DL
;
STI
RETN
SET_PROT ENDP
/ 20
ENABLE PROC NEAR
MOV AL,OD1H
/ 20
OUT 64H/AL
;
MOV AL,ODFH
/- 20
OUT 60H,AL
;
RETN
ENABLE ENDP
/ 20
DISABLE PROC NEAR
MOV AL/OD1H
OUT 64H,AL
MOV AL,ODDH
; 20
OUT 60H/AL
RETN

593

594

ASSEMBLER.

DISABLE ENDP

;
; 6 (. 6 . 5 )
SOUND PROC NEAR
PUSH AX
PUSH

MOV AL,10110110
/
OUT 43H,AL
IN AL,61H
OR AL,3
.
/
OUT 61H,AL
MOV AX,1200
;
OUT 42H,AL
MOV AL,AH
OUT 42H,AL
MOV CX,OFFFFH
;
LOO: LOOP LOO
MOV CX,OFFFFH
;
L001: LOOP L001
/ , ..
IN AL,61H
AND AL,11111100B
OUT 61H,AL
POP CX
POP AX
RET
SOUND ENDP
;
PROG_INT PROC NEAR
;
; 0-7 20-27
MOV AH,20H
MOV AL,11H
OUT 20H,AL
JMP SHORT $+2
MOV AL,AH
OUT 21H,AL
JMP SHORT $+2
MOV AL,4
OUT 21H,AL
JMP SHORT $+2

26.

MOV AL,1

OUT 21H,AL
JMP SHORT $+2
MOV AL,OFFH
OUT 21H,AL
JMP SHORT $+2
;
; 8-15 28H-2FH
MOV A H , 2 8 H
MOV AL,11H
OUT OAOH,AL
JMP SHORT $+2
MOV AL,AH
OUT OA1H,AL
JMP SHORT $+2
MOV A L , 4

OUT OA1H,AL
JMP SHORT $+2
MOV AL,1

OUT OA1H,AL
JMP SHORT $+2
MOV AL,OFFH
OUT OA1H,AL
JMP SHORT $+2
RETN
PROG_INT ENDP
;
WHAT_CRT PROC NEAR
MOV A X , 4 0 H
'MOV ES,AX
MOV B X , E S : [ 4 A H ]
MOV COLUMNS,BL
MOV BL,ES:[84H]
INC BL
MOV ROWS,BL
MOV BX,ES:[63H]
CMP BX,3D4H
JNE NO_COLOR
;
MOV- SEL_BUF,(GDT_CRT-GDTO)
MOV SEG_BUF,OB800H
MOV ES,SEG_BUF
JMP SHORT EXIT
NO COLOR:

595

596

; MDA
MOV SEL_BUF,(GDT_MDA-GDTO)
MOV SEG_BUF,OBOOOH
MOV ES,SEG_BUF
EXIT:
RETN
WHAT_CRT ENDP
;
; ES ,
;, - X,Y
;SI -
; -
WRITE -PROC NEAR
/
PUSH AX
MOV DL, COLUMNS
MUL DL
ADD AX,BX
SHL AX,1
MOV DI,AX
POP AX
L01:
LODSB
CMP AL, 0
JZ EN
STOSW
JMP SHORT L01
EN:
RETN
WRITE ENDP
;
END_INT PROC NEAR
IN
AL,61H
MOV AH,AL
OR
AL,80H
OUT 61H,AL
XCHG AH,AL
OUT 61H,AL
MOV AL,20H
OUT 20H,AL
RETN
END_INT ENDP
KEY PROC NEAR
PUSH AX
CALL SOUND

ASSEMBLER.

26.

IN
AL,60H
CMP AL, 1
JNZ NO_ESC
CALL END_INT
MOV _DL,48
CALL SET_REAL ;
NO_ESC:
;

CALL END_INT
POP AX
IRET
KEY ENDP
;
; ,
TIMER PROC NEAR
CLI
PUSH AX
MOV AX,TIME
CMP AX,18
JNZ DAL
MOV TIME,0
CALL SOUND
JMP SHORT DAL1
DAL:
INC TIME
DAL1:
MOV AL,20H
OUT 20H,AL
POP AX
IRET
TIMER ENDP
/
INT1 PROC NEAR
PUSH AX
MOV AL,20H
OUT 20H,AL
POP AX
MOV _DL,50
IRET
INT1 ENDP
;
INT2 PROC NEAR
PUSH AX
MOV AL,20H

597

598

OUT 20H,AL
OUT OAH,AL
POP AX
MOV _DL,51
IRET
INT2 ENDP
;
EX0 PROC NEAR
MOV
DL,52 ;1-
CALL SOUND
CALL SOUND
JMP
SET_REAL
EXOO ENDP
EX01 PROC NEAR
MOV _DL,53 ;l-e
CALL SOUND
CALL SOUND
JMP SET_REAL
EX01 ENDP
EX02 PROC NEAR
MOV _DL,54 2-
CALL SOUND
CALL SOUND
JMP SET_REAL
EX02 ENDP
EX03 PROC NEAR
MOV _DL,55 ;3-
CALL SOUND
CALL SOUND
JMP SET_REAL
EX03 ENDP
EX04 PROC NEAR
MOV
DL,56 ;4-e
CALL SOUND
CALL SOUND
JMP
SET_REAL
EX04 ENDP
EX05 PROC NEAR
MOV _DL,57 ;5-e
CALL SOUND
CALL SOUND
JMP SET REAL
EX05 ENDP
EX06 PROC NEAR

ASSEMBLER.

26.

06
07

EX07
EX08

EX08
EX09

EX09
EXOA

EXOA
EXOB

EXOB
EXOC

EXOC
EXOD

MOV
DL, 58 ;6-
CALL SOUND
CALL SOUND
JMP SET_REAL
ENDP
PROC NEAR
MOV
DL/59 ;7-e
CALL SOUND
CALL SOUND
JMP SET_REAL
ENDP
PROC NEAR
MOV _DL,60 ; 8-
CALL SOUND
CALL SOUND
JMP SET_REAL
ENDP
PROC NEAR
MOV _DL,61 ;9-
CALL SOUND
CALL SOUND
JMP SET_REAL
ENDP
PROC NEAR
MOV _DL,62 ;AH-e
CALL SOUND
CALL SOUND
JMP
SET_REAL
ENDP
PROC NEAR
MOV _DL,63 ;BH-e
CALL SOUND
CALL SOUND
JMP
SET_REAL
ENDP
PROC NEAR
MOV _DL,64 ;CH-e
CALL SOUND
CALL SOUND
JMP
SET_REAL
ENDP
PROC NEAR
MOV _DL,65 ;DH-e
CALL SOUND

599

ASSEMBLER.

600

EXOD
EXOE

EXOE
EXOF

EXOF
EX10

EX10
EX11

EX11
EX12

EX12
EX13

EX13
EX14

CALL SOUND
JMP
SET_REAL
ENDP
PROC NEAR
MOV _DL,66 ;-
CALL SOUND
CALL SOUND
JMP SET_REAL
ENDP
PROC NEAR
MOV _DL,67 ;FH-e
CALL SOUND
CALL SOUND
JMP SET_REAL
ENDP
PROC NEAR
MOV _DL,68 ;10H-e
CALL SOUND
CALL SOUND
JMP
SET_REAL
ENDP
PROC NEAR
MOV _DL,69 ;11-
CALL SOUND
CALL SOUND
JMP
SET_REAL
ENDP
PROC NEAR
MOV _DL,70 ;12H-e
CALL SOUND
CALL SOUND
JMP
SET_REAL
ENDP
PROC NEAR
MOV _DL,71 ;13H-e
CALL SOUND
CALL SOUND
JMP
SET_REAL
ENDP
PROC NEAR
MOV _DL,72 ;14H-e
CALL SOUND
CALL SOUND
JMP SET REAL

26.

14
15

15
16

16
17

17
18

18
19

19
1

EX1A
EX1B

EX1B
EX1C

ENDP
PROC NEAR
MOV _DL,73 ;15H-e
CALL SOUND
CALL SOUND
JMP SET REAL
ENDP
PROC NEAR
MOV
DL,74 ;16H-e
CALL SOUND
CALL SOUND
JMP
SET_REAL
ENDP
PROC NEAR
MOV _DL,75 17H-e
CALL SOUND
CALL SOUND
JMP SET_REAL
ENDP
PROC NEAR
MOV _DL,76 ;18H-e
CALL SOUND
CALL SOUND
JMP SET_REAL
ENDP
PROC NEAR
MOV _DL,77 ;19H-e
CALL SOUND
CALL SOUND
JMP SET_REAL
ENDP
PROC NEAR
MOV _DL,78 ;1-
CALL SOUND
CALL SOUND
JMP SET_REAL
ENDP
PROC NEAR
MOV _DL,79 ; 1-
CALL SOUND
CALL SOUND
JMP SET_REAL
ENDP
PROC NEAR

601

602

EX1C

ASSEMBLER.

MOV
DL,80 ;ICH-e
CALL SOUND
CALL SOUND
JMP SET_REAL
ENDP

EX1D PROC NEAR


MOV _DL,81 ;lDH-e
CALL SOUND
CALL SOUND
JMP
SET_REAL
EX1D ENDP
EX1E PROC NEAR
MOV _DL,82 ;1-
CALL SOUND
CALL SOUND
JMP
SET_REAL
EX1E ENDP
EXIF PROC NEAR
MOV _DL,83 ;lFH-e
CALL SOUND
CALL SOUND
JMP SET_REAL
EXIF ENDP
PAUSE PROC
PUSH CX
MOV CX,550
PL:
PUSH CX
MOV CX,OFFFFH
PL1:
LOOP PL1
POP CX
LOOP PL
POP CX
RETN
PAUSE ENDP
;
;
SET_REAL PROC NEAR
CLI
CALL DISABLE
;
MOV SP,SP

26.

;
MOV AL,OFEH
OUT 64H,AL
; SHUT_DOWN_RETURN
_WAIT:
JMP _WAIT
;
;
SHUT_DOWN_RETURN:
/
MOV AX,DATA
MOV DS,AX
MOV SS,_SS
MOV SP,_SP
MOV ES,_ES
;
MOV AX,
OUT 70H,AL
/
XOR AL,AL
OUT
21H,AL
OUT OA1H,AL
/
STI
MOV DL,_DL
MOV , 2
INT 21H
MOV ,4
INT 21H
RETN
SET_REAL ENDP
;
INI_PROT PROC
;
; GDT
MOV
MOV
MOV
SHR
SHL
MOV
MOV

AX,DATA
DS,AX
DL,AH
DL,4
AX,4
SI,AX
DI,DX

603

604

ASSEAffLER.

GDT
ADD AX,OFFSET GOTO
ADC DL,0

MOV
MOV
MOV
MOV
MOV

MOV
MOV
MOV
SHR
SHL
MOV
MOV
MOV
MOV

BX,OFFSET GDT_GDT
WORD PTR [BX] ,GDT_SIZE-1
[BX+2],AX
[BX+4],DL
BYTE PTR [BX+5],DATA_AC

BX,OFFSET GDT_DS
AX,SI
DX,DI
WORD PTR [BX] ,DSEG_SIZE-1
[BX+2],AX
[BX+4],DL
BYTE PTR [BX+5],DATA_AC

BX,OFFSET GDT_CS
AX,CS
DL,AH
DL,4
AX,4
WORD PTR [BX],CSEG_SIZE-1
[BX+2],AX
[BX+4],DL
BYTE PTR [BX+5],CODE AC

MOV
MOV
MOV
SHR
SHL
MOV
MOV
MOV
MOV

BX,OFFSET GDT_SS
AX,SS
DL,AH
DL,4
AX,4
WORD PTR [BX],400-1
[BX+2],AX
[BX+4],DL
BYTE PTR [BX+5],DATA AC

MOV
MOV
MOV
MOV
MOV

BX,OFFSET
WORD PTR
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV
MOV

GDT_CRT
[BX],3999
[BX+2],8000H
[BX+4],OBH
[BX+5],DATA AC

26.

MOV
MOV
MOV
MOV

MOV
MOV
MOV
MOV
MOV
MOV

BX,OFFSET GDT_MDA
WORD PTR [BX],3999
BYTE PTR [BX+4],OBH
BYTE PTR [BX+5],DATA_AC

BX,OFFSET GDT_IDT
AX,DS
DL,AH
DL,4
AX,4
AX,OFFSET EXC_00
DL,0
WORD PTR [BX],IDT_SIZE-1
WORD PTR [BX+2],AX
BYTE PTR [BX+4],DL
BYTE PTR [BX+5],IDT_AC

AX,OFFSET EXOO
BX,OFFSET EXC_00
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET EX01
BX,OFFSET EXC_01
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET EX02
BX,OFFSET EXC_02
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP_AC

MOV
MOV
MOV
SHR
SHL
ADD
ADC
MOV
MOV
MOV
MOV

MOV AX,OFFSET EX03


MOV BX,OFFSET EXC_03
MOV [BX],AX
MOV WORD PTR

[BX+2],(GDT_CS-GDTO)

MOV BYTE PTR [ B X + 4 ] , 0


MOV BYTE PTR [BX+5],TRAP AC

605

606

ASSEMBLER.

MOV AX,OFFSET 04
MOV BX,OFFSET EXC_04
MOV [ B X ] , A X

MOV WORD PTR [BX+2], (GDT_CS-GDTO)


MOV BYTE PTR [BX+4],0
MOV BYTE PTR [BX+5],TRAP_AC
MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

EX05
EXC_05

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET EX07
BX,OFFSET EXC_07
[BX],AX
WORD PTR [BX+2],(GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5] ,TRAP_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

[BX+2],(GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC
EX06
EXC_06
[BX+2],(GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC

EX08
EXC_08
[BX+2], (GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC
EX09
EXC_09
[BX+2], (GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC

MOV AX,OFFSET EXOA


MOV BX,OFFSET EXC OA

26.

MOV
MOV
MOV
MOV

[],
WORD PTR [+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET EXOB
BX,OFFSET EXC_OB
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5] ,TRAP_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV

AX,OFFSET EX10
BX,OFFSET EXC_10
[BX],AX
WORD PTR [BX+2], (GOT CS-GDTO)

EXOC
EXC_OC
[BX+2], (GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC
EXOD
EXC_OD
[BX+2],(GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC
EXOE
EXC_OE
[BX+2], (GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC
EXOF
EXC_OF
[BX+2],(GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC

607

608

ASSEMBLER.

MOV BYTE PTR [BX+4],0


MOV BYTE PTR [BX+5],TRAP AC
MOV AX,OFFSET EX11
MOV BX,OFFSET EXC_11
MOV [ B X ] , A X
MOV WORD PTR [BX+2] , (GDT_CS-GDTO)
MOV BYTE PTR [BX+4],0
MOV BYTE PTR [BX+5],TRAP_AC
MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

EX12
EXC_12

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET EX16
BX,OFFSET EXCJL6
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP AC

[BX+2],(GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC
EX13
EXC_13
[BX+2],(GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC
EX14
EXC_14
[BX+2], (GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC
EX15
EXC_15
[BX+2], (GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC

26.

/ "~

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET EX17
BX,OFFSET EXC_17
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

~"

EX18
EXC_18

[BX+2],(GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET EX1A
BX,OFFSET EXC_1A
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP_AC

MOV
MOV
MOV
MOV
MOV
MOV

MOV
MOV
MOV
MOV
MOV
MOV

[BX+2],(GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC

__ _.

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

_ _.

EX19
EXC_19

MOV
MOV
MOV
MOV
MOV
MOV

..

EX1B
EXC_1B

[BX+2],(GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC
.

AX,OFFSET EX1C
BX,OFFSET EXC_1C
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP_AC

20 - 4072

MOV AX,OFFSET EX1D


MOV BX,OFFSET EXC_1D

609

610

ASSEMBLER.

MOV [],
MOV WORD PTR [BX+2] , (GDT_CS-GDTO)
MOV BYTE PTR [BX+43,0
MOV BYTE PTR [BX+5],TRAP AC
MOV AX,OFFSET EX1E
MOV BX,OFFSET EXC_1E
MOV [BX],AX
MOV WORD PTR [BX+2] , (GDT_CS-GDTO)
MOV BYTE PTR [BX+4],0
MOV- BYTE PTR [BX+5 ] , TRAP_AC
MOV
MOV
MOV
MOV
MOV
MOV
MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET EXIF
BX,OFFSET EXC_1F
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP_AC

AX,OFFSET TIMER
BX,OFFSET INT_20
[BX],AX
WORD PTR [BX+2], (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],INT AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

KEY
INT_21
[BX+2], (GDT_CS-GDTO)
[BX+4],0
[BX+5],INT_AC
INT1
INT_22
[BX+2], (GDT_CS-GDTO)
[BX+4],0
[BX+5],INT_AC

MOV AX,OFFSET INT1


MOV BX,OFFSET INT_23
MOV [BX],AX
MOV WORD PTR [BX+2], (GOT CS-GDTO)

26.

MOV BYTE PTR [+4],0


MOV BYTE PTR [BX+5],INT AC

20'

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET INT1
BX,OFFSET INT_24
[BX],AX
WORD PTR [BX+2], (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],INT_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

INT1
INT_25
[BX+2], (GDT_CS-GDTO)
[BX+4],0
[BX+5],INT_AQ
INT1
INT_26
[BX+2], (GDT_CS-GDTO)
[BX+4],0
[BX+5],INT_AC
INT1
INT_27
[BX+2], (GDT_CS-GDTO)
[BX+4],0
[BX+5],INT_AC
INT2
INT_28
[BX+2],(GDT_CS-GDTO)
[BX+4],0
[BX+5],INT_AC
INT2
INT_29
[BX+2], (GDT_CS-GDTO)
[BX+4],0
[BX+5],INT AC

611

612

ASSEMBLER.

MOV AX,OFFSET INT2


MOV BX,OFFSET INT_2A
MOV [ B X ] , A X

MOV WORD PTR [BX+2],(GDT_CS-GDTO)


MOV BYTE PTR [BX+4],0
MOV BYTE PTR [BX+5],INT_AC
MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

INT2
INT_2B

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET INT2
BX,OFFSET INT_2C
[BX],AX
WORD PTR [BX+2J, (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],INT_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET INT2
BX,OFFSET INT_2E
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],INT_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET INT2
BX, OFF.SET INT_2F
[BX],AX
WORD PTR [BX+2], (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],INT AC

[BX+2], (GDT_CS-GDTO)
[BX+4],0
[BX+5],INT_AC

INT2
INT_2D
[BX+2], (GDT_CS-GDTO)
[BX+4],0
[BX+5],INT_AC

26.

613


PUSH DS
MOV A X , 4 0 H
MOV DS,AX
MOV WORD PTR D S : [ 6 7 H ] , O F F S E T SHUT_DOWN_RETURN
MOV D S : [ 6 9 H ] , C S
POP DS
; OFH CMOS 5
;
CLI
MOV AL,8FH
OUT 70H,AL
JMP $+2
MOV A L , 5
OUT 71H,AL
RETN
INI_PROT ENDP
CSEG_SIZE=$-BEGIN
CODE ENDS
END BEGIN
;

. 20.3. ,
.
. 20.3. ,
,
. , ,
INI_PROT. .
_DL. . . .
ESC
. , , , . ,
_WAI - , .
, , : MOV WORD PTR
CS:_WAIT,90.
INT. , .
, / . .
, , INT.
. , , . ? -, 386-

614

ASSEMBLER,

. -, , .
386- .
0 CRO (. 20). , , 286- .
. ,
386- 486- (. [19,22,25]). :
1. , :
- , , .. ;
- PG CRO;
- CR3 .
,
.
2. , 64.
CS , .
CS .
3. SS, DS, ES, FS GS , :
- 64,
- (G=0),
- ,
- ,
- ,
- - .
SS, DS, ES . FS, GS .
4. .
5. CRO.
6. ,
.
7. . , . , .
8. .
9. .
. , ,
, . :
1. - , ,
DOS. , , .

26.

615

2. .
3. - DOS- , .
. ,
.
, ,
, , , . ,
Windows 3.1.
/ 386-
.386
/
;10000000 -
;00011000 -
;00010000 -
;00000100 -
;00000100 -
;00000010 -
;00000110 -
;00000111 -
;
DATA_AC
EQU 10010010
;
CODE_AC
EQU 10011000B
;
STACK_AC EQU 10010110B
; IDT
IDT_AC
EQU 10010010B
;
INT_AC
EQU 10000110B
/
TRAP_AC
EQU 10000111B
;
ST1 SEGMENT STACK 'STACK'
DB 100 DUP(?)
ST1 ENDS
;
DATA SEGMENT
BEG_DATA=$
_SS DW ?
_ES DW ?
IDTT DQ ?
MSG DB ' .',

616

ASSEMBLER.

MSG1 DB ' . ',0


MSG2 DB ' . ',0
MSG3 DB ' . ',
PATH DB 'PROT.TXT',
BUF DB ' '
_DL DB 0
/
_ DW ?
/
COLUMNS DB ?
/
DB ?
?
/
ROWS
SEL_BUF DW ?
;
SEG BUF DW
/
/
/
GOTO
DQ
/ GDT
GDT_GDT DQ
/
GDT_CS
DQ
/
GDT_DS
DQ
/
GDT_SS
DQ
/
GDT_CRT DQ
/
GDT_MDA DQ
;
GDT_IDT DQ
GDT_SIZE = $-GDTO
/
/
IDT BEG=$
_00
DQ 0
_01
DQ 0
_02
DQ 0
_0 3
DQ 0
_04
DQ 0
_05
DQ 0
_0 6
DQ 0
_07
DQ 0
_08
DQ 0
_0 9
DQ 0
_
DQ 0
_
DQ 0

26.

_
EXC_OD
_
EXC_OF
_10
_11
_12
_13
_14
_15
_1
_17
_18
_19
_1
_1
_1
EXC__1D
_1
EXC_1F

DQ
DQ
DQ
DQ
DQ
DQ
DQ
DQ
DQ
DQ
DQ
DQ
DQ
DQ
DQ
DQ
DQ 0
DQ
DQ
DQ

;
INT_20
DQ 0 ;
INT_21
DQ 0 ;
INT_22
INT_23
INT_24
INT_25
INT_26
INT_27
INT_28
INT_29
INT_2A
INT_2B
INT_2C
INT_2D
INT_2E
INT_2F

DQ
DQ
DQ
DQ
DQ
DQ
DQ
DQ
DQ
DQ
DQ
DQ
DQ
DQ

0
0
0
0
0
0
0
0
0
0
0
0
0

IDT SIZE=$-IDT BEG

DSEG_SIZE=$-BEG_DATA ;
DATA ENDS

;
CODE SEGMENT PUBLIC PARA USE16
ASSUME CS:CODE, DS:DATA, SS:ST1

617

618

ASSEMBLER.

BEGIN:
MOV AX,DATA
MOV DS,AX
MOV _DL,0

;
MOV _ES,ES
MOV _SS,SS
SIDT QWORD PTR IDTT
CALL WHAT_CRT
;
CALL SETJPROT
;
MOV AH,07H
CALL CLS
;
MOV BX, 0 / X
MOV AX,2 ; Y
;
MOV SI,OFFSET MSG
MOV ,4 /
CALL WRITE
/
;
CALL SET_REAL
MOV AH,3CH
LEA DX,PATH
MOV CX,0
INT 21H
MOV _AX,AX
CALL SET_PROT
/
MOV BX,0
/ X
MOV AX,3
/ Y
/
MOV SI,OFFSET MSG1
MOV AH,41H /
CALL WRITE
/ ,
/
MOV BYTE PTR CS:_END,AL
/
CALL SET_REAL
MOV BX, AX

26.

LEA DX,BUF
MOV ,13
MOV ,4
INT 21
CALL SET_PROT
;
MOV BX,0
;
MOV AX,4
;
;
MOV SI,OFFSET MSG2
MOV AH,41H
/
CALL WRITE
;
CALL SET_REAL
MOV BX,_AX
MOV ,
INT 21H
CALL SET_PROT
;
MOV BX,0
;
MOV AX,5
/
;
MOV SI,OFFSET MSG3
MOV AH,41H
/
CALL WRITE
;
CALL SET_REAL
MOV _DL,48
_END:
MOV DL,_DL
MOV AH, 2
INT 21H
MOV ,4
INT 21H
;
/
SET_REAL PROC NEAR
CLI
MOV AX,DS
MOV ES,AX
MOV AX,CRO
AND AX,OFFFEH
/
MOV CRO,AX

X
Y

X
Y

619

620

ASSEMBLER.

/--
.
JM.P FAR FLUSH,
DB

DW
DW

OFFSET FLUSH
SEG FLUSH

FLUSH:
/
CALL PROG_INT1
/
MOV AX,DATA
MOV DS,AX
MOV SS,_SS
MOV ES,_ES
/
LIDT QWORD PTR IDTT
/ 20
CALL DISABLE
/
MOV AX,
OUT 70H,AL
STI
CMP
JNZ

_DL,0
_END

RETN
SET_REAL ENDP
/
SET_PROT PROC NEAR
/
CALL INI_PROT
CLI
/ 20
CALL ENABLE
/
CALL PROG_INT
/
LIDT QWORD PTR GDT_IDT
;
LGDT QWORD PTR GDT_GDT
/
MOV AX,CRO
OR AX,1
MOV CRO,AX
;
JMP FAR FLUSH1,

26.

DB

DW
OFFSET FLUSH1
DW
(GDT_CS-GDTO)
FLUSH1:
;
MOV AX,(GDT_DS-GDTO)
MOV DS,AX
MOV AX,SEL_BUF
MOV ES,AX
MOV AX,(GDT_SS-GDTO)
MOV SS,AX
;
XOR AL,AL
OUT 21H,AL
OUT OA1H ,AX
/
STI
RETN
SET_PROT ENDP
; 20
ENABLE PROC NEAR
MOV AL,OD1H
; 20
OUT 64H/AL
;
MOV AL,ODFH
; 20
OUT 60H,AL
/
RETN
ENABLE ENDP
/ 20
DISABLE PROC NEAR
MOV AL,OD1H
OUT 64H,AL
MOV AL,ODDH
; 20
OUT 60H,AL
RETN
DISABLE ENDP
;
PROG_INT PROC NEAR
;
; 0-7
;20-27
MOV ,20
MOV AL,11H
OUT 20H,AL
JMP SHORT $+2

621

622

ASSEMBLER.

MOV AL,AH
OUT 21H,AL
JMP SHORT $+2
MOV AL,4
OUT 21H,AL
JMP SHORT $+2
MOV AL,1
OUT 21H,AL
JMP SHORT $+2
MOV AL,OFFH
OUT 21H,AL
JMP SHORT $+2
;
/ 8-15
;28H-2FH
MOV AH,28H
MOV AL,11H
OUT OAOH,AL
JMP SHORT $+2
MOV AL,AH
OUT OA1H,AL
JMP SHORT $+2
MOV AL,2
OUT OA1H,AL
JMP SHORT $+2
MOV AL,1
OUT OA1H,AL
JMP SHORT $+2
MOV AL,OFFH
OUT OA1H,AL
JMP SHORT $+2
RETN
PROG_INT ENDP
/
PROG_INT1 PROC NEAR
;
/ 0-7
MOV AL,11H
OUT 20H,AL
JMP SHORT $+2
MOV AL, 8
OUT 21H,AL
JMP SHORT $+2
MOV AL,4

26.

OUT 21H,AL
JMP SHORT $+2
MOV AL,1
OUT 21H,AL
JMP SHORT $+2
;
/ 8-15
MOV AL,11H
OUT OAOH,AL
JMP SHORT $+2
MOV AL,70H
OUT OA1H,AL
JMP SHORT $+2
MOV AL,2
OUT OA1H,AL
JMP SHORT $+2
MOV AL,1
OUT OA1H,AL
JMP SHORT $+2
RETN
PROG_INT1 ENDP
;
WHAT_CRT PROC NEAR
MOV AX,4OH
MOV ES,AX
MOV BX,ES:[4AH]
MOV COLUMNS,BL
MOV BL,ES:[84H]
INC BL
MOV ROWS,BL
MOV BX,ES:[63H]
CMP BX,3D4H
JNE NO_COLOR
/
MOV SEL_BUF,(GDT_CRT-GDTO)
MOV SEG_BUF,OB800H
MOV ES,SEG_BUF
JMP SHORT EXIT
NO_COLOR:
; MDA
MOV SEL_BUF,(GDT_MDA-GDTO)
MOV SEG_BUF,OBOOOH
MOV ES,SEG_BUF
EXIT:
RETN

623

624

WHAT_CRT ENDP

;
; ES ,
;, - X , Y
;SI -
; -
WRITE PROC NEAR
;
PUSH AX
MOV DL,COLUMNS
MUL DL
ADD AX,BX
SHL AX,1
MOV DI,AX
POP AX
L01:
LODSB
CMP AL,0
JZ EN
STOSW
JMP SHORT L01
EN:
RETN
WRITE ENDP
;
END_INT PROC NEAR
IN
AL,61H
MOV AH,AL
OR
AL,80H
OUT 61H,AL
XCHG AH,AL
OUT
61H,AL
MOV AL,20H
OUT 20H,AL
RETN
END_INT ENDP
KEY PROC NEAR
PUSH AX
;

CALL END_INT
POP AX
IRET
KEY ENDP

ASSEMBLER.

26.

;
/ ,
TIMER PROC NEAR

MOV AL,20H
OUT 20H,AL
IRET
TIMER ENDP
;
INT1 PROC NEAR
PUSH AX
MOV AL,20H
OUT 20H,AL
POP AX
MOV _DL,50
IRET
INT1 ENDP
;
INT2 PROC NEAR
PUSH AX
MOV AL,20H
OUT 20H,AL
OUT OAH,AL
POP AX
MOV _DL,51
IRET
INT2 ENDP
;
EX 0 PROC NEAR
MOV _DL,52 ;0-e
JMP SET_REAL
EXOO ENDP
EX01 PROC NEAR
MOV _DL,53 ;l-e
JMP SET_REAL
EX01 ENDP
EX02 PROC NEAR
MOV _DL,54 ;2-e
JMP SET_REAL
EX02 ENDP
EX03 PROC NEAR
MOV _DL,55 ;3-e
JMP SET_REAL
EX03 ENDP

625

ASSEMBLER.

626

04 PROC
MOV
JMP
04 ENDP
05 PROC
MOV
JMP
05 ENDP
06 PROC
MOV
JMP
06 ENDP
07 PROC
MOV
JMP
07 ENDP
08 PROC
MOV
JMP
08 ENDP
09 PROC
MOV
JMP
09 ENDP
PROC
MOV
JMP
ENDP
PROC
MOV
JMP
ENDP
PROC
MOV
JMP
ENDP
EXOD PROC
MOV
JMP
EXOD ENDP
PROC
MOV
JMP
ENDP

NEAR
_DL, 56 ;4-
SET_ REAL
NEAR
_DL, 57 ; 5-
SET_ REAL
NEAR
_DL, 58 ; 6-
SET_ REAL
NEAR
_DL, 59 ;7-
SET_ REAL
NEAR
_DL, 60 ;8-
SET_ REAL
NEAR
_DL, 61 ; 9-
SET_ REAL
NEAR
_DL, 62 ;AH-e
SET_ REAL
NEAR
_DL, 63 ;BH-e
SET_ REAL
NEAR
_DL, 64 ;CH-e
SET_ REAL
NEAR
_DL, 65 ;DH-e
SET_ REAL
NEAR
_DL, 66 ;. EH-e
SET_ REAL

26.

EXOF PROG
MOV
JMP
EXOF ENDP
EX10 PROC
MOV
JMP
EX10 ENDP
EX 11 PROC
MOV
JMP
EX11 ENDP
EX12 PROC
MOV
JMP
EX12 ENDP
EX13 PROC
MOV
JMP
EX13 ENDP
EX14 PROC
MOV
JMP
EX14 ENDP
EX15 PROC
MOV
JMP
EX15 ENDP
EX 16 PROC
MOV
JMP
EX16 ENDP
EX 17 PROC
MOV
JMP
EX17 ENDP
EX18 PROC
MOV
JMP
EX18 ENDP
EX19 PROC
MOV
JMP
EX19 ENDP

NEAR.
_DL,67 ;FH-e
SET_REAL
NEAR
_DL,68 ;10H-e
SET_REAL
NEAR
_DL,69 ;11-
SET_REAL
NEAR
_DL,70 ;12H-e
SET_REAL
NEAR
_DL,71 ;13H-e
SET_REAL
NEAR
_DL,72 ;14H-e
SET_REAL
NEAR
_DL,73 ;15H-e
SET_REAL
NEAR
_DL,74 ;16H-e
SET_REAL
NEAR
_DL,75 ;17H-e
SET_REAL
NEAR
_DL,76 ;18H-e
SET_REAL
NEAR
_DL,77 ;19H-e
SET_REAL

627

628

ASSEMBLER.

1 PROC NEAR
MOV _DL,78 ;lAH-e
JMP SET_REAL
EX1A ENDP
EXIB PROC NEAR
MOV _DL,79 ;IBH-e
JMP SET_REAL
EX1B ENDP
EX1C PROC NEAR
MOV _DL,80 ;1-
JMP
SET_REAL
EX1C ENDP
EXID PROC NEAR
MOV _DL,81 ;lDH-e
JMP
SET_REAL
EX1D ENDP
EXIE PROC NEAR
MOV _DL,82 ;1-
JMP SET_REAL
EX1E ENDP
EXIF PROC NEAR
MOV _DL,83 ;lFH-e
JMP SET_REAL
EXIF ENDP
PAUSE PROC
PUSH CX
MOV CX,550
PL:
PUSH CX
MOV
CX,OFFFFH
PL1:
LOOP PL1
POP CX
LOOP PL
POP CX
RETN
PAUSE ENDP
;
;
INI_PROT PROC
;
; GDT

26.

MOV AX,DATA
MOV DS,AX
MOV DL,AH
SHR D L , 4
SHL A X , 4

MOV SI,AX
MOV DI,DX
GDT
ADD AX,OFFSET GOTO
ADC DL,0

MOV
MOV
MOV
MOV
MOV

MOV
MOV
MOV
SHR
SHL
MOV
MOV
MOV
MOV

BX,OFFSET GDT_GDT
WORD PTR [BX],OFFFFH
[BX+2],AX
[BX+4],DL
BYTE PTR [BX+5],DATA_AC

BX,OFFSET GDT_DS
AX,SI
DX,DI
WORD PTR [BX],OFFFFH
[BX+2],AX
[BX+4],DL
BYTE PTR [BX+5],DATA_AC

BX,OFFSET GDT_CS
AX,CS
DL,AH
DL,4
AX,4
WORD PTR [BX],OFFFFH
[BX+2],AX
[BX+4],DL
BYTE PTR [BX+5],CODE AC

MOV
MOV
MOV
SHR
SHL
MOV
MOV
MOV
MOV

BX,OFFSET GDT_SS
AX,SS
DL,AH
DL,4
AX,4
WORD PTR [BX],OFFFFH
[BX+2],AX
[BX+4],DL
BYTE PTR [BX+5],DATA AC

MOV
MOV
MOV
MOV
MOV
MOV
MOV

629

630

ASSEMBLER.

MOV
MOV
MOV
MOV
MOV

BX,OFFSET
WORD PTR
WORD PTR
BYTE PTR
BYTE PTR

GDT_CRT
[BX],3999
[BX+2],8000H
[BX+4],OBH
[BX+5],DATA AC

MOV BX,OFFSET GDT_MDA


MOV WORD PTR [ B X ] , 3 9 9 9
MOV BYTE PTR [BX+4],OBH

MOV BYTE PTR [BX+5],DATA_AC



MOV
MOV
MOV
SHR
SHL
ADD
ADC

BX,OFFSET GDT_IDT
AX,DS
DL,AH
DL,4
AX,4
AX,OFFSET EXC_00
DL,0

MOV
MOV
MOV
MOV

WORD
WORD
BYTE
BYTE

MOV
MOV
MOV
MOV
MOV
MOV

PTR [BX],IDT_SIZE-1
PTR [BX+2],AX
PTR [BX+4],DL
PTR [BX+5],IDT_AC

AX,OFFSET EXOO
BX,OFFSET EXC_00
[BX],AX
WORD PTR [BX+2], (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET EX01
BX,OFFSET EXC_01
[BX],AX
WORD PTR [BX+2], (GDT_CS-GDTO)
BYTE PTR [BX+4 ] , 0
BYTE PTR [BX+5],TRAP_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

EX02
EXC_02
[BX+2], (GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP AC

26.

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET EX03
BX,OFFSET EXC_03
[],
WORD PTR [BX+2], (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET EX04
BX,OFFSET EXC_04
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET EX06
BX,OFFSET EXC_06
[BX],AX
WORD PTR [BX+2], (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE.PTR
BYTE PTR

EX05
EXC_05
[BX+2], (GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC

EX07
EXC_07
[BX+2], (GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC
EX08
EXC_08
[BX+2], (GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC

MOV AX,OFFSET EX09


MOV BX,OFFSET EXC 09

631

632

ASSEMBLER.

MOV
MOV
MOV
MOV

[BX],AX
WORD PTR [BX+2], (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET EXOA
BX,OFFSET EXC_OA
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET EXOD
BX,OFFSET EXCJDD
[BX],AX
WORD PTR [BX+2], (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET EXOE
BX,OFFSET EXC_OE
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5] ,TRAP_AC

MOV
MOV
MOV
MOV

AX,OFFSET EXOF
BX,OFFSET EXC_OF
[BX],AX
WORD PTR [BX+2], (GOT CS-GDTO)

EXOB
EXCJDB
[BX+2],(GDT_CS-GDTO)
[BX+4],0
[BX+5J,TRAP_AC
EXOC
EXC_OC
[BX+2],(GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC

26.

MOV BYTE PTR [ + 4 ] , 0


MOV BYTE PTR [BX+5],TRAP AC
MOV AX,OFFSET EX10
MOV BX,OFFSET EXC_10
MOV [BX],AX
MOV WORD PTR [BX+2] , (GDT_CS-GDTO)
MOV BYTE PTR [BX+4],0
MOV BYTE PTR [BX+5],TRAP_AC
MOV AX,OFFSET
MOV BX,OFFSET
. MOV [BX],AX
MOV WORD PTR
MOV BYTE PTR
MOV BYTE PTR

EX11
EXC_11
[BX+2] , (GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET EX12
BX,OFFSET EXC_12
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET EX14
BX,OFFSET EXC_14
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

EX13
EXC_13
[BX+2],(GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC

EX15
EXC_15
[BX+2],(GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP AC

633

634

ASSEMBLER.

MOV AX,OFFSET EX16


MOV BX,OFFSET EXC_16
MOV [BX],AX

MOV WORD PTR [BX+2],(GDT_CS-GDTO)


MOV BYTE PTR [BX+4],0
MOV BYTE PTR [BX+5],TRAP_AC
MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

EX17
EXC_17

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET EX19
BX,OFFSET EXC_19
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

[BX+2],(GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC
EX18
EXC_18
[BX+2], (GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC

EX1A
EXC_1A
[BX+2], (GDT_CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC
EX1B
EXC_1B
[BX+2], (GDT__CS-GDTO)
[BX+4],0
[BX+5],TRAP_AC

MOV AX,OFFSET EX1C


MOV BX,OFFSET EXC 1C

26.

MOV
MOV
MOV
MOV

[],
WORD PTR [+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET EX1D
BX,OFFSET EXC_1D
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET EX1E
BX,OFFSET EXC_1E
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP_AC

MOV
MOV
MOV
MOV
MOV
MOV
MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET EXIF
BX,OFFSET EXC_1F
[BX],AX
WORD PTR [BX+2], (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],TRAP_AC
-
AX,OFFSET TIMER
BX,OFFSET INT_20
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],INT AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET KEY
BX,OFFSET INT_21
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],INT_AC

MOV
MOV
MOV
MOV

AX,OFFSET INT1
BX,OFFSET INT_22
[BX],AX
WORD PTR [BX+2], (GOT CS-GDTO)

635

636

ASSEMBLER.

MOV BYTE PTR [ B X + 4 ] , 0


MOV BYTE PTR [ B X + 5 ] , I N T AC
MOV AX,OFFSET INT1
MOV BX,OFFSET INT_23
MOV [ B X ] , A X

MOV WORD PTR [BX+2] , (GDT_CS-GDTO)


MOV BYTE PTR [BX+4],0
MOV BYTE PTR [BX+5],INT_AC
MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

INT1
INT_24

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET INT1
BX,OFFSET INT_25
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],INT_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET INT1
BX,OFFSET INT_26
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],INT_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET INT1
BX,OFFSET INT_27
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],INT_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET INT2
BX,OFFSET INT_28
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],INT AC

[BX+2], (GDT_CS-GDTO)
[BX+4],0
[BX+5],INT_AC

26.

MOV AX,OFFSET INT2


MOV BX,OFFSET INT_29
MOV [ B X ] , A X
MOV WORD PTR [BX+2], (GDT_CS-GDTO)
MOV BYTE PTR [BX+4],0
MOV BYTE PTR [BX+5],INT_AC
MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET INT2
BX,OFFSET INT_2A
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],INT_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET INT2
BX,OFFSET INT_2B
[BX],AX
WORD PTR [BX+2], (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],INT_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET
BX,OFFSET
[BX],AX
WORD PTR
BYTE PTR
BYTE PTR

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET INT2
BX,OFFSET INT_2D
[BX],AX
WORD PTR [BX+2], (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],INT_AC

MOV
MOV
MOV
MOV
MOV
MOV

AX,OFFSET INT2
BX,OFFSET INT_2E
[BX],AX
WORD PTR [BX+2] , (GDT_CS-GDTO)
BYTE PTR [BX+4],0
BYTE PTR [BX+5],INT AC

INT2
INT_2C
[BX+2],(GDT_CS-GDTO)
[BX+4],0
[BX+5],INT_AC

637

638

ASSEMBLER.

MOV AX,OFFSET INT2


MOV BX,OFFSET INT_2F
MOV [BX],AX
MOV WORD PTR [BX+2],(GDT_CS-GDTO)
MOV BYTE PTR [BX+4],0
MOV BYTE PTR [BX+5] , INT_AC
RETN
INI_PROT ENDP
;
; ES ,
; -
CLS PROC
MOV ,2000
MOV AL,32
XOR DI, DI
L2:
STOSW
LOOP L2
RETN
CLS ENDP
CSEG_SIZE=$-BEGIN
CODE ENDS
END BEGIN
Puc. 20.4. ,
386- .

27.
VGA- SVGA-.
, , ,

!
.. . .
10 640*350* 16. . VGA
.
, . , . , . , , . , SVGA,
.
..
10.

I. VGA.
.

.
1.
.
2. : , ,
.
3. : .
( ) .
4. . (
), , , .
5. : .
6. . , . VGA- 256 . Super
VGA 1 .

.

, . 5070 . ,

ASSEMBLER.

640

. ()
- , , (RGB - Red
Green Blue). , , ,
.
. , .
.
( ), , , ,
. , ,
( ),
. , . ,
.
.
, , . . (
). . , , ,
. . (. ).


VGA-. : , .

( )
, ,
.
. : , D, - .

27. VGA SVGA

641

.
. MOR - Miscellaneous Output
Register.
2, - .
:
0 - -. - , 1 - .
1 - . 0,
.
2,3 - :
0 - 640 320 ,
0 1 - 720 ,
1 0 - ,
1 1 - .
4 - .
5 - (64 ).
6,7 - :
0 - ,
0 1 - 350 ,
1 0 - 400 ,
1 1 - 480 .
. Feature Control Register - FCR.
3DAH, .
, 3 .
0. ISRO - Input Status Register.
2.
:
4 - - .
7 - . .
.
1. ISR1 - Input Status Register.
3DAH.
:
3 - . 1 .
VGA .
VGA. VGA_ER - VGA Enable Register.
.
0 , .

.
8 3D4H, 3D5H.
4, 5.
21 - 4072

642

ASSEMBLER.

, , , 0000:0463.
. .
. - Horizontal Total Register.
0. , . 5
, , .
. HDER - Horizontal
Display Enable End Register. 1. . , .
. SHBR - Start
Horizontal Blank Register. 2.
.
. EHBR - End
Horizontal Blank Register. 3.
:
0-4 - ,
.
5-6 - .
7 - .
. SHRR - Start Horizontal
Retrace Register. 4.
.
. EHRR - End Horizontal
Retrace Register. 5.
:
0-4 - , .
5-6 - .
7 - .
. VTR - Vertical Total Register. 6.

,
. 9 10 OVR.
. OVR - Overflow Register. 7.
:
0-6HT8VTR.
1-6HT8VDER.
2-6HT8VRSR.
3 - 8 SVBR.
4-6HT8LCR.
5-6HT9VTR.
6-6HT9VDER.
7-6HT9VRSR.

27. VGA SVGA

643

. PRSR - Preset Row Scan


Register. 8.
.
:
0-4 - ,
. .. .
5-6 - , 8 .
7 - .
. MSLR - Max Scan Line Register. 9.
.
:
0-4 - .
5 - 9 SVBR ( 15).
6 - 9 LCR ( 18).
7 - . 1, 200 ,
400 .
. CSR - Cursor Start Register. .
:
0-4 - .
5 - , .
7-6 - .
. CER - Cursor End Register. .
:
0-4 - .
5-6 - .
7 - .
. SAR - Start Adres Register.
, -.
. ,
.
.
, . CLR - Cursor Location
Register. , - OFH.
, , , X+5*Y.
. VRSR - Vertical Retrace Start Register.
.
. 10 .
OVR.
2

644

ASSEMBLER.

. VRER - Vertical Retrace End Register.


- 11.
.
:
0-3 - , .
4 - .
5 -
IRQ2.
6 - , 3.
7 - .
. VDER - Vertical Display End
Register. 12.
10 . 9-10 , OVR.
, .
. OFR - Offset Register. 13.
, .
. ULR - Underline Location Register. 14.
:
0-4 - (0-13).
5 - , -
4 1.
6 - .
7 - .
. SVBR - Start Vertical Blank Register. 15H.
10 . 9 OVR. 10 - (MSLR).
.
. EVBR - End Vertical Blank
Register. 16.
8 , , .
. MCR - Mode Control Register. 17.
:
0 - CGA.
1 - Hercules.
2 -
.
3 - , 1 , .
4 - .
5 - EGA.

27. VGA SVGA

645

6 - - , 1 - .
7 - ,
.
. LCR - Line Compare Register. 18.
10 . 9 OVR. 10 MSLR.
,
LCR, ,
. ,
, - , .

.
4 5.
. RR - Reset Register. 0.
:
0 - . 0,
. .
1 - . .
. CMR - Clock Mode Register.
1.
.
1 .
: 0 - . 5 -
, . .
.
. CPWE - Color Plane Write Enable.
2.
. 1, .
. CGSR - Character Generator Select Register.
3.
VGA 8 . .
0-5.
3 , , ,
.
2,3,5 , 3 1, 0,1,4 0.
:

646

ASSEMBLER.

5
.

0
0

1
1

1
1

. MMR - Memory Mode Register. 4.


:
0 - 0.
1 - 1.
2 - 0,
, - ( ).
3 - 0, , 0, 0, 1 -
1, 2 - 2, 3 - 3 ( ).
.

.

3CFH.
/. SRR - Set/Reset Register. 0.
SRER ,
.
:
0-3 - .
.
/. SRER - Set/Reset Enable Register. 1.

, - SRR.
:
0-3 - .
- .

27. VGA SVGA

647

, SRR, ( ,
).

(. MDR).
. CCR - Color Compare Register. 2.
.
:
0-3 - .
.
MDR CDCR.
.
. DRFS - Data Rotate and Fuction
Select. .
:
- , ,
- - .
:
0-2 - .
3-4 - .
- .
. . .
: 00- , 01 - "", 10 "", 11 - " ".
. RPSR - Read Plane Select Register. 4.
, .
0-1 - .
. MDR - Mode Register. 5.
:
-1 - .
0. . . : /, , ,
.
1. . 8 .
. .
2.
, / 0.
3.
/.

648

ASSEMBLER.

2 - .
3 - . 1 - , 0 1.
4 - / . .
5 - . 4 5.
6 - 256 .
7 - .
. MIR - Miscellaneous Register. 6.
:
0 - (1).
1 - , 16 32.
2-3 - :
- BOOO-.FFFF
0 1 - AOOO:FFFF
1 - BOOO-.7FFF
1 1 800:0000 - BOOO:FFFF
. CDCR - Color Don't Care Register.
7.
.
, , .
0-3.
. BMR - Bit Mask Register. 8.
. - , .

.
, , . () , 3DAH ( ).
. CPR - Color Palette Register's.
0-15.
, 6
.
. MCR - Mode Control Register. .
:
0 - .
1 - , 1.
2 - .
:
3 - 7- . , 7- , - .
4 - .

27. VGA SVGA

649

5 - .
6 - 256 .
1 - 4 5. , 4
5 , 0-1
.
. SBCR - Screen Border Color Register. 11H.
.
. CPER - Color Plane Enable Register.
12.
:
0-3 - ( ).
4-5 - .
6-7 - .
. HPR - Horizontal Panning Register.
13.
0-3 - .
. CSR - Color Select Register. 14.
:
0 - 4.
1 - 5.
2 - 6.
3 - 7.

- .
. PMR - Pixel Mask Register. 6.
. DAC_SR - DAC State Register. 7.
.
, .
11 - , 00 - .
. LTRIR - Look-up Table Index
Register. 7.
9 6- (, , ).
1. .
. LTWIR - Look-up Table Index
Register. 8.
9 .
. LDTR - Look-up Table Data Register.
9.
6 . 3 (,
, ).

650

ASSEMBLER.

II.
.
.
- 256,
. 64 .
.
- .
, , ..
0 15. VGA
. :
) , ,
) .
VGA- 1 -.
. , , 0-255.
10. ,
. 12, EGA-, , , 640x350,
10.
;,
;
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
ORG 10OH
BEGIN:
MOV AX,OAOOOH
/
MOV ES,AX
XOR BX,BX
;
; 640X480, 16
MOV AX,0012H
INT
CALL INPUT
/
MOV DX,3C4H
MOV AH,OFFH
MOV AL,2
OUT DX,AX
/
MOV DX,3CEH
MOV AX,OFF08H /
OUT DX,AX

27. VGA SVGA

651

/ /
MOV ,0005
; /-0
OUT DX,AX
;
MOV ,
OUT DX,AX
/ / - SRER
MOV ,0001
/ 1
OUT DX,AX
/
MOV AL,11111111
OR
ES:[BX],AL /
255
/
CALL INPUT
/ SRR
MOV ,00000001 /
MOV AL,1
OUT DX,AX
MOV AX, 0 / 0
/ 8 1111
/- (), 1110 -
OUT DX,AX
/ SRR
MOV AL,OFFH
OR
ES:[BX],AL /
CALL INPUT
/ =5, Y=5 ;- , - 1101
/ , 5- ()
MOV ,00001000
MOV AL,8
OUT DX,AX
/ / - 1 ( 0)
MOV ,00000010
MOV AL,1
OUT DX,AX
/ SRR
MOV AL,OFFH
OR
ES:[BX]+80*5,AL /
CALL INPUT
/ 1
MOV ,0105
/ /-1
OUT DX,AX
/ .

652

ASSEMBLER.

; ,
;AL,
MOV

AL,ES:[BX]

MOV ES:[]+8000,AL /
CALL INPUT
/ 2
MOV AX,0205H
/ /-2
OUT DX,AX
/ 1001 =5 Y=10
/ , /
;
MOV AL,00001001B / 4
OR ES:[BX]+80*10,AL
CALL INPUT
./ 3
MOV AX,0305H
/ /-3
OUT DX,AX
/ /
/
/,
/ . . 0001 -
/
MOV AL,
MOV , 1
OUT DX,AX
/
MOV ,11111111
MOV AL,8
OUT DX,AX
MOV AL,OFH /
OR
ES:[BX],AL
CALL INPUT
/
CALL SET_REG
MOV ,
INT
/ DOS
MOV AX,4COOH
INT 21H
/
/
INPUT PROC
XOR ,
INT 16H
RETN

27. VGA SVGA

653

INPUT ENDP
/
SET_REG PROC
;
MOV DX,
MOV AX,OFF08H
OUT DX,AX
; /
. MOV ,0005
; /-0
OUT DX,AX
;
MOV ,
OUT DX,AX
/ / - SRER
MOV ,0001
,- 1
OUT DX,AX
RETN
SET_REG ENDP
CODE ENDS
END BEGIN
. 26.1. .
10, . 26.1. .
, . 0 . RPSR
. , MOV AL,ES:[BX]. ,
( , ).
, ,
, .
. 1. , ,
(CCR). . CCR, 1, - 0.
CDCR.
"" . , , .
.
, 16 .
VGA 1. 320x200. , ..
. 0-255. ( ) 320x200=64000 .

654

ASSEMBLER.

X,Y :
320*+. ,
. , - .
/ 13
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
ORG 100H
BEGIN:
;
MOV AX,0013H

INT 10H
;
XOR BX,BX
MOV AX,OAOOOH
MOV ES,AX
CALL INPUT
MOV CX,320*200 ;
MOV AL,
L001:
MOV ES:[BX],AL
INC AL
INC BX
LOOP L001
CALL INPUT
XOR BX,BX
/
MOV CX,64000
; />=128 255
L002:
CMP BYTE PTR ES:[BX],128
JB
NO_CH
MOV BYTE PTR ES:[BX],255
NO_CH:
INC BX
LOOP LOO2
CALL INPUT
MOV AX,0003H
INT 10H
MOV ,4
INT 21H
INPUT PROC
MOV AH,0
INT 16H
RETN

27. SVGA

655

INPUT ENDP
CODE ENDS
END BEGIN

. 26.2. 13.
1 ,
67,
. , - .

III. .

. , 256
2 . ,
320x400 256 . : 320*400= 128000. . .. 64 2 .
: 320x400 - 256 , 2
- ; 640x400 -16 , 2 .
320*400. ,
. .
0 0,4,8,12..., 1 -
1,5,9,13..., 2- 2,6,10,14..., - 3,7,11,
15.... - , (+Y*N)/4, , , (X+Y*N) MOD 4. Y*N, , 4, X MOD 4.
.
, .
CODE SEGMENT
ASSUME CS:CODE,
ORG 10OH
BEGIN:

DS:CODE

; 13
MOV AX,0013H
INT
10H
MOV
AX,OAOOOH
MOV ES,AX
67

, , , ,
.

ASSEMBLER.

656


MOV DX,3C4H
MOV A L , 4
OUT DX,AL
INC
IN

DX
AL,DX

;
AND AL,11110111
;
OR
AL,00000100B
OUT DX,AL
5
MOV DX,3CEH
MOV AL,5
OUT DX,AL
INC DX
,
-
IN
AL, DX
AND AL, 11101111
OUT DX,AL
DEC DX
;

MOV AL, 6
OUT DX,AL
INC DX
; ,

;
IN
AL, DX
AND AL,11111101
OUT DX,AL
,
OFH
:
MOV DX,3C4H
MOV AL,2
OUT DX,AL
INC DX
MOV AL,00001111B
OUT DX,AL
;
: 13 64.
XOR DI,DI
MOV AX,DI

27. VGA SVGA

MOV
CLD
REP

657

CX,OFFFFH

STOSB
;
MOV DX,3D4H

MOV

AL, 9

OUT

DX,AL

INC

DX

; , ..
; 2
IN
AL,DX
AND AL,01100000B
OUT DX,AL
;
DEC DX
MOV AL,14H
OUT DX,AL
INC DX
;
IN
AL,DX
AND AL,10111111B
OUT DX,AL
;
DEC DX
MOV AL,17H
OUT DX,AL
. INC DX
,
4-
IN
AL,DX
OR
AL,01000000B
OUT DX,AL
;
MOV
,160
MOV
DX,200
MOV
BL,50
CALL POINT
CALL INPUT
;
MOV
AX,ES
ADD
AX,800H
MOV
ES,AX
MOV
CX,160
MOV
DX,200

658

ASSEMBLER.

MOV
BL, 1
CALL POINT
CALL INPUT
; , AL
; , 4
MOV
,0504
INT
10H
CALL INPUT
_END:
MOV AX,0002H
INT 10H
MOV ,4
INT 21H
;
; 320*400
; - X, DX - Y, BL -
POINT PROC

MOV AX ,80

MUL DX
f
PUSH CX
SHR CX ,1
SHR CX ,1
ADD AX ,cx
MOV DI ,AX
POP CX
/4
AND CL ,3
,
MOV AH ,1

SHL AH ,CL

MOV DX ,03C4H

2
MOV AL ,2
OUT DX ,AX
MOV ES : [DI],BL
RETN
POINT ENDP
INPUT PROC
MOV AH, 0
INT 16H
RETN
INPUT ENDP
CODE ENDS
END BEGIN

. 26.3. 320x400.

27. VGA SVGA

659

. 26.3 :
320x400, 0, 1, 1.
: 1 4.
, 8, 32.
640x400 2 16 ,
2 . , 640x350,
. , .
mov ax,000eh
/ 640x200 16
int 10h
mov dx,3d4h
mov al,9
/ MSLR
out dx,al
inc dx
in
al/dx
and
al,01100000b / 7-
out dx,al
/

IV. SVGA VESA.


SVGA, , . , . : . . ,
, , : AOOOH:FFFFH. , , .
, , 10,
. , 16 256 . 256 . 6-
, , , . 256 64*64*64=262144.
SVGA , . (Direct Color Mode).
, , , , , , . ,
. 32
. , , ,
5 . , 32768 (32*32*32=32768,32 =
5). 24 , -

660

ASSEMBLER.

256*256*256 = 16777216 . SVGA VESA.

VESA (VBE - VESA BIOS Extention).


VESA -
SVGA.
. ,
, VGA.
VESA , . VESA 4FH. AL.
, AL 4FH, , .
, 0, , 1, , , , 2.
VESA.
1. VBE .
AL = 0
ES:DI - 512 ( VBE 1.2) 256 (
1.2). 4 'VBE2'.
.

"VESA"

04

VBE ( ,
-

06

, VBE

0 (. 1 .2) - 1 -
1 (. 2.0) - 1 -
VGA, 2 (. 2.0) - 1 -
VBE

.
16- , FFFFh

12

1 .2. 64
2.0.

14

16

, -

27, VGA SVGA

1 EH

22

222

100

256

2.

.
AL=1
-
ES:DI - 256 .


0 - 1 -
1-1 -
2 - 1 - BIOS
3 - 1 - (0 - )
4 - 1 -
5 - 1 - ,
VGA
6 - 1 -
:0000 - AOOOH:FFFF
7 - 1 -

02

:
0 - ,
1 - ,
2 - ,

04

06

08


VBE 1.2.

12

661

ASSEMBLER.

662

14

16

17

18

19

:
0 -
1 - CGA
2 - Hercules
3 - 4 ()
4 - ,
,
5 - 256 ,
6 -

1CH

1DH

1EH

1FH

20H

21H

22H

23H

24H

25H

26H

27H

0 - 1 -
1 - 1 -
2.0.

28

32-

32

206

663

27. VGA SVGA

3. .
AL=2h
- VESA
VESA.

100

256

640*400

101

256

640*480

102

16

800*600

103

256

800*600

104

16

1024*768

105

256

1024*768

106

16

1280*1024

107

256

1280*1024

16

80*60

109

16

132*25

10

16

132*43

10

16

132*50

10

16

132*60

32768

320*200

10

65536

320*200

10FH

16777216

320*200

32768

640*480

111

65536

640*480

112

16777216

640*480

113

32768

800*600

114

65536

800*600

115

16777216

800*600

116

32768

1024*768

117

65536

1024*768

118

16777216

1024*768

119

32768

1280*1024

65536

1280*1024

108

10DH

664

ASSEMBLER.

4. .
AL = 03H
: - .
5.

/ .
AL = 04H
) .
DL = 0
-
0 -
1 -
2-
3 - SVGA
:
-
)
DL=1
ES:BX -
-
)
DL = 2
ES:BX -
-

6.

.
AL = 05
= 0
BL - (0,1 - ,)
DX - .
.

7.

.
AL = 5
= 1
BL -
:
DX - .

SVGA.
103 (800*600*256)
. :
) , , 256 800*600=480000. .. , -
VGA-. , -

27. VGA SVGA

665

VESA BIOS. . , ,
- BOOOH:FFFFH (. MIR) .
.
. , , , VESA .
) 320*400*256, . (. . 26.3).
) , (800*Y+X)/4 OFFFFH. ,
. , .
) _SI , 1 .
. ,
, - CALL RETN . . .

, 101 (640*480*256). VESA, .. 256 . , 640*400*256 VESA ( ).

.286

CODE SEGMENT
ASSUME CS:CODE, DS:CODE
ORG 100H
BEGIN:
/ 103
MOV AX,4F02H ,- 800*600*256
MOV BX,103H
INT
CMP AX,004FH
JZ
_OK
JMP _END
;
_:
MOV
AX,OAOOOH
MOV ES,AX
, VGA- , 256 . SVGA-, ,
VGA.

666

ASSEMBLER.

/.******************************************************
; 4
;
MOV DX,3C4H
MOV AL,4
OUT DX,AL
INC DX
IN
AL,DX
;
AND AL,11110111
/
OR
AL,00000100B
OUT DX,AL
/

; ,
; OFH
/ ( 4, 2).
MOV DX,3C4H
MOV AX,OFF02H
OUT DX,AX
/*******************************************************
;
MOV ,600
L002:
PUSH
INC Y
MOV X,
MOV CX,800
L001:
PUSH CX
MOV
CX, X
MOV
DX,Y
MOV
BL,COLOR
CALL POINT
INC
COLOR
INC
X
POP
CX
LOOP
L001
POP CX
LOOP LOO2
CALL INPUT

_END:
MOV
INT

AX,0002H
10H

27. VGA SVGA

667

MOV AH,4CH
INT 21H
;
; 800*600*256
; - X, DX - Y, BL -
POINT PROC

MOV AX,200
MUL DX

MOV DI,CX
SHR CX,2
ADD AX,CX
;/4+800*/4 -> DX:AX
ADC
DX,0
CMP DX,0
;,
JNZ _0
MOV SI,0
CMP _SI,SI
JZ
_1
CALL WIN_MOVE
JMP SHORT 1
0:
MOV

SI,I

CMP _SI,SI ; , ,
JZ

_1

CALL WIN MOVE


1:

MOV
MOV
AND
MOV
SHL

SI, AX
CX,DI
CL,3
AH,1
AH,CL

/4
,

MOV DX,03C4H

MOV AL,2
2
OUT DX,AX
MOV ES: [SI],BL
RETN
POINT ENDP
;
INPUT PROC
MOV ,
INT 16H
RETN
INPUT ENDP

668

ASSEMBLER.

; N
; SI,
;
WIN_MOVE PROC
MOV _SI,SI
PUSH AX
PUSH BX
PUSH DX
MOV AH,4FH
MOV AL,05
MOV BH,0
MOV BL,0
MOV DX, SI
INT 10H
POP DX
POP BX
POP AX
RETN
WIN_MOVE ENDP
/
;
X
DW
Y
DW
;
COLOR DB
;
_SI
DW
CODE ENDS
END BEGIN
. 26.4. 800*600*256.
1ODH VESA.
320*200 32768 . : , .
5 . .
. . . ,
320*200*2= 128000 . .
, .
; 13
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
ORG 10OH

27. VGA SVGA

669

BEGIN:
;
; 10DH
MOV AX,4F02H ; 320*200*32768
MOV BX,10DH
INT
CMP AX,004FH
JZ
_OK
;
JMP _END
_:
XOR ,
MOV ,
MOV ES,AX
/
CALL INPUT
MOV BX,20000
MOV AL,OOOOOOOOB
MOV ES:[BX],AL
INC BX
CALL INPUT
MOV AL,11111100B
/ 5
MOV ES:[BX],AL
/
CALL INPUT
/ -
MOV CX,320*200 /
MOV AL,
MOV ,0
L001:
MOV ES:[BX],AL
INC AL
INC BX
MOV ES:[BX],AL
INC BX
LOOP L001
;
MOV AH,4FH
MOV AL, 5
;
MOV BX,0
MOV DX, 1
INT 10H
CALL INPUT
;
MOV CX,320*200 /
MOV AL,0
MOV BX,

670

ASSEMBLER.

L002 :
MOV
INC
INC
MOV
INC
LOOP
XOR
CALL

ES:[BX],AL
AL
BX
ES:[BX],AL
BX
L002
BX,BX
INPUT

_END:

MOV AX,0003H
!. -INT. 1QH - _ ..
MOV AH,4CH

INT 21H
INPUT PROC

MOV AH,0
INT 16H
RETN
INPUT ENDP
CODE ENDS
END BEGIN

. 26.5. 10DH.

1.
.
8088/8086. , .
5,20.
BCD-.

AAD

BCD- .

BCD- .

60

BCD- .

83

AAS

BCD- .

BCD- ASCII- , ( ASCII-). , , ASCII-. 1 2. SUM RAZ. ,


.
CODE SEGMENT
ORG 100

ASSUME CS:CODE
BEGIN;
;
MOV AL,CS:P1+1
ADD AL,CS:P2+1

;
MOV CS:SUM+1,AL
MOV AL,CS:P1
.
ADC AL,CS:P2

;
MOV CS:SUM,AL
/
ADD BYTE PTR CSrSUM,48
ADD BYTE PTR CS:SUM+1,48
MOV DX,OFFSET CS:SUM
MOV AH, 9
INT 21H

672

ASSEMBLER.

/
MOV AL,CS:P1+1
SUB AL,CS:P2+1
AAS
;
MOV CS:RAZ+1,AL
MOV AL,CS:P1
SBB A L , C S : P 2
AAS
;
MOV CS:RAZ,AL
;
ADD BYTE PTR CS:RAZ,48
ADD BYTE PTR CS:RAZ+1,48
MOV DX,OFFSET CS:RAZ
MOV AH,9
INT 21H
RET
PI
DB '39'
P2
DB 42'
SUM DB ' ',13,10,'$'
RAZ DB ' ' ,13,10, '$'
CODE ENDS
END BEGIN
, ASCII-.
AL 10, , AL.
.
CODE SEGMENT
ORG 10

ASSUME CS:CODE
BEGIN:
/ PI 2 1*2<100
MOV
CL,CS :P1 + 1
MOV AL,CS :P2
SUB AL,48
SUB CL,48
;3*7
MUL CL
AAM
PUSH AX
MOV CL,CS :P1
MOV AL,CS :P2
SUB AL,48
SUB CL,48
;3*2
MUL CL
MOV AH,AL
XOR AL,AL
POP CX
ADD AL,CL ;1 + 0

1.

673

ADC , ;+2
OR
AX,3030H
; ASCII-
MOV
CS:MUL1,AH
MOV CS:MUL1+1,AL
;
LEA
DX,GS:MUL1
MOV , 9
INT 21H
RET
PI
DB '27'
P2
DB '3'
MUL1 DB ' ',13,10,'$'
CODE ENDS
END BEGIN
ASCII- AAD,
AL AL+* 10.
BCD-.

DAA
DAS

BCD- .

BCD- . 4

ADD

ADC

22 - 4072

-
-
-
-
-
-

-
-
-
-
-
-

2
2-4
2-4
3-4
3-6
2-3

9+
16+

4
17+

4
3
9+
16+

4
17+

2
2-4
2-4
3-4
3-6
2-3

ASSEMBLER.

674

SUB

-
-
-
-
-
-

3
9+
16+
4
17+
4

2
2-4
2-4
3-4
3-6
2-3

SBB


-
-
-
-
-
-

3
9+
16+
4
17+
4

2
2-4
2-4
3-4
3-6
2-3

3
16+

2
2-4

DEC

1
16-
8-

2
3
15+

1
2
2-4

INC

1
16-
8-

2
3
15+

1
2
2-4

MUL


8-
16-
8-
16-

IMUL


8-
16-
8-
16-

NEG

DIV


8-
1 6-
1 6-
8-

70-77
2
118-133 2
(76-83)+ 2-4
(124-139) 2-4
+
80-98
2
128-154 2
(86-104)+ 2-4
(134-160) 2-4
+
80-90
2
144-162 2
(86-96)+ 2-4
(150-168). 2-4
+

675

1.


8-
1 6-
8-
1 6-

101-112 2
165-184 2
(107-118)2-4
+ (171-190) 2-4
+

CBW

CWD

1
1

, . -
. , INC MEM, MEM , , . 6 . INC [BX] .
5 . .. . , 2-4 , 2 4 : ADD . 4 ,
ADD BX,[DI] - 2 ..
.

IN

OUT

MOV

22'

-
: IN AL,6 1
: MOV DX,61H/IN AL,DX

10
8

2
1

-
: OUT 61 H,AL
: MOVDX,61H/OUTDX,AL

10
8

2
1

-
-
-
-
-
-
-
- ( CS)
- ( CS)
-
-

10
10
2
8+
9+
4
10+
2
8+
2
9+

3
3
2
2-4
2-4
2-3
3-6
2
2-4
2
2-4

ASSEMBLER.

676

LEA

()

2+

2-4

LDS

DS ()

16+

2-4

LES

ES ()

16+

2-4

LAHF

SAHF

LODSB

LODSW

MOVSB

MOVSW

SCASB

SCASW

12
1
9+13/. 1

18
1
9+17/. 1

15
1
9+15/. 1

STOSB

STOSW

1
9+10/. 1

POPF

PUSHF



( CS)

8
8
17+

1
1
2-4

11
10
16+

2-4
1
1

XLATB

AL

11

XCHG

-
-
-

3
11+
4

PUSH

'2-4
1
1

677

1.

9+10/. , .
, 9+.
(=0), 9+10.
.

AND

OR

XOR

NOT

RCL

RCR

""
-
-
-
-
-
-
""
-
-
-
-
-
-
""
-
-
-
-
-
-
()


( )
( )
( )
( )

( )
( )
( )
( )

2
2-4
2-4
3-4
3-6
2-3

9+
16+

4
17+

4
3
9+
16+

4
17+

4
3
9+
16+

4
17+

4
3

2
2-4
2-4
3-4
3-6
2-3
2
2-4
2-4
3-4
3-6
2-3

16+

2
2-4

8+4/ 2
15+ 2-4
20++ 2-4

8+4/ 2
15+ 2-4
20++ 2-4

ASSEMBLER.

678

ROL

ROR

SAL

SHL

SAR

SHR


( )
( )
( )
( )

2
8+4/
15+
20++

2
2
2-4
2-4

2
8+4/
15+
20++
4/
4/

2
2
2-4
2-4


( )
( )
( )
( )

2
8+4/
15+
20++

2
2
2-4
2-4

()
( )
( )
( )
( )

2
8+4/
15+
20++

2
2
2-4
2-4


( )
( )
( )
( )

2
8+4/
15+
20++

2
2
2-4
2-4

2
8+4/
15+
20++
4/

2
2
2-4
2-4


( )
( )
( )
( )

()
( )
( )
( )
( )

1,

679

-
-
-
-
-
-

3
9+
9+

4
10+

2
2-4
2-4
3-4
3-6
2-3

CMPSB

CMPSW

22
1
9+22/ . 1

-
-
-
-
-

3
9+
4
4
17+

TEST

2
2-4
2-3
3-4
3-6

, , .
.

CALL

19
16
37+

3
2
2-4
5
2-4

21+

28


=3
=/3

52
51

1
2

INTO

54
4

1
1

ASSEMBLER.

680

24

RET

8
12
18
17

1
3
1
3

REP

REPE

REPZ

REPNE

REPNZ

LOOP

17/5

LOOPE

18/6

LOOPZ

18/6

LOOPNE

19/5

LOOPNZ

19/5

JMP


(SHORT)
(NEAR)


15
15
15
15+
11

2
3
5
2-4
2

JCXZ

, =0

18/6

JA/JNBE

16/4

JAE/JNB

16/4

JB/JNAE

16/4

JBE/JNA

16/4

JE/JZ

16/4

JG/JNLE

16/4

JGE/JNL

16/4

JL/JNGE

16/4

JLE/JNG

16/4

JC

16/4

JNC

16/4

1.

681

(JA/JNBE). 1 6/4
, .
.

CLC

GLD

CLI

CMC

ESC

2
8+

2
2-4

HLT

NOP

STC

STD

STI

WATT

3+5

2. .

- .

. .
.
.
.
.
, .
, , .
.
. , .
. 00000001 1. -! : 1+(-1)=0. 1111111 ( 1). , 2 00000010.
-2 -1 (-l)-l. 11111111-00000001=11111110.
, -2 11111110. , , 2+(-2)=0. . :

1
2
3

- 00000001
- 00000010
- 00000011

-3
-2
-1

- 11111101
- 11111110
- 11111111

, -128 127:
127-011111 , -128- 10000000.
. -32768 32767.
, , - .
(. 4 1).
: NEG,
CBW, .
386- 32- .
.
, .

3.
.
, ,
, .
.
. , . , , , , , . ,
, . , .
SEGMENT - ENDS.

.
:
SEGMENT [ .][][ .][]['']

ENDS
- BYTE, WORD, PARA (16 ), PAGE (256 ).
.
- READONLY. - , .
:
public - , , , .
stack - ,
SS, SP - .
common - , , ,
. ,
.
memory - common.
at - - .
: USE16 -16- , USE32 - 32- , FLAT - ,
.
: .
GROUP.
,
.
GROUP 1 ,2,...

684

ASSEMBLER.

, GROUP. , , - -.
GR GROUP CODE,DAT1
CODE SEGMENT BYTE
ASSUME CS:CODE
ORG 10OH
BEGIN:

MOV DX,OFFSET GR:STRING


MOV AH, 9
INT 21H
RET
CODE ENDS
DAT1 SEGMENT BYTE
STRING DB '.', 13,10, '$'
DAT1 ENDS
END BEGIN
INCLUDE.
: INCLUDE _.
. ,
. INCLUDE .
LENGTH, SIZE, TYPE.
LENGTH - , DUP: DW 64
DUP (?), DD 10 DUP(O) ..
TYPE - , .
SIZE=TYPE*LENGTH.
NAME.
. :
1. NAME , .
2. NAME , 6 TITLE.
3. NAME TITLE ,
.
.
LABEL.
. :
LOO LABEL BYTE
NADW1234H
LOO NA.

3.

685

RECORD.
.
: RECORD _:[=][,..].
:
BIT RECORD B1:3,B2: ,:3 - , .
BIT1 RECORD BI1:10=1010110011B,BI2:6=111001B - .
. : DEFB BIT1 <>. . DEFB MOV
BX.DEFB.
RECORD WIDTH MASK.
WIDTH : MOV AL.WIDTH BI2
- FL 6. MASK
, , .
:
81 1110000000000000
82 0001111111111000
83 0000000000000111
, : MOV
AL.BI 1. AL , BI1,
. , MOV CL,B 1 CL 13, MOV CL.B3 - 0.
: MACRO ,
ENDM. .
;
;: OUT_STRING ST , ST
OUT_STRING MACRO STRING
MOV DX,OFFSET STRING
MOV A H , 9
NT 21H
ENDM

/
;: LOCATE 12,20
LOCATE MACRO X,Y
MOV BH,0
MOV AH,2

686

ASSEMBLER.

MOV D H , Y
MOV D L , X
INT 10H

ENDM

,
, .
, .
, .. .
, INCLUDE. :
1. ,

. PURGE,
, , . : PURGE _!,_2..
2.
. , . , ,
LOCAL.
3. , , , INCLUDE, , .
:
IF1

INCLUDE _
ENDIF
, . :
IFXX
ELSE
ENDIF
:
IF - , .

3.

687

IFE - , .
IF 1 - , .
IF2 - ,
.
IFNDEF - EXTRN, .
IFB <> - , . .
IFNB <> - .
IFIDN <ARG I >, <ARG2> - , .
IFDIF <ARG1 >, <ARG2> - .
.
REPT -
ENDM .
IRP ,<> - , , . :
IRP N , < 2 , 3 3 , 6 7 , 3 3 , 7 7 >
DB N
ENDM

: DB 2, DB 33, DB 67, DB
33.DB77.
IRPC N, - .
EXITM.
.
:
IFXX

EXITM

ENDIF
EXITM,
ENDM.

688

ASSEMBLER.

, . :
.IF

ELSE

.ENDIF

. . ,
,
jnz _
add ax,bx

_no:

.IF ax=0
add ax,bx
.ENDIF
, ? , - ,
,
.
STRUC.

. :
_ STRUC

_ ENDS
,
:
_ <>. . :

3.

689

MSG MESSA <0,0,0,0,0,0,100,100>. ,


.
, :
NAMES STRUC
NAME1 DB 12 D U P ( O )
NAME2 DB 12 DUP(O)
NAMES ENDS
, :
NAME_F NAMES <>

:
LEA DX,NAME_F.NAME2 - NAME2 DX ..
().
-(1)
DW - (2)
DD - (4)
DF - (6)
DQ - (8)
DT - (10)
. , 5.0.
.SEQ - , . , , .
.ALPHA - .
.DOSSEG -
Microsoft. Masm 6.O. . 24.

4.
DEBUG.
DEBUG, .
- . . , , ,
.
(.
)
. -, -.

.
.
CTRL . .
[] - .
- . , : 040200 A CS: 1000 300 - CS:300 A - CS: 100 - CS:0000 -. .
- . .
: ! ! 2 2.
D [] - - .
, 128 , DS: 100.
- . .
F - . . , , , , .. .
G [= [ ]] - .
10 . . G .
I - . , .
N - .
, .
L - , N. : . -,
-.
- .
- .
R [] - . R . R .

4. DEBUG

691

S - .
[=[]] - .
. . , .
U [] - .
. 32 .
W - . .
.. ,
.
Q - .

.
, .
N, : . W.
-.

.
, ,
. - MS DOS.
, , . , DEBUG < A.DBG
. ,
(13,10), .

MOV , 2
MOV DL,7
INT 21
RET
G
Q
, ( 7).
, RET , ENTER, , ,
.

5.
.
Intel
. [2, 4, 6].
.
:
-
REG -
MOD -
R/M -
DISP -
DATA - .

11

REG
1 1

R/M
1 1

- 1 2

MOD
I

REG
I I

R/M
I
I

MOD
I

REG
I I

R/M
I
I

- 1 4

11

R/M
1 1

- 1 4

MOD
1

1 1

1 1

R/M
1 1

5.

693

1). NOP
90H
90 -
HLT
F4H
F4H -
2 ) . INC AX
40H
01000 -
000
- (REG)
DEC AX
48H
01001 -
000
- (REG)
INC BX
43H
01000 -
011
- BX (REG)
DEC BX
4BH
01001 - .
011
- BX (REG)

.
REG, REG.
3 ) . MOV A X , B X
89D8H
89 -
11
011 - BX (REG)
000 - (R/M)

ADD AX,CX
01C8H
01
-
11
001 - (REG)
000 - (R/M)
4) . MOV BX, [SI] 8B1CH
8 -
00 - MOD
011 - BX (REG)
100 - [SI] (R/M)

694

ASSEMBLER.

MOV A X , [ D I ] 8B05H
8 -
00 - MOD
000 - (REG)
101 - [DI] ( R / M )
JMP [SI]
FF24H
FFH -
00 - MOD
100 - REG
100 - (R/M)
5).

ADD A X , [ 1 0 6 H ]
03060601

-
00 - MOD
000 - (REG)
- R/M
0601
- DISP (106H)

6 ) . SUB B X , 4 3 A 4 H
81443
81 -
11
101 -
011 - (R/M)
443 - DATA ( 4 3 A 4 H )
7).MOV [12A7H],3456
7 -
00 - MOD
000 -
- R/M
712 - DISP
5634 - DATA

7067125634

, , .

. . , ,
.

6.

( BIOS DOS).
. INTER, , . ,
, .

INT 0 - .
0 ,
DIV IDIV ,
0. BIOS
, . MS
DOS INT 0. " " MS DOS. MS DOS , .
: Intel 80286 INT 0, MS DOS, BIOS,
0 DIV
(IDIV), .

INT 1 - .
1
, TF 1. TF
,
, TF .
BIOS INT1, TF () . MS DOS INT1, ,
, DEBUG MS DOS.

INT 2 - .
, .
.
. 2, BIOS, . "-1030",
, "", -

696

ASSEMBLER.

.
, .
MS DOS ,
MS DOS , , INT 2 .
2 - , IF ( CLI).
(. 26) .
:
1. PCjr .
2. System/2, 30, :
110 - ;
111 - - (
);
112 - - (Watchdog) - , ;
113 - - -
, 7.8 .
3. PC Convertible
, , -.
4. 8087 .
80287 80387
IRQ 13; 2.
5. , . ,
,
INT 2.

INT 3 - .
3 INT 3,
INT , .
( , DEBUG) 3
.
INT 3 .
BIOS INT 3, MS DOS.

6.

697

INT 4 - .
4 INTO,
1 OF .
(INT 4) OF.
BIOS INT 4, MS DOS. , , ,
, INT4, .

INT 5 - .
5 BIOS . ,
INT 5
, LPT1.
INT 5 ,
0000:0500:
- ;
01 - ;
OFFH - (
).
, , , .
.
(. INT1 ), . , , .
MS DOS 5, MS DOS GRAPHICS
, .
ctrl+BREAK.

INT 8 - .
8 (IRQ 0), 18.2 ( 55 ). BIOS
, :
;
;
1.

698

ASSEMBLER.


(32 , )
0000:046. , 24
, 0, 0000:0470
.
, , .
, 0.
.
0000:0440.
1 , .
MS DOS 8.

INT 9 - .
9 (IRQ 1) ,
- . - ,
, 0.5 , 0.1. .
, ( ) ,
.
BIOS 9 , (-) :
1. , - , . 32
, 0000:041 ,
. (.. )
0000:041.
2, , . .
2. , , 0000:0417
0000:0418. Alt, Ctl
, , Shift.
, ,
. - CapsLock, Num Lock, Scroll
Lock - : . Shift ,
( /), . Num Lock -

6.

699

, .
.
3. Alt . Alt 256 - 0.
4. Del Alt+Ctrl (.. Alt Ctrl) : - 0000:0472 1234, .
, .
5. Num lock (.. ) Ctrl
- .
6. Print Screen 5, ..
.
7. Scroll Lock Ctrl 1 (Break).
8. , , .
AT, PC Convertible, System/2 XT (BIOS 1986 .)
()=85 15,
. ,
15 () = 9102, .
( ) BIOS - . ()
= 4FH 15, ,
( 60).

INT 19H - .
19 0 0. 7:0,
.
(INT 1 (DL) = 0), -
(INT1 (DL) = 80H). ,
INT18, .

INT 1BH - .
1 Ctrl-Break (.
9). BIOS , () = 03, (AL) = 0. MS DOS
1, , . (
MS DOS ).

700

ASSEMBLER.

INT 1CH -
.
1
(INT 8) . BIOS
1 ; .

INT 1EH - .
BIOS 1
(. 14).

INT 40H - .
, , BIOS
1 , .
40. , ,
BIOS.

INT 41H -
.

. ,
. , . BIOS 41 ( ).
,
, (IBM AT, System/2) , 0.
46 1, .
, .

6.

:
7=1- ;
6=1- ;
5=1- ;
4 - ;
3 = 1- 8 ;
2 - 0 -

10

11

12

Landing Zone

14

15

701


.
. :
;
BIOS -;
;
6 7 ;
, 3 Landing Zone
;
,
.

INT 70H - .
70 .
- (. 9), 1024 . , , 0, . , . () = 86 INT 15H 7 04.
4
.

7. MS DOS.
DOS , . ,
. . .
, DOS . , . , MS DOS , .. (, ),
(. 12).
DOS:
MOV AH,NUM

{ }

INT 21H
NUM - DOS, , , . . AL.

DOS.
0.
: CS - PSP .
. INT 20H. 22, 23,
24. , , , . 4.
1.
:
( )
( ). . (
). Ctrl-Break Ctrl-C.
2.
: DL - .
. Ctrl-Break Ctrl-C.
3.
:
AL ( 1).
4.
: DL - .
.

7. MS DOS

703

5.
: DL - .
LPT1:.
6.
.
: DL-0-FEH
.
:-
AL - ,
Z. .
7.
. . , .
Ctrl-Break. 1 - .
8.
, Ctrl-Break.
9.
.
: DS:DX - , '$'.
.
.
: DS:DX - . :
, ,
. (13).
.
. , AL=0, , AL=FFH.
.
.
: AL - : 01,07,08, . DS:DX - . .
.
.
: AL - (0=, 1= ..)
AL - .
OFH-17 - FCB. ,
. , .

704

ASSEMBLER.

19.
.
AL - -, 1 - ..
1.
(DTA)
.
DS:DX - DTA.
1.
.
:
AL - ,
- ,
DX - ,
DS:BX -> -:
FFH- 320,
FEH- 160,
FDH- 360,
FCH- 180,
F9H- 1,2,
F8H- ,
FOH- .
1.
.
:
AL - .
: 1.
1FH.
.
:
AL - 0 - ,
DS:BX - : , .
21-24 FCB,
.
25.
.
:
AL - ,
DS:DX - .

7. MS DOS

705

26.
.
:
DX - PSP. PSP.
27-29.
FCB.
2.
.
:
-,
DH - ,
DL - ,
AL - (0 - ..).
2.
.
:
-,
DH - ,
DL - .
:
AL=0 - ,
FFH - .
2.
.
:
- ,
CL - ,
DH - ,
DL - .
2DH.
.
:
- ,
CL - ,
DH - ,
DL - .
:
AL=0 - ,
FFH - .
23 - 4072

706

ASSEMBLER.

2.
.
:
AL=0 - ,
AL= 1 - .
2FH.
(DTA).
:
ES:DX- DTA.
.

DOS.
:
AL=0 - OEM,
AL= I - ,
:
AL - ,
- ,
- OEM:
OOh-IBM,
16H-DEC,
99h - STARLITE,
FFH-Phoenix
- :
08h - DOS ,
- DOS .
31h.
.
:
AL - ,
DX - .
32.
.
:
DL - .
:
DS:DX - .
AL=OFFH.

7t MS DOS

707

.
Break (Ctrl Break, Ctrl ).
:
AL=0 - Break,
Al=1 - Break,
DL=0 - Break ,
1-OCh,
DL=1 - Break .
:
DL - Break, AL=0.
:
AL=2 - Break.
DL=0 - Break ,
1 - cocnjzybt Break .
:
DL - Break.
:
DL=5 - .
:
DL - (1 - , 2 - ..)
34.
.
:
ES:BX - .
35.
.
:
AL - .
:
ES:BX - , .. .
36.
.
:
DL - (0 - , 1 - : ..).
:
- ,
- ,
- ,
DX - .
AX=FFFFH.
37.
. -, 6.0 DOS
.

23-

?&8

ASSEMBLER.

38.
/ .
39.
.
:
DS :DX - ASCII, 0.
:
, - .
.
.
:
DS:DX - ASCII, 0.
:
, - .
.
.
:
DS:DX - ASCII, 0.
:
, - .
.
. , , , . .
:
- .
DS:DX - ASCII,
- .
:
- .
3DH.
. , .
:
AL - . 80,
.
DS:DX - ASCII, - .
:
- .
.
.
:
- .

7. MS DOS

3FH.
.
:
-.
- .
DS:DX - .
:
- ( ).
40.
.
:
-.
- . =0, .
DS:DX - .
:
- ( ).
41.
.
:
DS:DX - .
42.
.
:
AL - .
0 - ,
1 - ,
2 - .
-.
- .
DX - .
:
DX - .
- .
43.
.
:
AL - 0 - .
-1 - .
- .
DS:DX - .
:
- .

709

710

ASSEMBLER.

44. IOCTL - Input-Output Control.


. AL.
00. .
:
- ,
:
DX - -15 :
0 -1 - ,
1 -1 - ,
2 -1 - (NUL),
3 -1 - .
5 - (0 - ASCII, 1 - ),
6 -1 - , 0 - ,
7 -1 - , 0 -
14 -1 - IOCTL
- IOCTL .
: 0 - , 1 - ..)
01. .
:
- ,
DX - (DH=0).
:
DX - .
02-03. .
(2), (3) .
:
DS:DX - ,
- ,
- .
:
04-05. (04) (05) IOCTL .
:
DS:DX - ,
- ,
BL - (0 - , 1 - ..)
:
- , .
06-07. (06) (07).
:
- .
:
AL = fYH - , 0 - .
AL = FFH - , 0 - .

7. MS DOS

711

08. .
:
BL - (0 - , 1 - ..)
:
- 0 - , 1 - ( )
09. .
:
BL - (0 - , 1 - ..)
:
DX - :
0 -1 - ,
1 -1 - ,
2-1- NUL,
3 -1 - ,
6-1 - ,
11 -1 - ,
12 -1 - (, CD-rom),
13 -1 - IBM- ,
14 -1 - IOCTL,
15 -1 - , 0 - .
. , .
:
- .
:
DX - , 15 = 1, (.. ).
. .
:
DX - ,
- .
:
. .
:
- ,
- :
0 - ,
1 - - ,
3 - CON - ,
5 - .
CL - .
4ch - ,
4dh - ,
4ah - ,

712

ASSEMBLER.

6ah - ,
6bh -
DS:DX - ,
:
4ch,
3.
Odh. .
:
CL - .
40h - ,
60h - ,
41 h - ,
61 h - ,
42h - ,
62h - .
DS:DX - .
:
Oeh. , .
:
BL - (0 - , 1 - ..)
:
:
AL - 0 - , 1 - ..
OFh. .
:
BL - (0 - ..)
:
, :
AL - 0 - , 1 - ..
"Insert diskete for drive..."

Och IOCTL.
4, 4DH, 6.
DW ? ;
DW ? ;

4.
DW
DW
DW
DW
DW

? ;
? ;
? ;
15BH ; , ,
? ;

7. MS DOS

713

6.
DS:DX.
DW ? ;
DW ? ;
DW ? ; 1
DW ? ; 2

DW ? ;
DW ? / 1
DW ? / 2

Obh IOCTL.
40,60.
DB ? / : 60h
/ 0, 0=1 -
/,
0=0 -
/ 4 3 :
/ 0 - 1 DeviceBPB
/ - 0 - DeviceBPB
;1 - 1 - ,
/
; 2 - 1 -
DB ? / ( ):
/ - 320/360 5.25
/1 - 1.2 5.25
/2 - 720 5.25
/3 - 8-
; 4 - 8-
/ 5 -
/6 -
; 7 - .
DW ? / ( )
; - 0 - 1 - ,
; -
/ 1 - 1 , 0 -
DW ? / ( ) -
/ ,
DB ? / - ,
/ 1.2 :
/ - 1.2, 1 - .
DB 31 d u p ( ? ) /DeviceBPB. + 12

714

ASSEMBLER.

DeviceBPB:
(13 , . 14, . 14.4)
DW ? ;
DW ? ;
DD ? /,
DB 10 dup(?) ;
DB ?

; ( )

:
DW ? ;
DD ? ; (, DW 1,200)

41,61.
DB ? ; ( 0)
DW ? ; /
DW ? ; /
DW ? ; ( 0)
DW ? ; ( 0)
DD ? ;
42,62.
DB ? / ( 0)
;=0
;=1
DW ? ;
DW ? ; ()

DOS.
45.
, .
:
-
:
- .
46.
. , .
:
- ,
- , .

7. MS DOS

715

47.
.
:
DL - (0 - , 1 - ..)
DS:SI - (64 ).
:
.
48.
.
:
- .
:
- .
, , , , .
49.
.
:
ES - .
4.
.
:
ES - ,
- .
:
- .
4.
( ).
11.
:
AL = 0 - ,
= 1 - ,
= 3 - .
ES:BX - (. 11)
DS:DX - .
4.
.
:
AL - .

ASSEMBLER.

716

4DH.
.
:
= 0 -
1 - Ctrl+Break
2 -
3 - hit 21 31 h .
AL = .
4.
.
:
-
DS:DX - , .
:
DTA.
4FH.
.
4 , . - .
DTA.
.

40

21

+15

+16

4FH

+18

+1

DWORD

+1

13

..

50.
PSP. , 5.0.
:
- PSP, .
51.
PSP .
:
- PSP .

7. MS DOS

7/7

52.
.
:
ES:BX - .
54.
"verify".
:
AL - 0
1 .
56.
.
:
DS:DX - .
ES:DI - .
57.
0.
.
:
- .
AL=0.
:
- (0-4 ., 5-Ah ., Bh-Fh .
DX - (0-4 ., 5-8 , 9-Fh - . 1980).
1.
- .
-.
AL=1.
CX,DX - (. . 0).
59.
.
.
:
= 0
:
- ,
- ,
BL - ,
- .
, : DX, SI, DI, BP, DS, ES.

718

ASSEMBLER.

5.
. .
:
-
DS:DX - ()
:
DS:DX -
-
5.
.
, , .
5DH.
:
AL = 6
. .
:
DS:SI -
- ,
, DOS
DX - ,

:
AL = Oah
DS:DX - 3- , .
:
.
59.
62.
PSP .
:
- PSP.
67.
.
:
- .
:
PSP .
(.
8).

7. MS DOS

719

68.
, .
:
-
69.
.
:
BL - (0 - , 1 - ..)
AL - 0 -
1 -
DS:BX-
:
.
0020
02h 4
06h 11 'NONAME',
1 lh 8 (AL=0) FAT12 FAT16
6.
.
:
AL-00,
- (. ),
- ( ),
DX - :
- , ,
- , ,
2 - ( ), ,
- , ,
001 - , .
:
0-2 - - (0 - , 1 - ,
2 - ).
4-6 - .
13 - 0 - 24, 1 -
24,
- .
14-0 , 1 - - ().
API CreateFile (Windows).

8. BIOS.
, .
, . , . BIOS
SVGA ( VESA) 27. ,
, .

( ).
BIOS . 1 . .
, 0 -15 , . ,
, , , .
10- . . ,
, .

()

1 (01)

2 (02)

3 ()

4 (04)

5 (05)

6 (06)

7 (07)

8 (08)

9(09)

10 ( )

()

12 ()

13(ODH)

14()

15(OFH)

8. BIOS

16 ()

721

18(12)

EGA

19(13)

20 (14)

VGA

21 (15)

26(1 )

27(1)

28(1)

BIOS .
1.


: () = 0,
(AL) -
.
, , SI, DI.

() .

(AL)

40*25

, MDA

16 8000

40*25

, MDA

16/8

80*25

, MDA

16 8000

80*25

, MDA

16/8

8000

320*200

, MDA

8000

320*200

, MDA

8000

640*200

, MDA

8000

80*25

MDA

160*200

PCjr

16

320*200

PCjr

16

10

640*200

PCjr

16

8000

ASSEMBLER.

722

11

12

13

320*200

EGA.VGA

16

AOOOO

14

640*200

EGA.VGA

16

AOOOO

15

640*350

EGA,VGA

AOOOO

16

640*350

VGA

16

AOOOO

17

640*480

VGA

AOOOO

18

640*480

VGA

16

AOOOO

19

320*200

VGA

256

AOOOO


. , ,
,
(, , ). 25 40 80 .
(,
) . 200 ( 350) 320 640
. . BIOS.
CGA (3D8H).
- .
.

CGA

3D8H

1 6 5 4 3 2 1 0

1 0 0

b 0

b 0 0 0 0

b 0

b 0 0 0 1

b 0

1 1

b 0

0 - ,

b 1

1 -

1 0 1

-
b - :
0 - ,
1 - ,
- :

8. BIOS

723

0,2 5 1,3 4, ,
. ( );
(RGB), ,
, 1, , 0.
, .
0, , ; 6 7
. (EGA, PCjr, VGA) . (AL).
, , ,
.
,
( 0), MS DOS 2.
BIOS , ()=15INT1 .
:
1. EGA, PCjr, PC Convertible, VGA. 7 (AL) = 1, .
2. EGA. ( ) .
3. PC Convertible. - 2, - - 7. 7 - VGA (640*200)
MDA (640*350).
4. VGA. - 3. , 19, 16 ;
240 .
5. VGA. 3 ( ) 7 (-).
, 19, 64
; 192
.
2.


: ()=1,
() - ,
(CL) - .
.
, , SI, DI.

BIOS .

724

ASSEMBLER.

( ), - BIOS.
.
1 INT 10H.
CL.
, 0, , . (CL) <
(), .
CL : CGA 8 ,
7, MD EGA 13.
: ()
= 6 (CL) = 7 CGA EGA , MDA, () = 11 (CL)
= 12 MDA EGA MDA.
5 6 ()
, , .
,
. ,
( 2 - . ) .
1 .
. , BIOS , , .
. VGA. () ,
a (CL) .
3. .
: () = 2,
() - ,
(DH) - ,
(DL) - .
.
, , SI, DI.
. , , .
0. . , .
.
0 24, - 0 40

725

8. BIOS

80. (DH)=25,
.
2 BIOS ,
. , . ,
() , .

0,1

320*200

40*25

8*8

MDA

320*350

8*14

EGA, VGA

320*400

8*16

360*400

9*16

VGA

8*8

PC-jr,CGA,
PC Convertible

640*200

8*8

EGA, VGA

640*350

8*14

EGA, VGA

640*400

8*16

VGA

720*400

9*16

VGA

2,3

640*200

80*25

4,5

320*200

40*25

8*8

MDA

640*200

80*25

8*8

MDA

720*350

80*25

9*14

MDA, PC Convert

720*350

9*14

EGA, VGA

720*400

9*16

VGA

640*200
160*200

20*25

8*8
8*8

4
1

PC Convertible
PC-jr

160*200

40*25

8*8

PC-jr

10

160*200

80*25

8*8

PC-jr

13

320*200

40*25

8*8

EGA, VGA

14

640*200

80*25

8*8

EGA, VGA

5,16

640*350

80*25

8*14

EGA, VGA

17

640*480

80*30

8*16

VGA

18

640*480

80*30

8*16

VGA

19

320*200

40*25

8*8

VGA

726

ASSEMBLER.


4.
: () = 3,
() - .
: () - ,
(CL) - ,
(DH) - ,
(DL) - .
, , SI, DI.
,
1 2. ,
, . 0.
11.5. , .
5.
: () = 4.
: () - :
0 - ,
1 - ,
() - ;
() - ( 15 -18 - ());
(DH) - ;
(DL) - .
, , SI, DI. () = 0
, DX .
: ( ) . : ,
4 8 .
() = 0 ,
.
. PC Convertible, VGA- ; () = 0; (), (), (DX) .

8. BIOS

727

6.
: () = 5,
(AL) - .
.
, , SI, DI.
. - . . 5. .
. PC-jr. :
(AL) = 80H - . :
(BL) - ,
() - ;
(AL)= 81- .
:
(BL) - ;
(AL) = 82H - . :
(BL) - ;
(AL) = 83H - . :
(BL) - ,
() - .
7.
: () = 6,
(AL) - ,
() - ,
() - ,
(CL) - ,
(DH) - ,
(DL) - .
.
, , SI, DI.
. , () (DX),
(AL) . , , ,
( 20) (). . (AL) = 0 .
: min
{(CH),(DH)} min{(CL),(DL)}, - max
{(CH),(DH)} max {(CL),(DL)}.

728

ASSEMBLER.

8.
: () = 7,
(AL) - ,
() - ,
() - ,
(CL) - ,
(DH) - ,
(DL) - .
.
, , SI, DI.
(AL) = 6 .
9.
: () = 8,
() - .
: (AL)- ,
() - .
, SI, DI.
. . () = 0.
,
.
,
, - . - , m - -
, CGA :
0 1 B8000H+2048*p+80*n+2*m;
2 3 8000+4096*+160*n+2*m.
: 2 - 0 - :
000 - ,
001-,
010-,
011-,
100-,
101-,
-,
111- ;
3 - : 0 - , 1 - ; 6-4- ( , );

8., BIOS

729

; 7 - : 0 - , 1 - .
; , 000,
(., , . 11.1).
,
3 7 .

(. 11.12); (AL) = 8 , ( )
. 0 - 7FH
BIOS; (80 - OFFH)
1FH. BIOS , , . 80 69
OFFH GRAFTABL ,
1FH .
8 ,
(AL) = 0.
10.
: () = 9,
(AL) = ,
() - ,
(BL) - ,
() - .
.
, , SI, DI.
. ()
, .
. ,
() = 1; () = 0 65536 .
, ,
. .
7 BL ,
( XOR).
19 () .
14.

69

730

ASSEMBLER.

11.
: () =10,
(AL) = ,
() - ,
() - .
.
, , SI, DI.
, . .
12.
: () =11,
() - (0 1),
(BL) - .
.
, , SI, DI.
() = 0 .
; (BL) 0 16.
, (320*200) . (. ) 0. ( ) 0 .
() = 1 ( )
. CGA 4 5, (EGA, PCjr)
. (BL) (0 1 CGA).
.
0:
0 - ( ),
1 - ,
2 - ,
3 - .
!:
0 - ,
1 - ,
2 - ,
3 - .
EGA, VGA.
640*400 () = 0, .

8. BIOS

731

13.
: () =12,
(AL) - () ,
() - ,
(DH) - .
.
, , SI, DI.
.
:
, 0
( ) , 1 - .
, 8
(0,2,..., 198), 8 - . , - .
m m :
- 2*(m mod 4) 2*( mod 4)+1
B8000H+8192*(n mod 2)+80* ( n / 2 ) + m / 4
- - 7-(m mod 8)
8000+8192*(n mod 2 ) + 8 0 * ( n / 2 ) + m / 8
(AL): 0,
, 1,
( XOR) .
: , , ().
14.
: () =13,
() - ,
(DH) - .
: (AL) - () ,
, , SI, DI.

(AL). (AL) 0.

732

ASSEMBLER.

: , , ().
15.
: () =14,
(AL) - ,
(BL) - ( ).
.
, .
" " (ODH), " " (), "" (07) "
" (08) .
: .
16.
: () =15.
: () - ;
(AL) - ;
() - .
, SI, DI.
() = 0.
17.

EGA, PCjr, VGA.
1.

.
: () = 1000,
(BL) - ,
() - .
.

1 64 . () :
0 - ,
1 - ,

8. BIOS

733

2 - ,
3 - ,
4 - ,
5 - ,
6 7 .
, - ,
.
.
. , EGA :

01

02

04

05

14

07

38

9
10

12
13
14
15

39

3FH

EGA
2.

.
: ()=100,
() - .
.

734

ASSEMBLER.

3. .
: () = 1002,
(ES:DX) - 17- ,
16 ,
, - .
.
4. .
: ()=1003,
(BL) = 0 - ,
(BL) = 1 - .
, .
VGA.
5.

.
: ()=1007,
(BL) - (0 -15).
: () - .

6.

.
: () = 1008.
: () - .

7. .
: () = 1009,
(ES:DX) - 17- .
: 0-15 - ;
16 - .
8. .
: ()=1010,
() - ,
(DH) - ,
() - ,
(CL) - .
.

8. BIOS

9.

735

: () = 1012,
(ES:DX) - ;
() - ,
() - .
.
: , .
10. .
: ()=1013,
(BL) = 0,
() - :
0 - 4 64 ;
1 - 16 16 .
.
19.
11. .
: () = 1013,
(BL)=1,
() -
(0-3 0 -15 ).
.
. () = 0 64
64- .
.
12. .
: ()=1015,
() - ,
: (DH) - ,
() - ,
(CL) - .
13. .
: ()=1017,
(ES:DX) - ;

736

ASSEMBLER.

() - ,
() -
:
: ,
.
14. .
: () =101 ,
: (BL) - (0 1),
() - .
15. .
: () = 101,
() -
() - .
.
, (30% , 59% 11% ) .
VGA:
() = 1, () = 0712 - ; ;
() = 1003-. 11.17.4;
() = 1010-. 11.17.8;
() =1012-. 11.17.9;
() = 1015-. 11.17.12;
() = 1017-. 11.17.13;
() =101-. 11.17.15.
18. -
() = 11 .
EGA, .
64
. , ,
256 .
. 4-6
128 , - 256 .

8. BIOS

1.

737

( ).
: ()=1100,
(ES:BP) - ,
() - ,
(DX) - ,
(BL) - ( ),
() - ().
.

2. .
: () =1101,
(BL) - ( ).
. 8* 14.
3. .
: ()=1102,
(BL) - ( ).
. 8*8.
4. .
: () = 1103,
(BL) - :
3 - 2 - ,
3 1,
1 - 0 - ,
3 0.
.
11 -1102 () EGA,
, , . 1103 512 .
, , 3,
1103 (BL) = OFH. 3, 3 (. 16.11). 1103 2 (BL) 0 3 1, 3
.
11, , (BL) = ,
512 . 3 0,
0, 3 1 - 1.
24 - 4072

738

ASSEMBLER.

512 , 1 () = 0712
.
5. () = 111 , 1111 1112 () = 1100, 1101 1102 :
-
( 0);
- 0;
- ,
.
.
6. .
: () = 1120,
(ES:BP) -
80 - OFFH ( 8*8 ).
.
7. ( ).
: ()=1121,
(ES:BP) - ,
() - (),
(BL) - :
- (DL),
1-14 ,
2-25 ,
3-43 .
.
8.

8* 14 .
: ()=1122,
(BL) - ( 1121 ).
.

9.

8*8 .
: () = 1123,
(BL) - ( 1121 ).
.

1121 256
00 - OFFH, 1120

8. BIOS

739

1FH. 11 -1112,

.
10. .
: () = 1 ,
() - :
0 - INT IFH,
1 - INT 44H,
2 - 8*14 (),
3 - 8*8 (),
4 - 8*8,
5 - 9*14 ().
: ()- (),
(DL) - ,
(ES:BP) - .
VGA:
() = 1100, 1101.1102 (. 11.18.1-11.18.3);
() = 1120, 1121, 1122,1123 (. 11.18.6 -11.18.9);
11. .
: () =1103,
(BL) - :
4,1,0- ,
3 ,
5,3,2 - ,
3 1.
.
1100 -1102 () , , , . 11 512 .
, , 6,
1103 (BL) = 03. 6, 3 - (. 16.11).
1103 2 (BL) 0, 3 1 5 4,
3 .
1103, , (BL) = 28H,
512 . 3 0,
0, 3 1, - 6.

24'

740

ASSEMBLER.

512 , 1 () - 0712
.
12. 8* 16.
: ()=1104,
(BL) - ( 1121).
(BL) - ( ).
. 8*16.
13. () = 11 -1112 1114 () = 1100 -1102 1104 :
-
( 0);
- 0;
- ,
.
.
14. 8* 16.
: () = 1124,
(BL) - ( 1121).
. 8*16.
15. .
: ()=1130,
() - :
0 - INT IFH,
1 - INT 44H,
2 - 8* 14 (),
3 - 8*8 (),
4 - 8*8,
5 - 9*14 (),
6 - 8* 16 ,
7 - 9* 16.
: () - (),
(DL) - ,
(ES:BP) - .
VGA:

()=1100, 1102,1103(. 11.18.1,11.18.3,11.8.4);


() = 1104 (. 11.18.12);

8. BIOS

741

() = 1120, 1121, 1123(. 11.18.6,11.18.7,11.18.9);


() =1124, . 11.18.14 11.18.15).
. VGA. 1101, 11 -1114, 1122, , 1104, 1100 -1104, 1124. 1100 () = 14, 14- 16-. 11 () =. 5 7.
19. EGA
EGA VGA.

1. .
: () = 12,
(BL)=10H.
:
() = 0 - ( 3DxH),
1 - ( ),
(BL) - :
- 64 ,
1-128 ,

2-192 ,
3-256 ,
() - ( ),
(CL) - .
2.

: () = 12,
(BL) = 20H.
.
5 (
), .
VGA.

3. - .
: () = 12,
(BL) = 30H,
(AL) = 0-200 -,
1 - 350,
2-400.
: (AL) = 12 , . . 30.

741

ASSEMBLER.

4.
: () = 12,
(BL) = 31H,
(AL) = 0 - ,
1 - .
: (AL) = 12, , .
, EGA
16 , 256 .
5. .
: ()=12,
(BL) = 32,
(AL) = 0 - ,
1 - .
: (AL) = 12, , .

-.
6.
: () = 12,
(BL) = 33H,
(AL) = 0 - ,
1 - .
: (AL) = 12 , .
,
() = 0 ( ) () = ( ).
7. .
: ()=12,
(BL) = 34H,
(AL) = 0 - ,
1 - .
: (AL) = 12 , .
, ,
() = 1, . . 30.
8. .
: ()=12,
(AL) - :
0 - ,
1 - ,

8. BIOS

743

2 - ,
3 - .
(ES:DX) - 128-
( (AL) = 1).
: (AL) = 12 , .

BIOS . -, , ,
BIOS - ,
.
() = 12, (BL) = 32, .

. , .
:
1. (AL) = 0;
2. .
. , ((AL) = 2) ((AL) = 3) . .
.
.
9. .
: ()=12,
(BL) = 36H,
(AL) = 1 - ,
- .
: (AL) = 12 , .
30 System/2.
11.20.
: () = 13,
(AL) - :
0 - (BL) ,
1 - (BL) ,
2 - ,
3 - ;
() - ,
(BL) - ( (AL) = 0 1),
() - (),
(DH) - ,

744

ASSEMBLER,

(DL) - ,
(ES:BP) - .
.
2 3 . 0 2 , 1 3
. 14,
" " (ODH), " " (), "" (07)
" " (08); .
13 ,
, BIOS.
21. VGA
1.

.
: () = 1400,
(ES:DI) -
,
() - (1 - 256),
(DX) - (),
(BL) = 0 - ,
1 - , - ;
() - .
.

2.


: ()=1401,
(BL) = 0 - ,
1 -, - ;
.

3.

VGA.
: () = 1402,
(BL) = 0 - ,
1 - ,
2 - ,
3 -
, - .

22.
: ()=15,
: () - :
- ,
5140-VGA,

745

8. BIOS

5153-,
5151 - ;
(ES:DI) - :
1 - ;
2 - PEL ( );
3 - PEL ( );
4 - PEL ,
5 - PEL ,
6 - PEL ()
7 - PEL ().
PC Convertible , . 7.

CGA

VGA

5151

5153

5140

5140

0498

081

15

0987

0280

0280

0352

018

0184

019

PC Convertible.
23.
VGA.
1.
: ()=1.
: (AL) = 1 , ,
(BL) - ,
() - .
VGA:
0 - ,
1 - 5151,
2-CGAc5153/4,
4 - E G A 5153/4,

746

ASSEMBLER.

5-EGA5151,
6 - 5175
7 - VGA ;
8 - VGA ;
11 - VGA ;
12 - VGA ;
255 - ;
.
2.
: () = 101.
(BL) - ,
() - .
: (AL) = 1 , .
24.
VGA.
: ()=1,
() = 0,
(ES:DI) - (40 );
: (AL) = 1 , .
(ES:DI) :
() - ;
02 () - .
:
04 () - (. () = 0);
05 () - ;
07 () - ();
09 () - ;
() - (, );
1 () - () ;
1DH () - ;
1 () - ( - MDA, 3Dx - CGA);
20 () - 3x8;
21 () - 3x9;
22 () - ;
23 () - - ;
25 () - ;

8. BIOS

747

26 () - ;
27 () - , ;
29 () - , ;
2 () - - :
2 () - (. () = 1103);
2 () - (. () = 1103);
2DH () - :
7,6 - ;
5 = 0- , 1 - ;
4 = 1 - ( 30 - 0);
3 = 1- ;
2 = 1- ;
1 = 1- ;
0 = 1 - ( 30 - 0);
2 () - ;
31 () - :
- 64, 1 -128, 2 -192, 3 - 256, - ;
32 () - :
7,6 - ;
5 = 1- DCC,
4 = 1 - ,
3 = 1- ;
2 = 1 - ;
1 = 1 - ;
0 = 1 - 512- .
(13 ) - .
16 ( ,
):
- :
7 - 0 - 7-0;
01 - :
7 - 0 - 15 - 8;
02 - :
3 - 0 - 19-16,
7 - 4 - ;
- 06 - ;
07 - - :
0-200,
1 - 350,
2 - 400,
3 - 7 - ;
08 -

748

ASSEMBLER.

09 -
(. () = 11);
- :
7 - (. () = ; 30 - 0),
6 - (. () = ),
5 - EGA (. () = ),
4 - (. () = 1),
3 - (. () = 12),
2 - (. () = 11 ),
1 - (. () = 12),
0 - ( 30 0);
- :
7 - 4 - ,
3 - DCC (. () = 1 ),
2 - (. () = ),
1 - (. () = 1, 0),
0 - (. () = 4);
OCH-ODH-;
- :
7, 6 - ;
5 = 1- DCC ( 30 0),
4 = 1 - ,
3 = 1 - ,
2 = 1 - ,
1 = 1- ,
0 = 1 - 512- ;
OFH - .
25. .
VGA.
1.

/.
: ()=1,
() - (. ).
: (AL) = 1 , ,
() - ( 64 ).

2.

.
: () = 101,
() - (. ),
(ES:BX) - .
: (AL) = 1 , .

8, BIOS

3.

749

.
: ()=102,
() - (. ),
(ES:BX) - .
: (AL)= 1CH , .
.
(
/ ):
15 - 3 ,
2 - (DAC) ,
1 - BIOS,
0 - .

: ;
.


( 11).
11 . , 0000:0410.
:
15 -14 - (0 - 3); 13 (
) - ; 12 ( ) -
; 11 - 9 - ;
8 - ;
7-6 ( 0 1) - (00 -1,01-2,
10-3,11-4);
5 - 4 - ,
BIOS:
00 - ,
01- 1(40*25, . 11.1),
10 - 3 (80*25),
11 - 7 (80*25);
3 - 2 - ( );
2 - "";
1 - ;
0 - ,
.
.
: 8INT1.

750

ASSEMBLER.

. . 11 - .

( 12).
12 .
, 0000:041 .
(
000:0000); 640. BIOS ,
.

88 1 15.

( 14).
INT 14H RS-232-C:
() = 0 - ;
1 - ;
2 - ;
3 - ;
4 - ;
5 - .
, . - BIOS.
1. .
: () = 0;
(DX) - (0 - 3)
BIOS 40:0;
(AL) - :
1,0 = 00 - 5- ,
= 01- 6- ,
= 10 - 7- ,
= 11- 8- ;
2 =
0-1 -,
1 - 2 - 6-8- ,
1,5 - 5- ;

= 0- ,
= 1 - ;

8. BIOS

751

= 0 - ,
= 1 - ;
7-5 - ():
= 000-110
= 100-150
= 010 - 300
= 110-600
= 001 - 1200
= 101 - 2400
= 011-4800
= 111-9600
: () - ,
(AL) - (. 15.4).
2.

: ()=1;
(DX) - (0 - 3)
BIOS 40:0;
(AL) - .
: () - (. 15.4),
(AL) - .
7 1,
. .
3.
: () = 2;
(DX) - (0 - 3)
BIOS 40:0;
(AL) - .
: () - (. 15.4),
(AL) - .
BIOS .
4. .
: () = 3;
(DX) - (0 - 3)
BIOS 40:0;
: ()- :
7 - -
6 - ()
5 - ()

752

ASSEMBLER.

4 - ()
3 - -
2 -
1 -
0 - ()
(AL) - :
1 -
( 109),
6 - ( 125),
5 - ( 107),
4 - ( 106).
5.
.
: () = 4;
(DX) - (0 - 3)
BIOS 40:0;
(AL) = 0 - Break,
1- Break,
() - :
-,
1 - ,
2 - ,
3 - stick (?) ,
4 - stick (?) ,
(BL) = 0-1 -,
1 - 2 - 6-8- ,
1,5 - 5- ;
() = 0 - 5- ,
1 - 6- ,
2 - 7- ,
3 - 8- ;
(CL) - ():
0-110
1 - 150
2-300
3-600
4 - 1200
5 - 2400
6 - 4800
7-9600
8 - 19200.
: () - ,
(AL) - (. 4).

8. BIOS

6.

753

:
() = 0500 - ,
() = 0501 - .
1. : () = 0500,
(DX) - (0 - 3)

BIOS 40:0;
:
(BL) - :
0 - (DTR, 108),
1 - ( 105),
2 - OUT 1,
3 - OUT2,
4 - ( ),
5 - 7 - .
2. : () = 0501,
(DX) - (0 - 3)
BIOS 40:0;
(BL) -
( 1).
: ()- ,
(AL) - (. 15.4).


( 13).
BIOS .
. , DOS, INT 13H , .
BIOS . 8. 0-5
. , (DL) , 0 - 7FH , 80 - OFFH - .
.
, , () = 90FDH 15, , . .
INT 1 BIOS
90 15 , -

ASSEMBLER.

754

; ,
.
91 15,
. 90 91 (, ).

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

8. BIOS

755

BIOS
1.


: () = 0,
(AL) - .
: (CF) = 0 - ,
= 1 - , (. . 7).

(DL) < 80, , - . () ;


,
0000:0441.
, , (, ),
. .
:
, 7 (DL) ,
.
2.


: ()=1,
(DL) - .
: () - ,
(CF) = 0 - 0 (. . 9)
= 1 - .

(DL), ,
.
BIOS . 9.

00

01

02

03

04

05

756

ASSEMBLER.

06

07

08

09

OD

OF

10

11

20

40

80

FF


:
0000:0441, -
474.
3.


: () = 2,
(AL) - ,
(DL) - ,
(DH) - ,
() - ,
(CL) - ,
(ES:BX) - .

8. BIOS

757

: (CF) = 0 - ,
= 1 - ,
() - ,
(AL) - .
. , , .
, .
() 8 ,
7 6 (CL).
: (AL) = 0 , .
4.
: () = 3,
(AL) - ,
(DL) - ,
(DH) - ,
() - ,
(CL) - ,
(ES:BX) - .
: (CF) = 0 - ,
= 1 - ,
() - ,
(AL) - .
.
, , . , .
() 8 ,
7 6 (CL).
: (AL) = 0 , .
5.


: () = 4,
(AL) - ,
(DL) - ,
(DH) - ,
() - ,

758

ASSEMBLER.

(CL) - ,
(ES:BX) -
(CF) = 0 - ,
= 1 - ,
() - ,
(AL) - .

^11,). . , , . , .
() 8 ,
7 6 (CL).
:
1. (AL) = 0 , .
2. ES:BX (AT, PC Convertible, System/2).
6.


: () = 5,
(AL) -
,
() - ( - 8 ),
(CL) - 6-7
,
(DL) - ,
(DH) - ,
(ES:BX) - ,
( , . ).
: (CF) = 0 - ,
(CF) = 1 - , .

. , , .
ES:BX , , :
0 - ,
1 - ,
2 - ,
3 - :
-128 ,
1-256 ,
2-512 ,
3-1024 .

8. BIOS

759

, ,
17 18 13, , .
; BIOS . 1. .
( , ) .
(AL) , . , ES:BX,
, (. ).
, 0, BIOS 1, DOS :
0 1 1 2 0 1 2 2 . . . 0 1 9 2
ES:BX 512- , , . ( , ) :
0 = 00 - ,
80 - ;
1 - .
, (AL) (. 7).
:
BIOS; 01 ( ).
7.


: () = 6,
(AL) - ,
() - (8 ),
(CL) - 6-7 ,
(DL) - ,
(DH) - ,
: (CF) = 0 - ,
(CF) = 1 - , .

, . , , .

760

ASSEMBLER:

: BIOS (. 5). .
8. , .
: () = 7,
(AL) - ,
() - (8 ),
(CL) - 6-7 ,
(DL) - ,
(DH) - ,
: (CF) = 0 - ,
(CF) = 1 - , .
, . ,
, .
: BIOS (. 5), , IBM AT System/2 01. .
9.


: () = 8,
(DL) - .
: (CF) = 0 - ,
(ES:DI) - 11 -
(. . 8), ,
() - ( 8 ),
(CL) - 5-0,
6-7,
(DH) - ,
(DL) - , ,
.
() = 0 ( ),
(BL) - 3-0:
001 - 360 , 40 -,
010-1.2 , 80 -,
011 - 720 , 80 ,
100 -1.44 , 80 .

. (BL) ,
(, CMOS ); (BL) = 0.

8. BIOS

761

8 .
( , ). . 24, - . 27.
10.
: () = 9,
(DL) - .
: (CF) = 0 - ,
(CF) = 1 - , .
, , .
.
41 . . 11. (IBM AT, System/2), ,
0 41 , 1 - 46. ,
: .
11.
: () = ,
(DL) - ,
(DH) - ,
() - ,
(CL) - 6-7.
: (CF) = 0 - ,
(CF) = 1 - , .
.
, BIOS .
12.
: (AH) = ODH,
(DL) - .
: (CF) = 0 - ,
(CF) = 1 - , .

762

ASSEMBLER.


(. 14.1).
13.
: ()=10,
(DL) - .
: (CF) = 0 - ,
(CF) = 1 - , .
.
0.
14.
: ()=10,
(DL) - .
: (CF) = 0 - ,
(CF) = 1 - , .
.
15.
: ()=15,
(DL) - .
: (CF) = 0 - ,
()- :
0 - ,
1 - , ,
2 - , ,
3 - ;
(CX:DX) - ,
(CF) = 1 - , .
,
, , .
16.
: ()=16,
(DL) - .
: (CF) - ,

8. BIOS

763

() - :
- ,
01 - ,
06 - ,
80 - .
. (CF) , (CF) = 1
() = 6.
17.
: ()=17,
(DL) - ,
(AL) - :
1 - 320/360 ,
2 - 360 ,
3 - 1.2 ,
4 - 720 .
: (CF) = 0 - ,
(CF) = 1 - , .
. , . .
18.
: ()=18,
(DL) - ,
() - (, 8 ),
(CL) - , ,
.
: (CF) = 0 - ,
(ES:DI) - ,
(CF) = 1 - , .
. , .
(. .).
( ), -

764

ASSEMBLER.

. , . , .
19.
System/2.
: ()=19,
(DL) - ;
: (CF) = 0 - ,
(CF) = 1 - , .
.
20.
IBM ESDI .
: ()=1,
(AL) = 0 -
;
- .
(ES:BX) - ;
(CL) - :
7 - 5 ;
4 - .

,
.
: 0 - , 1 - ,
2 - . BIOS
15 () = OFH.
CF
, - ,
3 - .

,
,
2 - .
1,
,
1 - ;
0 - .
(DL) - .

8. BIOS

765

AT ( 15).
BIOS 15 . ( 0-3)
. BIOS INT 15H . INT 15H :

00

01

02

03

OF

21

40

41

42

43

44

4F

80

81

82

83

84

85

SysReq

86

87

88
89

90

91

766

1.

ASSEMBLER.

BIOS


: () = 0.
: (CF) = 0 () = 0.

(CF) = 1 ,
. () = 86.
2.


: ()=1.
: (CF) = 0 () = 0.

(CF) = 1 ,
. () = 86.
3.

: () = 2,
(ES:BX) - ,
() - .
: (CF) = 0 - ,
(ES:BX) - ,
(DX) -
(CF) = 1 - ,
() - : 01 - ,
02 - ,
04 - .
PC-jr.
(CF) = 1 ,
. () = 86.

8. BIOS

767

4.
: () = 3,
(ES:BX) - ,
() - .
: (CF) = 0 - ,
(ES :) - ,
,
(DX) -
(CF) = 1 - ,
() - : 01 - ,
02 - ,
04 - .
PC-jr.
(CF) = 1 ,
. ,
() = 86.
5. .
IBM ESDI
. 15 () = OFH (. 14.20) : (AL) = 0 - , (AL) = 1 - , (AL) = 2 - .
BIOS (CF) = 1, . ESDI,
, (CF) = 0.
: (AH) = OFH,
(AL) - (0 - 2),
: (CF) = 0 - ,
1 - .
6.
System/2, 30,
, (POST).
(CF) = 1 ,
.

768

1.

ASSEMBLER.

POST.
: () = 2100.
: (ES:DI) - ,
() - (),
() = () = 0.

2. POST.
: () = 2101,
() - ,
(BL) - .
: (CF) = 0 () = 0 - ,
(CF) = 1 () = 1 - .
7.
PC Convertible.
(CF) = 1 () = 80 86 ,
.
: () = 40,
(AL) - :
0 - ,
1 - ,
2 - ,
3 - ,
() - 1 3,
() - 1.
: (CF) = 0 - ,
(AL) = 0 - ,
() - ,
() - 0
(CF) = 1 (AL) = 80H - .

. ( , ): () 15 = 0-
"" , = !(*)- "" , 14 = 0- , = !(*)- , 13 -12 -
: 00 - , 01 - 40*25 CGA (VGA
), 10 (*) - 80*25 CGA (VGA
), 11 - 80*25 , 11 -10 - VGA: 00 (*) - -

8. BIOS

769

, 01 - , 10 - , 11 - , 9 = 0 (*) -
, 1 - , 8 = 0 (*) - , 1
- , 7 - 0 - .
() 15 - 8 - ( ),
, 7 - 0 - ( ) .
:
() 15-14-,
13 = 0 (*) - ,
1 - ,
12 -10 - :
000 - ,
001 - ,
010 - , ,
011 (*) - , ,
100 - ,
- ,
9 - 8 - :
00-,
01-,
10(*)-1200,
11 - 2400 ,
7 - 0 - .
8.

PC Convertible.
(CF) = 1 () = 80 86
, .
.
() .
: () = 41,
(AL) - :
00 - ,
01 - ,
02 - ,
03 - ,
04 - ,
- 14 - 00 - 04,
, -,
25-4072

770

ASSEMBLER.

() - ,
(BL) - - (55 ),
(ES:DI) - ( 4 AL 0),
(DX) - - ( 4 AL 1).
(CF) = 1 - -.

01,02,11 12 , ,
, 03,04,1 14 - TEST.
9.

PC Convertible.
(CF) = 1 () = 80 86 , .
: () = 42,
(AL) - :
00 -
(. 40),
01- .
: (CF) = 1 - ,
() - .
, ; (CF)= 1 .
,
. (AL) = 1, (. 40) "" , , .
:
.
10.
PC Convertible.
(CF) = 1 () = 80 86
, .
: () = 43.
: (CF) = 0 - ,
() - ,
(AL) -
(CF) = 1 - ,

8. BIOS

771

:
7 = 1 - ,
6 = 1- ,
5 = 1- (
),
4 = 1 - ,
3 = 1- ,
2 = 1 - ,
1 - ,
0 = 1 - (VGA) .
(. 8 1 , ).
11.
PC Convertible.
(CF) = 1 () = 80 86 , .
: () = 44,
(AL) = 0 - ,
1 - .
: (CF) = 1 - ,
(AL) = 80H - ,
(CF) = 0 (AL) = 0 - .
(. 40).
12.
: (AH) = 4FH,
(AL) - - .
: (CF) = 1 - - ,
(AL) - -
(CF) = 0 - - (AL ).

(INT 9) . - .
: BIOS.
BIOS ( ) (CF) = 1 () = 80 (CF) = 1 ()=
86. INT 15H , .
BIOS, , - .
25*

772

ASSEMBLER.

13.
: () = 80,
() - ,
() - .
: (CF) = 0 - ,
1 - .
,
.
,
. () BIOS.
PC, PC-jr BIOS XT.
14.
: () = 81,
() - ,
() - .
: (CF) = 0 - ,
1 - .
,
.
,
. () BIOS.
PC, PC-jr BIOS XT.
15.
: () = 81,
() - .
: (CF) = 0 - ,
1 - .
,
.
, . () BIOS.
PC, PC-jr BIOS XT.

8. BIOS

773

16.
: () = 83,
(AL) - :
0 - ,
1 - ,
(ES:BX) - ,
,
,
(CX:DX) - .
: (CF) = 0 - ,
1 - .
,
. (AT BIOS 1/10/84) 0.
, , ,
ES:BX. 1 ; 0. 976 . (). , () = 98 (DX) = 9680 - 10 .
17.
: () = 84,
(DX) - :
0 - ,
1 - resistive inputs
: (CF) = 1 - ,
- ,
0 4-7 (AL) - ;
1 () - (),
() - (),
() - (),
(DX) - ().
(Joystick) BIOS . PC, PC-jr BIOS XT.

774

ASSEMBLER,

18. SysReq
: () = 85,
(AL) - :
0 - ,
1 - .
: (CF) = 0 - ,
1 - .
, BIOS, , CF.
SysReq. (INT 9) SysReq, .
PC, PC-jr BIOS XT.
19.
: () = 86,
(CX:DX) - .
: (CF) = 0 - ,
1 - .
,
. 976 . (). , () = 98 (DX) = 9680H
10 .
. PC, PC-jr BIOS XT.
20.
: () = 87,
() -
( 8000, 64 ),
(ES:SI) - (. ).
: (CF) = 0 -
1 - ,
() - :
0 - ,
1 - ,
2 - ,
3 - .

8. BIOS

775

BIOS Intel 80286 ( 16 ). DOS , 1.


ES:SI , 8 . :
0 -1 - (),
2-3- 24- ,
4 - 24- ,
5 - ,
6 - 7 - .
, (ES:SI), ( ):
- , 000000;
- ;
000000; BIOS;
- ;
- ;
- ; 000000; BIOS;
- ; 000000; BIOS.
, 0,
. :
- , ,
2**(()-1);
- ;
- 93, .
. ,
.
21.
: () = 88.
: (CF) = 0 - ,
() - ,
100000
(CF) = 1 - .
BIOS Intel 80286 ( 16 ). , BIOS -

776

ASSEMBLER.

. .
22.
: () = 89, () - , ( IRQ 0); (BL)
- , , (ES:SI) - (. ).
: () = 0 ( (CF) = 0) - , (CF) = 0 ()
- ; (CF) = 1 - .
BIOS Intel 80286 ( 16 ). , .
, .
(ES:SI) ,
.
( ):
- 000000;
- ;
000000; BIOS;
- ; ;
- ; ;
- ; ;
- ; ;
- ; ;
- BIOS; 000000; BIOS.
, , BIOS, -. . , , . . BIOS.
23.
: () = 90,
(AL) - (. ).
: (CF) = 0 - ,
1 - .

8. BIOS

777

90 , ,
.
, , ,
.
:
- 00 - 7FH
( ,
);
- 80 - OBFH (
-; (ES:BX) );
- - OFFH ,
(-). :
00 - - ,
01 - - ,
02 - ,
03 - - ,
80 - ; (ES:BX) ;
OFDH - ,
OFEH - (-).
. ,
(CF) = 1 () = 80 86 .
24.
: () = 91,
(AL) -
: (CF) = 0 - ,
1 - .
91 ,
, (.. ). ,
(INT 9) ,
, .
. - . 16.21.
. ,
(CF) = 1 () = 80 86 .
25.
: () = .
: (CF) = 0 () = 0 - ,
(ES:BX) -
(CF) = 1 - .

778

ASSEMBLER.

:
0 - (8);
1 - ,
2 - ( );
3 - BIOS;
4 - ;
5 - 8 - ().
:
7 = 1- BIOS 3 ;
6 = 1 - ;
5 = 1- ;
4 = 1 - ?
() = 4FH INT 15H;
3 = 1- ;
2 - 0 - .
. ,
(CF) = 1 () = 80 86 .
PC, PC-jr BIOS XT.
: 3
, , , IBM .
26. BIOS
System/2.
: () = 1.
:
(CF) = 0 - ,
(ES) - BIOS.
, (CF) = 1 () = 80 86
.
16.27. ""

"" System/2. ,
(CF) = 1 () = 80 86 .
1.


: () = 200,
() = 0 - ,
1 - .

8. BIOS

2.

779

(CF) = 0 - ,
= 1 - ;
() - :
0 - ,
1 - ,
2 - ,
3 - ,
4 - Resend
5 - .

: () = 201.
: (CF) = 0 - ,
= 1 - ;
() - ( 1)
() - ,
, :
- ,
- 100 ,
- 4 ,
- 1:1,
- , .
(BL) .
3.


: () = 202,
() - :

4.

0-10
1-20
2-40
3-60
4-80
5-100
6 - 200
(CF) = 0 - ,
= 1 - ;
() - ( 1).


: () = 203,
() - :
0-1
1-2

780

ASSEMBLER.

5.

2-4
3-8
(CF) = 0 - ,
= 1 - ;
() - ( 1).

ID
: () = 204.
: (CF) = 0 - ,
. = 1 - ;
() - ( 1),
() - .

6.

: () = 205,
() - :
- ,
- (1 - 8).
: (CF) = 0 - ,
= 1 - ;
() - ( 1).
, :
- ,
- 100 ,
- 4 ,
- 1:1.
7.
: () = 206,
() = 0 - ,
1 - 1:1,
2 - 2:1.
: (CF) = 0 - ,
= 1 - ;
() - ( 1).
() = 0 (BL),
()():
(BL) 7 - (0);
6 = 0- (stream),
1 - (remote);

8. BIOS

781

5 = 0- ,
1 - ;
4 = 0- 1:1,
1 - 2:1;
3 - (0);
2 = 1 - ,
1 - (0);
0 = 1 - ,
(CL) =00-1 ,
01-2 ,
02-4 ,
03-8 ;
(DL) - (10, 20,40, 60, 80, 100 200).
8.
: () = 207
(ES:BX) -
: (CF) = 0 - ,
= 1 - ;
() - ( 1).
,
, - .
BIOS.

:
1 - :
7 = 1- Y,
6 = 1 - X,
5 = 1- Y,
4 = 1 - X,
3 - ( 1),
2 - ( 0),
1 = 1- ,
0 = 1 - ,
15 - 8 - ;
2 - X ( 15 - 8 - );
3 - Y ( 15 - 8 - );
4 - .
, .

782

ASSEMBLER.

28. " "


System/2, 30.
, (CF) = 1 () = 80 86 .
: () = ,
(AL) = 0 - - " ",
1 - -,
()- (1-255).
: (CF) = 0 - ,
1 - .
" " - , .
29.
System/2.
, (CF) = 1 () = 80
86 .
1. POS.
: () = 400.
: (CF) = , (AL) = ,
(DX) - POS.
2. .
: () = 401,
(BL) - .
: (CF) = 0 - ,
1 - .
3. .
: () = 402.
: (CF) = 0 - ,
1 - .

( 16).
BIOS . 3.
0-2 BIOS. . ,

8. BIOS

783

1 , 11 12 , -
. - :
1. ( )
, - .
2. ,
-, . -,
- .
.
3. -.
0 1
- , . .
, . 11.
, - 12 BIOS, , 5, OFFH - OFFH. 5 (AL) = 0, , 5, , 11 12 . , 16 () = OFFFFH,
-12 .

1.

00

01

02

03

04

05

10

11

12


: () = 0.
:
(AL) - ,
() - - .

784

ASSEMBLER.

- BIOS ().
BIOS , .
90 15,
() , . 91 INT 15H.
: ( , ) - () (AL) = 0.
2.
: () = 1.
: (ZF) = 1 - ,
(ZF) = 0 -
(AL) - ,
() - scan- .
0 , (), . BIOS , (ZF) = 1.
3.
: () = 2.
: (AL) - ,
() .
(AL) ,
0417.
4.


. (AL) = 0,...,4 PC-jr, (AL) = 5 - AT System/2.
: () = 3,
(AL) - :
0 - ,
1 - ,
2 - ,
3 -
,
4 - ,
5 - ;

8. BIOS

785

(BL) - ( 5),
() - ( 5).
1 ,
. - .
5 (BL) 0 31,
30 2 ( (BL) ). ()
. 0 3, 0.25
1 .
5.

(PC-jr, PC Convertible).
: () = 4,
(AL) = 0 - ,
1 - .
.
6.
BIOS ,
. PC, PC-jr,
PC Convertible BIOS XT AT.
: () = 5,
() - -,
(CL)- .
: (AL) = 0 - ,
1 - .
7.
: () = 10.
: (AL)- ,
(AL) - - .
, , 0, BIOS (. 1), PC, PC-jr, PC Convertible BIOS XT AT.
26 - 4072

786

ASSEMBLER.

8.
: () = 11.
: (ZF) = 1 - ,
(ZF) = 0-
(AL) - ,
() - scan- .
, , 1, BIOS (. 1). PC, PC-jr, PC Convertible BIOS XT AT.
9.


: () = 12.
: (AL) - ,
() - .

(AL) ,
0417, () - ,
0418. PC, PC-jr, PC Convertible BIOS XT AT.

( 17).
BIOS :
() = 0 - ,
() = 1 - ,
() = 2 - .
1.


: () = 0,
(AL) - ,
(DL) - .
: () - (. 18.3).

(DL) 0408. (DL)


.
2. .
: () = 1,
(DL) - .
: () - (. 18.3).

8. BIOS

787

(DL) 0408. (DL)


.
3.

: () = 2,
(DL) - .
: () - :
7 = 1 - ,
6 = 1 - ,
5 = 1 - ,
4 = 1 - ,
3 = 1 - ,
0 = 1 - -,
2 1 .
(DL) 0408. (DL)
.

( 1).
BIOS, . 0 1 ,
.

00

01

02
03
04
05
06

07

08
09

0
80
26'

788

ASSEMBLER.

.
1.
: () = 0.
: () - ,
(DX) - ,
(AL) - .
(INT 8)
0470.
0. AL
, , 24 (
), (AL) = 1.
, , , , .
2.
: () = 1,
() - ,
(DX) - .
.
. , 1800.
, .
3.
: () = 2.
: (CF) = 1 - ,
(CF) = 0 - ,
()-,
(CL) - ,
(DH) - ,
(DL) = 0 - 24- ,
1 - 12- .
(AT, System/2),
12- .
.
, () = 0904, (DH) = 12 9 4 12 .

8. BIOS

789

. , . 0.
4.
: () = 3,
()-,
(CL)-,
(DH) - ,
(DL) = 0 - 24- ,
1 - 12- .
: (CF) = 0 - ,
(CF) = 1 - .
(AT, System/2),
12- .
. , () = 0904,
(DH) = 12H 9 4 12 .
5.


: () = 4.
: (CF)=1> ,
(CF) = 0 - ,
()- (XIX XX),
(CL) - ,
(DH) - ,
()-.

(AT, System/2).
. , () =
1988, (DX) = 1127 27.11.1988. 1 (. 20.3).
6.

- "

: () = 5,
()- (XIX XX),
()-,
(DH) - ,
(DL) - .

790

ASSEMBLER.

(CF) = 0 - ,
(CF) = 1 - .
(AT, System/2).
. , () = 1988,
(DX) = 1127 27.11.1988.
7.


: () = 6,
()-,
(CL) - ,
(DH) - .
: (CF) = 0 - ,
(CF) = 1 - .

(AT, System/2).
. , () = 0904,
(DH) = 12 9 4 12 .
4, . BIOS .
8.

.
: () = 7.
: (CF) = 0 - ,
(CF) = 1 - .

(AT, System/2).
, .
9.
: () = 8,
()-,
(CL) - ,
(DH)-.
: (CF) = 0 - ,
(CF) = 1 - , ,
.
, ,
System/2.

8. BIOS

791

10.
: () = 9.
: (CF) = 1 - ,
(CF) = 0 - ,
()-,
(CL) - ,
(DH) - ,
(DL) - :
0 - ,
1 - , ,
2 - .
, ,
System/2.
(. 20.3).
11.
: () = .
: (CF) = 1 - ,
(CF) = 0 - ,
() - 1.01.1980.
,
BIOS. 0 .
12.
: () = ,
() - 1.01.1980.
: (CF) = 0 - ,
1 - .
,
BIOS. 0 .

792

ASSEMBLER.

13. .
PC-jr.
: () = 80,
(AL) - :
0 - 2 8253,
1 - ,
2 - "Audio In" -,
3 - .
: (CF) = 0.
(CF) = 1 ,
.

9.
-.
.
Intel
: IN ( ) OUT ( ). 286-
, INS OUTS (. 26), . IN OUT.
FFH, : IN AL,port,
IN AX,port, OUT port,AL, OUT port,AX. FFH, DX: IN AL,DX, IN AX,DX, OUT
DX,AL,OUTDX,AX.
IN/OUT, ,
, .. , . , . :
JMP
:

JMP SHORT $+2. , - . , . , , . , .

.
AT Intel 8042. :
;
;
() ;
;
.
:
( ). FOh. scan-. FOh ( ) 7- scan-. , , . , .

794

ASSEMBLER.

.
64. :
0 - 0, .
1 - . , .
2 - , .
3 - , . 1,
, 0 - .
4 - , 0, .
5 - 1, .
6 - 1, .
7 - 1,
, .. .
. : 60h - , 64 .
. 60.
. .
:
0-3 - .
4 - RAM .
5 - -.
6 - .
7 - , .
, , .
. ( DOH)
( D1H). :
0 - , .
1 - 20.
2-3 - .
4 - 1, .
5 - 1, .
6 - .
7 - .
. .
0 - .
1 - .
2-7 .
.
, 64, , 60.
20. .

9. -

795

60. ( 60).
:
0 - 1 ,
.
1 - 0.
2 - .
3 - 1, .
4 - 1 .
5 - . I ,
scan-.
6 - .
7-0.
. . ,
55h.
(. 20h 60h).
.
. :
00- ,
01 - ,
02 - ,
03 - ,
04 - .
. 16- , , . scan-.
, -.
ADH. .
. .
. .
.
DOH. .
.
D1H. .
.
1 .
FOH-FFH - .
.

60. ,
. , , 60h . , FEH.
EDH. . , 3 , 0:0 - Scrol Lock, I - Num Lock, 2 - Caps Lock.

796

ASSEMBLER.

.
(). .
EFH, F1H. .
FOH. -. : 0 , 1 - 1,2- 2,3- 3.
F2H. . ,
- 83.
F3H. . 0-6:
= (1 +2*6+5)*250;
= 4.17*(8+4*2+2*+)*2*(2*4+).
F4H. .
, .
F5. ,
.
F6h. , .
F7h-FAh. :
F7h - ,
F8h - ,
F9h - ,
FAh - .
FBh-FDh. .
FBh - ,
FCh - ,
FDh - .
scan- ( 3).
FEh. - .
FFh. . AAh
, FCh - .

(. 12.1), .
23,
.
CODE

SEGMENT
ASSUME CS:CODE, DS:DATA, SS:STAK
BEGIN:
MOV AX, DATA
.
MOV DS,AX
MOV _CL, 0
MOV COUNT,0
MOV AL, 0

9. -
;
;,
MOV AL,00000010
OUT 21H,AL
LOO:
/,
CALL WAIT_IN_BUF
;
MOV AL,OEDH
OUT 60H,AL
;
CALL WAIT_OUT
IN AL,60H
; ?
CMP AL,OFAH
JNZ ERR1
; ,
CALL WAIT_IN_BUF
MOV AL,00000001B
MOV CL,_CL
;
SHL AL,CL
OR
_AL,AL
MOV AL,_AL
OUT 60H,AL
;
CALL DELAY
INC _CL
; ?
CMP _CL, 3
JNZ LOO
MOV _CL,0
MOV _AL, 0
CALL WAIT_IN_BUF
/
MOV AL,OEDH
OUT 60H,AL
CALL WAIT_OUT
IN AL,60H
CMP AL,OFAH
JNZ ERR1
CALL WAIT_IN_BUF
MOV AL,0
OUT 60H,AL
INC COUNT

797

798

ASSEMBLER.

; ?
CMP COUNT,20
JZ
_END
CALL DELAY
JMP LOO
ERR:
POP

AX

ERR1:
MOV
OUT
LEA
INT
MOV
INT

AL, 0
21H,AL
DX,MES
21H
AX,4C01H
21H

_END:
MOV AL, 0
OUT 21H,AL
MOV AX,4COOH
INT 21H

;,
WAIT_IN_BUF PROC
XOR CX,CX
Tl:
IN A L , 6 4 H
TEST AL,2
LOOPNZ Tl
JNZ ERR
RETN
WAIT_IN_BUF ENDP

;,
WAIT_OUT PROC
:
IN A L , 6 4 H
TEST AL,1
JZ
T3
RETN
WAIT_OUT ENDP
DELAY PROC
XOR CX,CX
LL1:
PUSH CX
MOV CX,50
LL2 :
LOOP LL2
POP CX

9. -

799

LOOP LL1
RETN
DELAY ENDP
CODE ENDS
DATA SEGMENT
_CL
DB ?
_AL
DB ?
COUNT DW ?
MES DB
' !',13,10,'$'
DATA ENDS
STAK SEGMENT STACK
DB 50 DUP(?)
STAK ENDS
END BEGIN

. PI2.1. .

.
7
( ). .
BIOS 3- .
, 0:408h,
LPTn, = 1,2,3. .

LPT1

LPT2

378

379

37

LPT3

278

279

27

.
.
0-7 - .
.
:
0-1 -,
2-0 .
3-0 .
4-1 .
5 -1 .
6 - 0 - .
7 - 0 - .

v,,

800

<

ASSEMBLED.

.
:
:
0 - , 1,
.
1 - 1, .
2 - 0 - .
3 -1 - .
4 -1 - .
5 - 0 - , 1 - .
,
17 .
, , , (,
). - . 7 (. 7.8).

DMA.
DMA -, . ( ).
AT DMA,
4 . . DMA , 7
. ,
0.
DMA 8- 16- . 16- 8 . , . ( ).
DMA 7 :
1. . 08. - . - 8.
. . :
0 - 0 - , 1 - .
1 - 0 - , 1 - .
2 - 0 - , 1 - .
3 - 0 - , 1 - .
4 - 0 - , 1 - .
5 - 0 - , 1 - .
v
6 - 0 - , 1 -
.

9. -

801

2. . 08. . - 8.
.
0-3 - 0-3.0 - , 1 - . 4-7 -
0-3.0 - , 1 - .
3. . 09. . - 8.
.
-1 :
00- ,
01-!,
10 - 2,
11 - 3.
2 - : 0 - , 1 - .
.
4. . . . - 8.
.
-1 ( ).
2 - : 0 - , 1 - .
, .
5. . . . - 8.
.
0-1 (, .).
2-3 - :
00 - ,
01 - ,
10 - ,
11 - .
4 - : 0 - , 1 - .
5 - : 0 - , 1 - .
6-7 - :
00 - ,
01 - ,
10 - ,
11 - .
6. . . . - 8.
.
.
7. . OFH. . - 8.
.
0-3 - : 0 - , 1 - .
.

802

ASSEMBLER.

8, . ODH. . - 8.
.
, :
1. . -16. ,

0

1
02h
2
04h
3
06h
2. . -16. ,

0
OOh
1 .
02h
2
04h
3
06h
3. . -16. ,

0
Olh
1
03h
2
05h
3
07h
4. . 16. ,

0
Olh
1
03h
2
05h
3
07h
5. . 8. .
0
87h
1
83h
2
81h
3
82h
DMA
: . 24- .
10000, 20000 .. ,
.. 64.
.
DMA ,
.
:
;
, ;

9. -

803

, , ;
, DMA.
.
:
, ;
;
, .
.
. .
. .
.
.
16- .
AT.
4-7:
- ,
- ,
- D2H,
- D4H,
- D6H,
- DAH,
- DEH,
- D8H,
- DAH,
- .
4-7:
1. . -16. ,

4
COh
5
C4h
6
C8h
7
CCh
2. . -16. ,

4
COh
5
C4h

804

ASSEMBLER.

C8h

6
7

3. . -16. ,

4
C2h
5
C6h
6
CAh
7
CEh
4. . -16. ,

.,.,.

5 "
6
7

C2h

. . . . . .

. .

C6h
CAh
CEh

5. . -8. ,

4
8Fh
5
8Bh
6
89h
7
8Ah
DM A.
.
,
1. .
2. , .
3. .
4. .
. , ,
3 :
MOV AL,00000111
OUT OAH,AL

.
1:
. MOV AL,00000001B
OUT 09H,AL

. - , - .
MOV AL,0111D010B
OUT OBH,AL

9. -

80S

.
-,
1 - ,
2 - ,
3 - ,
4- ,
5-,
6 -,
7-.
DMA (. ).

.
. :
,
,
,
.
MFM - .
IBM PC .
:
,
,
.
:
GAP4A - , . 80 , 4.
SYNC - , . 12 , OOh.
- , . 3 2
FCH.
GAP 1 - , .
50 , 4.
:
- SYNC- 12 , OOh.
IDAM - . 3 1
, FEh - .
CYL - ( ).

806

ASSEMBLER.

HEAD- . .
SEC - , .
NO - , . 128*2ANO.
CRC1 - - .
GAP2 - 22 , 4.
DATA AM - .
. 3 1 FBH ( ), F8H ( ),
.
CRC2 - (2 ).
GAP3 - , .
. :
5.25/360 - 80,
5.25/1.2 - 84,
3.5/720 - 80,
3.5/1.4 - 108.
:
GAP4B - , . 4.
.
3FOH.

. 4. .
.
0-1 - 1 0 1 , .
2-3 - .
4 - 1 .
.
5 - 1 .
SPECIFY DMA.
6 - 0 - , 1 - .
7 - 0 - , 1 - .
. 5. . .
. 7.
. .
7 ( ) , .

9. -

807

. 7.
. .
0-1:
00 - 500 /
01-300 /
10-250 /
11 - .
. 2. . .
0 - .
1=1.
2 - 0 - , 1 - .
3 - 0 - DMA , 1 - .
4-0 0,1 - .
5-0 1,1- .
6-7 - .
. . .
0.

-1:
00 - ,
01- 1,
10- 2,
11 - 3.
2 - (), .
3 - .
4 - 1, ,
77 " ".
5 - (1).
6-7:
00 - ,
01 - ,
10 - ,
11 - .
1.
0 -1 - .
1 -1 - .
2 -1 - .
3 - .
4 -1 - DMA.
5 - .
6-.
7 - 1
.

808

ASSEMBLER.

2.
0 -1, .
1 -1, FFH.
2 - .
3 - .
4 -1, .
5-1 .
6-1 "".
7 - .
3.
0 - .
1 - .
2 - ().
3 - .
4-1 0.
5 - .
6 -1 - .
7-.
.
: (1), (2), (3). , .
- ,
- ,
R - ,
N - ,
EOT - ,
GPL - (GAP3),
DTL - (0 128 FFH ),
STO - ,
ST1 - 1,
ST2 - 2,
ST3 - 3,
HDS - ,
DS - ,
HLT - ,
HUT - ,
- ,

9. -

809

NCN - ,
PCN - ,
SK - ,
SRT - ,
- ,
SC - ,
D - ,
SSEL - .
.

, .

1 SK 0 0 1
1 0
0 0 0 0 0 HDS 0 D S

R
N
EOT
GPL
DTL

STO
ST1
ST2

"' ' ' '

H
R
N
.

1 SK O i l
0 0
0 0 0 0 0 HDS 0 DS

R
N
EOT
GPL
DTL

810

ASSEMBLER.

2
3

STO
ST1
ST2

R
N

1 0 0 0 1

01

0 0 0 0 0 HDS 0 DS

R
N
EOT
GPL
DTL
2
3

STO
ST1
ST2

R
N

1 0 0 1 0
01
0 0 0 0 0 HDS 0 DS

R
N
EOT
GPL
DTL

9. -

2
3

STO
ST1
ST2

R
N

0 1 0 0 0 0
10
0 0 0 0 0 HDS D S

R
N
EOT
GPL
DTL

2
3

STO
ST1

ST2

R
N

0 1 0 0 1 1 0 1
0 0 0 0 0 HDS 0 DS
N
SC
GPL
D

R
N

811

812

ASSEMBLER.

2
3

STO
ST1
ST2

. .

'

0 1 0 0 1 0 1 0
0 0 0 0 0 HDS 0 DS

2
3

STO
ST1
ST2

R
N

.
.

0 1 0 0 0 1 1 1
0 0 0 0 0 0 0 DS

. .

0 0 0 0 1 1
11
0 0 0 0 0 HDS D S

1
3

0 0 0 0 1 0 0 0
STO
PCN

813!

9. -

0 0 0 0 0 1
0 0
0 0 0 0 0 HDS D S
ST3

"". .
'..,;

. . . . . .
0

__

UT

0
_

14

ND

SRT.

500

250

0
1

16
15

26.7
25

32
30

OFH

2
1

3.33
L67

4
2

HUT.

500

30QK

250

0
1

256
16

426
26.7

512
32

OFH

224
240

373
400

HLT.

500

250

0
1
2

256
2
4

426
3.3
6.7

512
4
8

OFH

252
254

420
423

504
508

'

448
480

.
.

SRT+HUT

HLT

SSEL

5.25/360
5.25/1.2

360
360

DFH
DFH

02
02

02
01

GPLR/WIF
2|50
2|50

814

ASSEMBLER.

5.25/1.2
3.5 /720
3.5/1.44
3.5/1.44

1.2
720
720
1.44

DFH
DFH
DFH
AFH

02H
02H
02H
02H

02H
02H

1BHJ54H
2AH 1 50H
2AH|50H
1BH|6CH

.
1.4. , . . ,
, 12.5.
; 1.4
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
ORG 100H

BEG:

/ DMA
CALL " SETCOORD
/
XOR AX,AX
MOV ES,AX

MOV AX,ES:[OEH*4+2]
MOV CS:OLDINTSE,AX
MOV AX,ES:[OEH*4]
MOV CS:OLDINTOF,AX
MOV AX,OFFSET NEWINT
CLI
MOV ES:[OEH*4],AX
MOV AX,CS
MOV ES: [OEHM+2] ,AX
STI
;
;
MOV DX,03F7H
/
MOV AL,0
; 500 /.
OUT DX,AL
JMP SHORT $+2
;
CLI
/ DMA, ,
;
MOV AL,00011000
MOV DX,03F2H

9. -

815

OUT DX,AL
JMP SHORT $+2
; 29
MOV DX,35
CALL TIMERM
/ DMA, , ,
MOV AL,00011100
MOV DX,03F2H
OUT DX,AL
JMP SHORT $+2
CALL WAITINT
;
CMP ERROR,0
JZ
DALl
JMP _ERR
DALl:
; 4
/ ""
MOV ,4
MOV
DL,11000000
RES:
CALL SENSI
CMP ERROR, 1
JNZ
DAL2
JMP _ERR
DAL2 :
MOV AH,STO
TEST AH,DL
JZ
DAL3
JMP _ERR
DAL3 :
INC DL ;
LOOP RES
; (0.5 )
/,
MOV ,500
_WAIT1:
MOV DX,1190
''" ""''CALL TIMERM
LOOP _WAIT1
/ SPECIFY
/
/
MOV
AL,3
CALL OUTFP
CMP ERROR, 1

ASSEMBLER.

816

DAL4

JNZ
JMP

ERR

MOV
CALL
CMP
JNZ

AL,OAFH ; 1.4
OUTFP
ERROR,1
DAL5

DAL4:

JMP

ERR

DAL5:
MOV
CALL
CMP
JNZ
JMP

AL,2H
;
OUTFP
ERROR,I
DAL
_ERR

DAL6:
; RECALIBRATE
;
; , .. 80
;
MOV CX, 2
RECAL:
CLI
MOV AL,7
CALL OUTFP
CMP ERROR,1
JNZ DAL7
JMP
_ERR
DAL7:
MOV AL, 0
0
CALL OUTFP
CMP ERROR,!
JNZ DAL8
JMP
_ERR
DAL8:
CALL WAITINT
CMP ERROR,1
JNZ DAL9
JMP
_ERR
DAL9:
;
CALL SENSI
CMP ERROR,1
JNZ DAL10
JMP
_ERR
DAL10:

9, -

/
MOV AH,STO
AND ,11000000
JZ COMPL
ESHE:
LOOP RECAL
JMP
ERR
COMPL:
MOV DX,18750 ; 15
CALL TIMERM
;
; SEEK
;
CLI
MOV AL,OFH
CALL OUTFP
CMP ERROR, 1
JNZ DAL23
JMP _ERR
DAL23:
MOV AL, 0
CALL OUTFP
CMP ERROR,1
JNZ DAL231
JMP _ERR
DAL231:
MOV AL,0
;
CALL OUTFP
CMP ERROR,1
JNZ DAL232
JMP _ERR
DAL232:
CALL WAITINT
;
CMP ERROR,1
JNZ
DAL589
JMP
_ERR
DAL589:
;
CALL SENSI
CMP ERROR,1
JNZ
DAL345
JMP _ERR
DAL345:
MOV DX,18750 ; 15
CALL TIMERM
27 - 4072

817

ASSEMBLER.

818

/ DMA
; ( 46)
MOV
,512
MOV
AL,046H
CALL SETDMA
;
CLI

MOV AL,046H
CALL OUTFP
CMP ERROR,1
JNZ DAL 11
ERR
JMP
DAL11:

MOV AL,0
CALL OUTFP
CMP ERROR,1
JNZ DAL111
JMP _ERR
DAL111:

/ ,

/ - "- "- -""""""

MOV AL, 0
CALL OUTFP
CMP ERROR,1
JNZ
DAL1112
JMP _ERR
DAL1112:
/ " * " " . . -

MOV AL,0
CALL OUTFP
CMP ERROR,1
JZ _ERR

; :

MOV AL,1
CALL OUTFP
CMP ERROR,!
JZ _ERR

; 1

MOV AL,2
CALL OUTFP
CMP ERROR, 1
JZ _ERR

; 2

_ _ _ _ _ _ _

^ ._. -._.__________.,

MOV AL,18
CALL OUTFP

9. -

JZ

ERROR,1
ERR

MOV AL,1BH
CALL OUTFP
CMP ERROR, 1
JZ
ERR

MOV
CALL
CMP
JZ

AL,OFFH
OUTFP
ERROR,1
_ERR

i
;
CALL WAITINT
CMP ERROR,1
JZ
_ERR
/
CALL SENSI
;
CMP ERROR, 1
JZ
_ERR
MOV AH,STO
AND AH,11000000B
JNZ _ERR
CALL WSE
;

LEA DX,TEXT2
MOV AH,9
INT 21H
; () 36
; (8 ),
;. FAT12.
MOV SI,OFSSECT
ADD SI,36H
MOV CX,8
L002 :
LODSB
MOV DL,AL
MOV AH, 2
INT 21H
LOOP L002
JMP SHORT _END
;
ERR:

27'

819

820

ASSEMBLER.

; STO ( )
MOV DL,STO
MOV ,2
INT 21H
MOV ,9
LEA DX,TEXT1
INT 21H
_END:
CALL WSE
RET
;
/ DMA
;AL -
; -
SETDMA
PROC
PUSH

PUSH

PUSH
/ (10)
CLI
MOV
AL,00000110
OUT
OAH,AL
JMP
$+2
POP
AX
OUT
OCH,AL
;
JMP
$+2
;
; 46 = 01000110
;.. 2 (10), (01)
; (0),
; (01)
OUT
OBH,AL
JMP
$+2
;
PUSH

; DMA
MOV
AX,OFSDMA
;
4,AL
OUT
;
JMP
$+2
MOV
AL,AH
OUT
4,AL
;
$+2
JMP
MOV
AL,SEGDMA
;
OUT
81H,AL
JMP
$+2

(0),

.9. -


; 512-1
POP
AX
DEC
AX
OUT
5,AL
;
JMP
$+2
MOV
AL,AH
OUT
5,AL

JMP
$+2
;
MOV
AL,00000010B
OUT
OAH,AL
JMP
$+2
STI
POP
CX
POP
AX
RET
SETDMA
ENDP
;
INFP PROC
PUSH AX
PUSH
PUSH CX
PUSH DX
PUSH DI
MOV DI,OFFSET STO
MOV ERROR,0
MOV DX,3F4H
/
MOV BH,7
LO;
MOV BL,2
MOV CX,0
LI:
/
IN AL,DX
TEST AL,10000000B
JNZ L2
LOOP LI
DEC BL
JNZ LI
MOV ERROR,1
JMP SHORT ER
L2:
;
INC DX
IN AL,DX

821

822

ASSEMBLER.

STOSB
; STO
DEC DX
;
PUSH DX
;
MOV DX/35
CALL TIMERM

POP DX
/
IN

AL,DX

TEST AL,00010000B
JZ
DEC

ER
BH

JNZ

LO

MOV ERROR, 1

ER:
POP
POP
POP
POP
POP
RET
INFP ENDP

DI
DX
CX
BX
AX

/
/AL -
OUTFP PROC
MOV ERROR,
PUSH AX
PUSH
PUSH DX
PUSH CX

MOV

DX,3F4H

MOV BL,2
XOR CX,CX

MOV AH,AL
L001:
/,
IN AL,DX
/
TEST AL,10000000B
JNZ _OUT
LOOP L001
DEC BL
JNZ L001
MOV ERROR,!
JMP SHORT _END_OUT

OUT:

9. -

INC DX

823

MOV A L , A H

OUT DX,AL
;
JMP SHORT $+2
; 29
MOV DX,35
CALL TIMERM
_END_OUT:
POP CX
POP DX
POP BX
POP AX
RET
OUTFP ENDP
,- N .
; N/(0.840336)=M
/
; DX (M)
TIMERM PROC
PUSH AX
PUSH DX
/ 2 . . - . .
IN AL, 61H
AND AL,11111100B
OUT 61H,AL
JMP SHORT $+2
/ :
/
/ 2
/
/ 2
MOV AL,10110100B
OUT 43H,AL
MOV AL,OFFH
OUT 42H,AL
JMP SHORT $+2
OUT 42H,AL
JMP SHORT $+2
IN AL,61H
OR AL,01H
/
OUT 61H,AL
JMP SHORT $+2

. . .

824

ASSEMBLER.

; ,
;
NEC DX
WAITING:
;
; 2
/""
MOV AL,10000100
OUT 43H,AL
JMP SHORT $+2
IN AL,42H
XCHG AH,AL
IN AL,42H
XCHG AH,AL
CMP DX,AX
JB WAITING
, POP DX
POP AX
RETN
TIMERM ENDP
;
NEWINT PROC
PUSH AX
MOV FLAG,1 /
;
MOV AL,20H
OUT 20H,AL
POP AX
IRET
NEWINT ENDP
/ SENSI -
SENS I PROC
PUSH AX
MOV AL, 8
;
CALL OUTFP
CMP ERROR,1
JZ
_ENDS
CALL INFP
; STO
_ENDS:
POP AX
RET
SENSI ENDP
;
WAITINT PROC
PUSH CX
PUSH DX

9. -

MOV FLAG,
MOV ERROR,
STI
;
MOV ,2000
_WAIT:
MOV DX,1190
CALL TIMERM
CMP FLAG,1
;
JZ _RET
LOOP _WAIT
MOV ERROR, 1
_RET:
POP DX
POP CX
RET
WAITINT ENDP
; DMA
SETCOORD PROC
; ,
;
LEA
AX,SECTOR
MOV
BX,CS
MOV
CL,4
SHL
BX,CL
ADD
BX,AX ;
JC
DAL
MOV
DX,BX
;
ADD
BX,512
JNC
DAL
/
;
SUB
AX,DX
DAL:
OFSSECT, AX ;
MOV
; DMA
DX,AX
MOV
MOV
AX,CS
,
;ii
MOV
CL,4
/
ROL
AX,CL
MOV
CH,AL
;

825

826

.ASSEMBLER.

AND
ADD
ADC
MOV
AND
MOV
RET

AL,OFOH
AX,DX
CH,
OFSDMA,AX
CH,OFH ' "
SEGDMAyCH

/
;
;
; 4

; : " .

SETCOORD ENDP
/
WSE PROC
/ . uv.^ ' ; , . , : . - . . - , . - : . ";
,
. :
/ DMA, , ,
MOV AL,OQo6lOOQB
;
M O V DX,,03F2H . " . , . . . . . ' .
OUT DX,AL
JMP SHORT $+2
;
MOV AX,OLDINTOF
-CLI ' . . ' .
MOV ES:[*4},
MOV AX,OLDINTSE
,
MOV ES:[OEH*4+2],AX
STI
RET
WSE ENDP
/ 512 ,
/ DMA
SECTOR
DB
2*512 DUP(O) /
/
OFSSECT
DW
?
OFSDMA
DW
?
SEGDMA
DB
?
ERROR
DB
?
/
OLDINTOF DW ?
OLDINTSE DW ?
FLAG DB 0
/
/
STO DB 0
/ STO
1
DB '',13,10, '$'
2
DB ' ','$'
CODE ENDS
'
END BEG
. PI2.2. .

9. -

827

.
27.

.
. .
BIOS.

.
AT, ,
, . .
:
976.562 .;
;
.
0 (IRQ 8).
14 . 70, 71 (. 23). 14
(RTC):

01
02

04
05

07
08
09

ODH
32

!
2
3
4

CMOS 23,
.

828

ASSEMBLER.

1. - . , 7-
2 0. ,
( 1 7- 3).
2.
( 2, 5). , 7
2 0.
3. 976.562 .
6 2.
4. , 4 2.
(. 12.3) . 70
. , , .
, .
, 1024 (1/0.000976562
= 1024), . , , , .
CODE SEGMENT
ASSUME CSrCODE,

DS:CODE

ORG 100.H

BEGIN:

.
.
MOV WORD PTR PRIZN,0 /
/
MOV ,

MOV ES,AX
/
MOV AX,ES:[70H]
MOV OFF__70,AX
MOV AX,ES:[70H+2]
MOV SEG_70,AX
/
CLI
LEA AX,INT_70
MOV ES:[70H],AX
PUSH DS
POP AX
MOV ES:[70H+2],AX
/ 976.562 .
MOV AL,OBH
OUT 70H,AL
JMP SHORT $+2
IN AL,71H
OR AL,01000000B
MOV AH,AL
MOV AL,OBH

.. :
v ,,'

9. -

OUT 70H,AL
MOV AL,AH
JMP SHORT $+2
OUT 71H,AL
STI
;
LOO:
CMP WORD PTR PRIZN,100
JB LOO
;
MOV AL,OBH
OUT 70H,AL
JMP SHORT $+2
IN AL,71H
AND AL,10111111B
MOV AH,AL
MOV AL,OBH
OUT 70H,AL
MOV AL,AH
JMP SHORT $+2

OUT 71H,AL
;

MOV AX,OFF_70
MOV E S : [ 7 0 H ] , A X
MOV AX,SEG_70
MOV ES:[70H+2],AX
RET
;
INT_70 PROC
/
INC WORD PTR CS:PRIZN / DS:PRIZN
;
MOV AL,OCH
OUT 70H,AL
JMP SHORT $+2
. IN AL,71H
IRET
INT_70 ENDP
;
PRIZN DW ?
OFF_70 DW ?
SEG_70 DW ?
CODE ENDS
END BEGIN

Puc. PI2.3.

829

836

> , ASSEMBLER.

6 .
: INC WORD PTR CS:PRIZN.
INC WORD PTR DS:PRIZN, .. DS (. 9).

.

RS232C.
:
,
,
,
,
.
. :
1-0040:0000
2-0040:0002
-0040:0004
4-0040:0006
:
. 3 .
.
0-1 - :
00-5 ,
01 -6 ,
10-7,
11-8 .
2 - -, 0-1 -, 1-2- - (1.5
5 ).
3-1 - .
4 - (0 - , 1 - ).
5 - .
6 -1 - "", .
7 - (. ).
. 0 . . 0.
. 0 . . 0.

9. -

831

. 0 . .
!.
. 1
. . 1.
.

0900h

0600h
0180h
OOCOh
0060h
0040h

0020h
001 8h
OOlOh
OOOCh
0006h
0003h
0002h
OOOlh

50
75
150
300

600
1200
1800
2400
3600
4800
7200
9600
19200
38400
57600
115200

. 1 . . 0. :
0 - , 1 - , 0 - ,
1 - , 1 , 0 - ,
2 - , 1 - , 0 - ,
3 - , 1 - , 0 - ,
4-7 - .
. 2 . . :
0 -1 - , 0 - ,
1-2:
11 - , ,
, - ,
10 - , - ,

, w

832

ASSEMBLER.

01 - , -
,
00 - , -
.
0.
. 4 .
.
-1 - " " 1,0- ,
1 -1 - " " 1,
2 -1 - Out 1 1,
3-1 - Out2 1,
4 - .
. 5 . .
0 -1 - ,
1 -1 - - ,
,
2 - ,
3 - -,
4 - "",
5 - ,
6 - .
.
. 6 . .
0 - CTS,
1 - DSR,
2 - ,
3 - DCD,
4 - CTS,
5 - DSR,
6 - RI,
7 - DCD.
9 (. 9.4).

.
.
. , .

9. -

833

.
. . 43. ().
. 16 . : 0 - 40, 1 41, 2 - 42. ( ).
. .
( ). , .
.
. .
, . - .
:
) CLK - ,
) GATE - , 2, .,
) OUT - : 0 -
0,1 - , 2 - .
.
0 - 0 - , 1 - - .
1-3 - :
000- ,
001 - 1,
!0-2,
x l l -,
100 - 4,
101 - 5.
- .
4-5 - - :
00 - ,
01 - ,
10 - ,
11 - , .
6-7 - :
00- ,
01-!,
10- 2,
11 - .
.
:
) , .
) .

834

ASSEMBLER.

.
(. ).
:
7 - 0 - , 1 - ,
6 - 0 , 1 - ,
.
.
42.
:
- ,
,
.
:
( 2),
(. ).
.

.
.
( ).
0 . .
1. ( ). 2.
2. .
.
3. , .
.
4. 0 ( 0).
5. 2. 0.

.
0.840336 . . 1. ..
1 0.840336 . ,
, OFFFFH=65535. .. , .,
, 0.840336*65535=55071.41976 . , , N .,
(N* 1000000)755071.41976.
.
6.

9. -

835

1. , . ,
. , ,
, ,
.
CODE SEGMENT
ORG 100

ASSUME CS:CODE, DS:CODE


BEGIN:
MOV AH, 9
LEA DX,TEXT1
INT 21H
MOV CX,182
; 10 .
;10/(0.000000840336*65535)=181.58238962
CALL TIMER
MOV AH, 9
LEA DX,TEXT2
INT 21H
RET
;
;
TIMER PROC
; 2
IN AL,61H
AND AL,11111100B
OUT 61H,AL
JMP SHORT $+2
; :
;
; 2
;
; 2
MOV AL,10110100B
OUT 43H,AL
MOV AL,OFFH
;
OUT 42H,AL
JMP SHORT $+2
;
OUT 42H,AL
JMP SHORT $+2

836

ASSEMBLER.

IN AL,61H
OR AL,01H
/
OUT 61H,AL
JMP SHORT $+2
MOV BX,OFFFFH
WAITING:
;
; 2
/""
MOV AL, 10000100
OUT 43H,AL
JMP SHORT $+2
;
IN AL,42H
XCHG AH,AL
/
IN AL,42H
XCHG AH,AL
;
CMP AX,BX
MOV BX,AX
JB
WAITING
LOOP WAITING
RETN
TIMER ENDP
TEXT1 DB '...10 . ',13,10,'$'
TEXT2 DB '... ',13,10,'$'
CODE ENDS
END BEGIN
. PI2.4. .
, [25], .
, 10 .,
TIMERM, .
.
CODE SEGMENT
ORG 100

ASSUME CSrCODE, DS:CODE


BEGIN:
MOV AH,9
LEA DX,TEXT1
INT 21H

9. -

; 10 .
MOV , 1 0 0 0 0
LOO:

/ 1000 .
; 1000/(0.84033)=1190.0001904
MOV DX,1190
CALL TIMERM
LOOP LOO
MOV ,9
LEA DX,TEXT2
INT 21H
RET
;
; DX
TIMERM PROC
; 2
IN AL,61H
AND AL,1H11100B
OUT 61H,AL
JMP SHORT $+2
; :
;
; 2
;
; 2
MOV AL,10110100B
OUT 43H,AL
MOV AL,OFFH
OUT 42H,AL
JMP SHORT $+2
OUT 42H,AL
JMP SHORT $+2
IN AL,61H
OR AL,01H
;
OUT 61H,AL
JMP SHORT $+2
/ ,
/
NEC DX
WAITING:
;
/ 2
/""

837

ASSEMBLER.

838

MOV AL,10000100
OUT 43H,AL
JMP SHORT $+2
IN A L , 4 2 H
XCHG A H , A L
IN A L , 4 2 H
XCHG AH,AL
CMP D X , A X
JB WAITING
RETN
TIMERM ENDP
TEXT1 DB ' . . . 1 0 . ' , 1 3 , 1 0 , ' $ '
TEXT2 DB '.
',13,10,'$'
CODE ENDS
END BEGIN
Puc. PI2.5. .

.
I. .
9 . .
9, .

->0

->4

4-

20

20
fffffj

20
(ISRj

9, -

839

:
1.
. IRR .
2. (IMR). ,
.
3. (PR). , .
4. ( INT) (ISR).
5. CLI, , ..
IRR. INT
.
6. , INTA.
ISR IRR. .
7. . CLI.
. AT
. () , (). .. 15 : 8 7 .
:
()

COM2
1
LPT2

LPT1

8
9
10
11
12
13
14
15
3
4
5
6
7

840

ASSEMBLER.

.
.
1. ( ).
2. .
3. INTA.
.
1. . .
.
2. .
,
.
3. . .
4. .

.
.
. 20 21, .
1. .
.
1. :
=1,
1 -
,
2 = ,
3 - AT ,
4=1,
5 = 0,
6 = 0,
7 = 0.
20 ().
2. :
-2 = 0,
-'
3-7 - 5 ( ).
21 ( 1).

9. -

841

3. :
- 00000100,
- 00000010.
21 ( 1). .
4. :
0-1 ( Intel),
1-0 ( 1 - ),
2 - ,
3 - ,
4 - 0 - .
21 ().
2. .
(IMR). 21 (1).
. :
0-2 - , . ,
= 0,
4 = 0,
5-7;
,
001 - 1 (. ),
011 - 2,
101 - ,
..,..
100 - ,
000 - ,
111 - ,
110 - ( ),
010 - .
20 ().
. :
0-1:
10 - IRR,
11 - ISR.
2 = 0,
=1,
4 = 0,
5-6:
10 - ,
11 - .
20 ().
.

842

ASSEMBLER.

.
61. .
.
:
0-0 GATE ( GATE
), 1 - ,
1 - 0 - , 1 - ,
2 - 0 - , 1 - ,
3 - 0 - , 1 - ,
4 - ,
5 - OUT 2 ,
6 - 0 - , 1 - ,
7 - 0 - , 1 - .
:
0 - GATE , 1 - ,
1 - 0 - 2 , 1 - ,
2 - 0 - , 1 - ,
3 - 0 - , 1 - ,
4-6 - ,
7 - .

.
, . , ,
IBM PC.
(F). , MS DOS , Windows 70.
. , ,
.
1. ..,.. . 80286. ., 1990.
2. .. . . ., 1991.
3. . . IBM PC XT.
. .,1991.
4. . . IBM PC . .,1992.
5. . . IBM
PC XT AT. .,1992.
6. - , . . 8086/8088. ., 1987.
7. , , . " ", 4, 5, 1992.
8. RICHARD WILTON.PROGRAMMER'SGUIDTOPC&PS/2VIDEOSYSTEMS.
MAXIMUM VIDEO. PERFORMANCE FROM THE EGA, VGA, HGC AND
MCGA. MICROSOFT PRESS, 1987, WASHINGTON.
9. . . IBM MS
DOS. .,1991.
10. . , . . IBM PC. M., 1993.
11. MICROSOFT. MS-DOS. PROGRAMMER'S REFERENCE. VERSION 4.X.
MICROSOFT PRESS, 1988, WASHINGTON. (F).
12. .. . . ., 1992.
13. Tech Help. The Electronic Technical Reference Manuel. By Dan Rollins. 1990. (F).
14. . . ., 1992.
15. .. , . . . .
., 1992.
16. , , , ( , USA). . 1990.
"Mixed-Language Programming Guide", Microsoft. (F).

70

Windows.

844

ASSEMBLER.

17. . . IBM.
18. . . 80286. Versus Ltd., M., 1992.
19. . , .. . Intel 80286/80386/
80486. , 1993.
20. ... MASM.M.,1994.
21. .. . IBM. M., 1993.
22. .. . i486. ( 4
). ., 1993.
23. . . MS DOS. , 1992.
24. . . .
, . 1,2. ., 1995.
25. .. , .. .
. , 1995.
26. . , . . . -
IBM PC. , 1990. (F).
27. . . , .. . Microsoft Windows. . , 1992.
28. . C++ Windows 95. . 1996.
29. . Windows 95. . 1996.
30. . . ., 1990.
31. .. , .. . ( 3 )1993.
32. . INTEL 8086 Pentium . -, 1998.

.
. , , .

V
659

VESA

SVGA
..153, 659
VGA
95, 153, 639, 720
..... 134, 830

94, 720
....96, 799

19, 59

19

19, 59

371
( )...... 10, 12

..

61, 70
........ 259
157, 650
85, 88
29, 54, 497
103


25, 120

639

79, 157, 648, 720


. 79, 166, 659, 664, 727

326

323

323

43, 679


663, 721
655

59, 570

....; 59, 570,


....-.......:...;............ 344,

......;.
.220,
........1........
1.....
.........

572
352
293
224
282
284
283

'........... ...... .. ...... 246


.,. .............. ....345
. .................. .66, 570
- . .......... ;........,.. ....92, 736

;'; . ; ' / V ;;,;" . '/.

, ....... ....,..v....... .;,,*.... 204


.................. .......4... ..... 588

............................... 251
.................................. 85, 793
......... . ................................ 32
... 66, 368
..... 41, 367, 671, 692
..................... 377
........................... 549
................ 805
..... ............... 793
........... 130, 838
............... . ................ 43

................................ 683
............................ 685
............... 129
.................... 43
......................... 30, 359
......................... 64, 512
.................................. 262

ASSEMBLER.

846

().. 549

226

204
204

365
39, 360
641
197
559

183,
MS DOS
Windows
Windows NT

- ,


124,

188
74
511
569
75
690
29
133



(conventional)

19,
232, 266,

()



120,


DMA


1
SPX

24
499
485
476
181
485
181, 230
514, 549
232
259

29, 54
19, 683
683
59
471
385, 429
259, 514
82
86
19
388
373
34, 37

(FAT).. 251

832

463
374

114, 702
158, 640
793
199, 588
120
319
804
82
128, 589
388
409

API

252
251
77, 103
512
702
522

827

19