Вы находитесь на странице: 1из 329

-

-
2011

681.3.068+800.92
32.973.26-018.1
17

. .
17

. . 2- ., . .
.: -, 2011. 336 .: . + CD-ROM
ISBN 978-5-9775-0591-8
. Intel, 16- 32- ,
, ,
, . , , ( Norton Commander FAR Manager) .
, , . . - , , .

681.3.068+800.92
32.973.26-018.1

:

.
.

02429 24.07.00. 31.01.11.


70 1001/16. . . . . 27,09.
2000 .
"-", 190005, -, ., 29.
-
77.99.60.953..005770.05.09 26.05.2009 .
.

" ""
199034, -, 9 , 12.

ISBN 978-5-9775-0591-8

. ., 2011
, "-", 2011


................................................................................................................................... 1
.......................................................................................................................... 2
...................................................................................................... 3
I. : ............................................................................. 7
1. ........................................................................................................ 9
1.1. ................................................................................ 9
1.2. ........................................................................................................ 12
1.3. ......................................................................................................... 13
1.4. .................................................................................................................................... 16
2. .................................................................................................. 17
2.1. 808680186 ...................................................... 17
2.1.1. ............................................................................................................. 17
2.1.2. -......................................................................................................... 18
2.1.3. ..................................................................................................... 18
2.2. .......................................................................................... 19
2.2.1. add ................................................................................................................... 19
2.2.2. sub ................................................................................................................... 19
2.2.3. inc .................................................................................................................... 20
2.2.4. dec ................................................................................................................... 21
2.3. ....................................................................................................... 21
3. .............................................................. 23
3.1. . ............................................................................ 23
3.1.1. ................................................................ 25
3.1.2. ................................................................ 25
3.1.3. .............................................. 26
3.2. ............................................................................. 26
3.2.1. ......................................................................... 28
3.3. ...................................................................................................... 32
3.3.1. ASCII? ............................................................................................................. 32
3.4. ....................................................................................................... 33
3.5. ...................................................................................................................... 34
II. ....................................................................................... 37
4. ......................................................................................................... 39
4.1. ..................................................................................... 39
4.1.2. .................................................................................................... 39
4.2. .................................................................................................................... 42
4.2.1. ....................................................................... 43
4.3. ..................................................................................... 44
4.3.1. .......................................................................... 45

IV

4.4. ....................................................................................................... 45
4.4.1. .......................................................................................... 46
5. ............................................................................................................ 47
5.1. ............................................................................................................... 47
5.2. ....................................................................................................................... 48
5.3. ....................................................................................................... 51
5.4. AFD....................................................................................... 53
6. ......................................................................................................... 54
6.1. ......................................................................................................................................... 54
6.2. ....................................................................................................... 61
6.2.1. nop ................................................................................................................... 61
6.2.2. ........................................................................................................... 62
7. ................................................................................................ 64
7.1. 6 ............................................................................................... 64
7.2. ............................................................................................................... 66
7.3. .................................................................... 69
7.4. ASCII ..................................................................................................... 69
7.5. ....................................................................................................... 71
8. ..................................................................................... 74
8.1. .............................................................................................. 74
8.2. .................................................................................................... 76
8.3. ....................................................................................................... 82
9. ........................................................................................................ 84
9.1. .............................................................................................. 84
9.2. ....................................................................................................... 87
III. , , ........................................... 91
10. . .......................................... 93
10.1. ............................................................................................ 93
10.2. ..................................................................................................................................... 97
10.2.1. .......................................................................... 98
? .................................................................................................... 98
? ................................................................................. 98
? .................................................................................................................. 98
? .......................................................................................... 98
? ....................................................................................................... 98
? ....................................................................................................... 98
10.3. ................................................................................................................................ 99
10.3.1. ........................................................................................... 99
10.4. ...................................................................................... 101
10.4.1. ................................................................ 104
10.5. ........................................................................................... 104
10.5.1. ? ........................................................................... 106
11. ................................................................................ 109
11.1. ............................................................................................................................. 109
11.2. ................................................................................................... 112

12. ............................................................................. 115


12.1. .............................................................................................................................. 115
12.2. .................................................................... 115
12.3. ........................................................................................... 118
12.4. xor sub ........................................ 125
12.5. ...................................................... 126
13. : .................................................................... 127
13.1. ................................................................................................................................. 127
13.2. ............................................................................................................................. 128
13.3. movs ..................................................................................... 132
13.4. , ......................... 134
13.5. ..................................................................................................................... 135
14. ................................................................................. 137
14.1. ................................................................................................................... 137
14.1.1. COM?.......................................................... 137
14.1.2. ? ................................................. 137
14.2. SuperShell .......................................................................................................... 139
14.2.1. ................................................................................................. 139
14.2.2. 80286+ ................................................... 140
14.3. () .................................................................................. 142
14.3.1. ........................................................................... 142
14.3.2. Draw_frame............................................................................................... 143
? ................................................................. 144
14.4. ............................................................................................................................. 145
14.5. ............................................................................................................... 145
15. .................................................................. 148
15.1. ................................................................................................................................. 148
15.1.1. ....................................................... 150
15.1.2. .............................. 151
.................................................................................................................... 151
..................................................................................................................... 151
15.2. ret retf .......................................................................................................... 152
15.2.1. ret................................................................................................................. 152
15.2.2. retf................................................................................................................ 153
15.3. . iret ............................................ 155
15.4. ............................................................................................................................. 157
15.5. ..................................................................................... 159
15.5.1. or ................................................................................................................. 159
15.5.2. and ............................................................................................................... 160
15.5.3. xor ................................................................................................................ 161
15.6. .................................................................... 162
15.6.1. 05h ...................................................................................... 162
15.6.2. 09h ...................................................................................... 162
15.6.3. 1Ch ..................................................................................... 163
15.7. ................................................................................................................................ 164
16. ............................................................................ 165
16.1. ....................................................................................................... 165
16.1.1. 03h .......................................................................................................... 165

VI

16.2. ............................................................................... 170


16.2.1. ................................................................................... 170
16.3. ............................................................................................................................. 172
17. ................................................................................... 174
17.1. .................................................. 174
17.2. ................................................................................................................................... 176
17.2.1. "-".................................................................................. 180
17.2.2. "-" ...................................................................... 181
18. ........................................................ 183
18.1. .......................................................................... 183
18.2. 17 .............................................................................................................. 184
18.3. Super Shell ......................................................................................................... 185
18.3.1. .................................................................... 185
18.3.2. ..................................................................................... 192
18.3.3. .......................................... 192
18.3.4. Copy_scr / Restore_scr (display.asm) ...................................................... 193
18.3.5. scas .............................................................................................................. 194
18.3.6. ................................................................. 196
18.3.7. ...................... 198
18.4. ................................................................................................................................ 199
19. ........................................................................... 200
19.1. .............................................................................................................................. 200
19.2. ? ........................................................................... 204
20. ..................................................................................... 205
20.1. ................................................................................................................................... 206
20.1.1. ret, call jmp....................................................................................... 206
20.1.2. ......................................................................................................... 207
20.1.3. ...................................................................................... 210
20.2. ................................................................................................................................ 211
21. .................................................................... 213
21.1. SuperShell .......................................................................................................... 213
21.1.1. .......................................................................................................................... 213
21.1.2. ...................................................................................................................... 214
............................................................................................................... 214
............................................................................................................... 215
21.1.3. test................................................................................................................ 215
21.2. DOS ..................................................................................... 219
21.2.1. .................................................................................................. 219
21.2.2. .................................................................. 222
22. ................................................................................... 223
23. PSP DTA. ( DOS) ................... 225
23.1. ............................................................................................ 226
23.2. ( MS-DOS) ............................................................... 227
23.3. ............................................................................................................ 231
23.3.1. ............................................................................... 232

VII

23.3.2. ................................................................................... 233


23.3.3. " " ............................................................. 235
23.4. ...................................................... 237
24. ........................................................................................ 238
24.1. 80386/80486. ......................... 238
24.1.1. 16- 32- ................................................................................... 240
24.1.2. use16/use32 ................................................................................................ 241
24.1.3. ........................................... 241
24.2. . ................................................................................... 242
24.3. ................................................................................................................................ 247
25. ......................................................................................... 248
25.1. ......................................................................................... 248
25.2. ................................................................................ 249
25.3. ....................................................... 254
25.4. ..................................................... 255
25.5. ............................................................................................................................. 256
25.5.1. .............................................................. 256
26. ............................................................................................ 258
26.1. IBM- ......................................... 258
26.2. ....................................................................................................... 259
26.3. ............................................................................................................................. 260
26.3.1. ....................... 261
26.3.2. ........................................................ 262
27. ............................................................................. 264
27.1. ............................................................................................. 264
27.1.1. 21h .......................................................................................... 264
27.1.2. ? ....................................................... 267
27.1.3. , ........................................................... 268
27.2. ............................................................................................................................. 269
28. ................................................. 271
28.1. ............................................................... 271
28.2. ........................................................................ 273
28.3. ......................................................................................... 274
28.4. <PageUp> <PageDown>.................................................................. 276
28.5. <Home> <End> ............................................................................... 276
29. ................................................................................. 278
29.1. .............................................................. 278
29.1.1. ....................................................... 279
? ....................................................... 279
4 ? ......................... 280
bx (3)?...................................................................... 280
29.1.2. PSP ................................................................................... 280
29.1.3. EPB .......................................................................................................... 281
( DOS) ................. 282
DOS? ............................................................ 283
........................................................................... 283
FCB .................................................................................. 284

VIII

29.1.4. ................................................................................................ 284


29.1.5. ....................................................................................................... 285
29.2. " " ........................................................................................... 286
30. .......................................................................... 288
30.1. (XMS) . .............................................................. 288
30.2. XMSmem.asm. XMS- ......................................... 289
30.2.1.
XMS- ..................................................................................... 289
30.3. XMSblock.asm.
.......................................................................................................... 291
30.3.1. ................................................................................. 293
30.3.2. XMS- ...................................................... 293
30.4. XMScopy.asm.
......................................................................................................... 294
31. ............................................. 296
31.1. Super Shell ......................................................................................................... 296
31.1.1. ........................................................... 297
31.1.2. ................................................................................................ 298
31.2. ............................................................................ 299
31.2.1. ................... 299
31.2.2. - ..... 300

32. ............................................................. 302


32.1. ? ................................................................................................... 302
32.1.1. ............................................................................. 302
32.1.2. .................................................................................................... 303
32.1.3. (FAT) .......................................................................... 304
32.2. ................................................................................... 305
32.3. ............................................................................................... 306
32.3.1. FAT, FAT32 .......................................... 306
............................................................................................................... 307
1. (
) .................................................................................................... 309
1.1. MASM 6.106.13 .............................................................................................. 309
1.2. .............................................................................................................. 309
1.3. ....................................................................................................................... 310
1.3.1. Microsoft (MASM) ............ 311
2. .......................... 312
3. .......................................................................... 313
3.1. ASCII ................................................................................................ 313
3.2. ASCII ................................................................................................ 320
3.3. - ..................................................................................................... 322
4. - ........................................................................ 324
............................................................................................................ 325


, . , , ,
. , , , . , : , ,
.

"? ! ". ,
18 000 ,
. , (
). MS-DOS Windows.
, . , , .
.
, , ,
.
,
, , , .
, ,
, , , .
:
I , ( ), II Windows; III
/ ;
,
;

, ;
;
, 10,
:
;
;
( Norton Commander, FAR Manager . .) XMS-;
(, ).
, ,
. -, , , . , .

- ,
http://www.Kalashnikoff.ru (
).
.
.
(-), .
.
,
, , , , , -.
, !
, . II III.
! ,
, ( , , , .).
, , , , http://RFpro.ru.
,
.


1. ( MS-DOS)
( Windows)?
-, . .
, .
-, WinAPI, ,
MS-DOS. WinAPI
, Windows. , WinAPI.
-, , COM-, MS-DOS Windows, .
2. ?
Microsoft
, . , , MS-DOS 3.30, , , , ,
, .
Windows 95/98/2000/XP/Vista ,
, MS-DOS, DOS-, "" , , ,
, , , DOS4GW.
, (Windows Explorer), . , Norton
Commander, Far Manager,
, .
Microsoft (Windows)
MS-DOS: | | cmd | <Enter>.
,
, COM- MS-DOS.

Microsoft IBM- :
Windows 2000 Pro Server;
Windows XP Home Edition Pro;
Windows Vista/Server 2008/7.

!
,
Windows.
. ? : !

3. ,
, ?
, , , , Akelpad,
- (, Far Manager). ,
, . . . Far Manager
(<F4>). , ,
, , .
,
. MASM.EXE (ML.EXE)
Microsoft, TASM.EXE Borland, FASM .
Windows MASM32.

http://Kalashnikoff.ru. , ,
. MASM 6.11
Macro Assembler Microsoft 6.11 I
MASM32 II, . , 2 http://RFpro.ru.
(AFD, SoftIce, CodeView).
.
AFD CodeView SoftIce
.
, , ,
. IDA,
.
,
: http://www.Kalashnikoff.ru.
4. ?
.
, .
().
().

1. , ,
, . , , , , -

, . ,
Basic, Pascal, C - ,
. , .
, MS-DOS, . .
( | | cmd). Far Manager, Windows Commander, Total Commander . .
5. ?
.
Intel 8086, 80286, 80386, 80486.
16- 32- .
.
.
(XMS-).
.
CGA, EGA, VGA ().
.
BIOS () MS-DOS.
, .
.
.
MS-DOS Windows.
, . . .
6. , ?
, ,
http://RFpro.ru. ,
:

;
;
, .
http://RFpro.ru
!
1 , "Hello, world!".
!

I
:


1.1.
. . . , , , .
, , -
, 10 . :
1 10 = 10
10 10 = 100
100 10 = 1000
. .
0 9, . . (, ).
, ,
"". "" , . . . 0 9 , ,
: A, B, C, D, E, F. F, , 15 (. 1.1).
1.1.

26

1A

27

1B

28

1C

29

1D

30

1E

...

...

...

...

158

9E

I. :

10

1.1 ()

159

9F

10

160

A0

11

161

A1

12

162

A2

13

...

...

14

254

FE

15

255

FF

16

10

256

100

17

11

257

101

...

...

...

...

, -
, 16 ( 1.1).
1.1
1 16 = 10
10 16 = 100
100 16 = 1000

. .
1.1 ?
: 10, 12, 45, 64, 12, 8, 19?
, . , , h H ( .
hexadecimal ),
hex. , , . 0
9 , , 5
5h, . , 1
( 1.2 1.3).
1.2.
1 16 = 10h
10h x 16 = 100h
100h x 16 = 1000h

1.

11

1.3.
1h x 10h = 10h
10h x 10h = 100h
100h x 10h = 1000h

.
, , .
, .
10 ( 0 9) 6 (A, B, C, D,
E, F). -
, 16 . , . . .
,
. ,
,
. , 1.1.
1.1. ,
...
(01)

mov ah,9

(02)

mov al,8

...
(15)

mov dl,5Ah

...

, ,
! , :
(01) -, (15) -.
, -, , , -
. ,
.
. -
. :
mov ah,9

MOV AH,9

I. :

12

. , , , .
, .

1.2.
, (\001\prog01.asm) ( 1.2).
1.2.
(01) CSEG segment
(02) org 100h
(03)
(04) Begin:
(05)
(06)

mov ah,9

(07)

mov dx,offset Message

(08)

int 21h

(09)
(10)

int 20h

(11)
(12) Message db 'Hello, world!$'
(13) CSEG ends
(14) end Begin

: , !
- ( \001\prog01.asm, 001 , prog01.asm
DOS-).
, !
1.2, . .
, .
. , (01), (02) (13) .
(03), (05), (09) (11) .
. -
.
. (04) . , .
(14) end Begin (Begin ; end ). . Begin

1.

13

. , Start. ,
End Start (14).
(06)(08) "Hello, world!".
( ).
. , , :
A=5
B=8
C=A+B
A, B C ( ), . = 5 : " 5".
- mov ( . move ""). (06) : " ah 9" ( , ah 9). , . (07)
dx ( "Hello,
world!$"). , (08) MS-DOS,
. , .

1.3.
MS-DOS ( MS-DOS),
. ( 1.3).
,
. MASM/TASM . :
;
mov ah,9

, .
1.3. ()

A=5

; A 5

B=8

; B 8

Addition
; 13
A=10

; ,

14

I. :

B=25
Addition
; 35

;
...
Addition
C = A + B

; ,

() Addition,
, A B. .
, , ,
, , , .
,
.
(08) (. 1.2)
( ), .
, , , . .
. ( ,
) . (08) : "
" (int . interrupt ).
, 21 h. , , (33 ). ,
int 21h int 33. . ,
.
(10) , , 20h.
- . ( DOS).
20h , (, ). , Norton Commander DOS Navigator. -
exit .
(12) . (message ) . (, mess
string .). (07),
dx .

1.

15

, Mess2. ,
(09), :
...
(09)
(10)
(11)
(12)
(13)
(14)
(15)
(16)

mov ah,9
mov dx,offset Mess2
int 21h
int 20h
Message db 'Hello, world!$'
Mess2 db ' !$'
CSEG ends
end Begin

, , .
Message Mess2 $.
. , 21h
, -
$. , , "" , .
. 1. , COM-, EXE!
COM-, (MASM/TASM) . COM- Macro Assembler 6.11 . 1.1.
2, .
(AFD, CodeView), ( !)
.
, .

. 1.1. Prog01.com

I. :

16

. 1.2. AFD Pro

. 1.2 , AFD Pro.


, , , . .

1.4.
.
, . , 34 ,
.
, , , ,
.
,
, .
, , ,
. , , .
, , ,
, 10 "", FOR,
NEXT, PRINT ., . , - . . ,
, . . , ,
. ,
, . . , " ".
* * *
2
.


2.1.
808680186
, ,
- . 808680186
14 . 1 : ah dx. . 2.1, 2.3
2.4 , ip , .

2.1.1.

( ). : ,
. . 2.1 32- ,
0 4 294 967 295 (0FFFFFFFFh). . 16-, 0
65 535 0h FFFFh , .
8- : ah, al, bh, bl, ch,
cl, dh, dl. 255 (FFh).
( ) 16- .
2.1.
EAX

EBX

ax
ah

bx
al

bh

cx
bl

ch

dx
cl

dh

dl

mov, . , , al 35h, :
mov al,35h

I. :

18

ax 346Ah, :
mov ax,346Ah

, ,
. , :
mov ah,123h

FFh

mov bx,12345h

FFFFh

mov dl,100h

FFh

,
(12h), (5h), : 0C5h.
, - , , . .
, mov ax,1234h.
ah 12h, al 34h. ah, al, bh, bl, ch, cl, dh
dl (Low) (High) 16-
(. 2.2).
2.2.

mov
mov
mov
mov

ax
bx
cx
dx

ax,1234h
bx,5678h
cx,9ABCh
dx,0DEF0h

=
=
=
=

1234h, ah = 12h, al =
5678h, bh = 56h, bl =
9ABCh, ch = 9Ah, cl =
0DEF0h, dh = 0DEh, dl

34h
78h
0BCh
= 0F0h

2.1.2. -
si ( ) di ( ) . bp sp (. 2.3).
.
2.3. -
si

Di

bp

sp

2.1.3.
(. 2.4)
(, ). , .
2.4.
CS

DS

ES

SS

2.

19

2.2.

: add, sub, inc, dec.

2.2.1. add
add . 2.5. .
.
, () ,
. , , .
2.5. add

add ,

Addition

8086

8086, , , (80286, 80386,


80486, Pentium . .).
add ( 2.1).
2.1. add
mov al,10

; al 10

add al,15

;al = 25; al , 15

mov ax,25000

; ax 25000

add ax,10000

;ax = 35000; ax , 10000

mov cx,200

; cx 200

mov bx,760

; bx 760

add cx,bx

;cx = 960, bx = 760 (bx ); cx ,


;bx

2.2.2. sub
sub (. 2.6, 2.2).
2.6. sub

sub ,

Subtraction

8086

I. :

20
2.2. sub
mov al,10
sub al,7

;al = 3; al , 7

mov ax,25000
sub ax,10000

;ax = 15000; ax , 10000

mov cx,100
mov bx,15
sub cx,bx


, . ,
0
65 535.
. , 100 , , 100 . ,
:
...
mov ax,2700
mov bx,15000
add ax,bx
...
ax 17 700,
bx 15 000. add ax,bx
80486. , 486 DX2-66
0 0FFFFh 66 (!) !

2.2.3. inc
inc . 2.7.
2.7. inc

inc

Increment

8086

inc (
). :
add , 1

( 80486)
( 2.3).

2.

21

2.3. inc
mov al,15
inc al

; al = 16 ( add al,1)

mov dh,39h
inc dh

;dh = 3Ah ( add dh,1)

mov cl,4Fh
inc cl

;cl = 50h ( add cl,1)

2.2.4. dec
dec . 2.8.
2.8. dec

dec

Decrement

8086

dec ( 2.4).
:
sub , 1
2.4. dec
mov al,15
dec al

; al = 14

mov dh,3Ah
dec dh

;dh = 39h

mov cl,50h
dec cl

;cl = 4Fh

2.3.
, , .
DOS.
BIOS () 16h,
, 20h,
21h . IO.SYS/MSDOS.SYS
MS-DOS.
, 10h 16h. :
mov ah,10h

; ah

int 16h

; 16h BIOS ()

I. :

22

,
ax , .
(\002\prog02.asm)
, PAUSE BAT- ( 2.5).
2.5.
(01) CSEG segment
(02) org 100h
(03) Start:
(04)
(05)

mov ah,9

(06)

mov dx,offset String

(07)

int 21h

(08)
(09)

mov ah,10h

(10)

int 16h

(11)
(12)

int 20h

(13)
(14) String db ' ...$'
(15) CSEG ends
(16) end Start

(01), (02) (15) . (05)(07),


, . ( (09), (10)) . , (12)
.
inc, dec, add sub. ( ) . , :
...
mov ah,0Fh
inc ah
int 16h
...

.
* * *
3 ,
. .



. ,
. , . ,
. ,
. - !
. , , . 4,
.
,
. : CodeView (CV.EXE)
AFD Pro (AFD.EXE). ,
prog03.asm. , prog03.com. , CodeView/AFD,
MS-DOS :
CV.EXE prog03.com

:
AFD.EXE prog03.com

, !

3.1. .
, . , , , ""?
( ).
, , (
). .
, :
0000 ( ),

0001,

0010 (. . ,
1).

I. :

24

0011
0100
0101
0110
0111
1000
1001

. .
"" "" . , , 0 1, . . ("0" "1" ).
, , ,
, : 0001 ;
0010 ; 0100 ; 1000 . .
. 0 9,
( ; : 1010, 1011, ..., 1111).
. (, , , .) . "" 256 ( 0 255)
. , (09),
(az, AZ), (, ) . (. 3).
(255) 8 .
8 . ,
1 (. 3.1).
3.1. "Z"
0

"" "" "" "" .

.
, , "", <Enter>. , 1 .
,
. ""
4Dh , , 1001101 . , "" 4 4 8 = 32 .
, ()
, "" "".

3.

25

" , (, , ), "-"?" .
, , ( ) (),
. , , , .
b.
, -
, . : 10
, 10h , 10b . ,
, . :
...
mov ax,20
mov bh,10100b
mov cl,14h
...

ax, bh cl , , .
( bh).
, . ( ) : 10101110 10010010 01111010
11100101 (, ; ). . , . . .
, . , . . , "".
, - , ! .

3.1.1.
, ,
.
, 20. :
10100b.
, , 4 0.
:
10100b = 24 + 0 + 22 + 0 + 0 = 16 + 8 = 20

10100b = 1 16 + 0 8 + 1 4 + 0 2 + 0 1 = 16 + 0 + 4 + 0 + 0 = 20.

3.1.2.
, :
20/2 = 10, 0;
10/2 = 5, 0;

I. :

26

5/2 = 2, 1;
2/2 = 1, 0;
1/2 = 0, 1.
: 10100b = 20.

3.1.3.

, 16:
8Ah = 8 16 + 10 (0Ah) = 138.
, . , Windows. DOS
Navigator. ,
, , , .
!

3.2.
: " ".
, "" "" , ... . , .
, 3.1 ( "_" ).
3.1
0000:

0010:

0020:

0030:

"" "" ; "" ,


"" . . , . . ""
: 0000:0003, . . 0000, 0003.
"" , , . "" : 0010:0005, . .
, : 0010 , 0005 .
"" , 0020 . , "" 0020:0001, . . 0020,
0001.

3.

27

, , , , : . : cs, ds, ss, es (. . 2.1.3),


( ):
cs (code segment );
ds (data segment );
ss (stack segment );
es , (, ).
es:di
"" "" 3.1.
( 3.2).
3.2
...
(1)

mov ax,0020

(2)

mov es,ax

(3)

mov di,2

...

es 20, di () "" "". , ...


, ( ) . (1) ax, (2) 20 ax es.
mov ds,15

;!

mov ss,34h

;!

,
. COM
( ,
, ).
. , , COM ,
5674h,
:
cs = 5674h
ds = 5674h
ss = 5674h
es = 5674h

: cs = ds = ss = es = 5674h.
COM 100h. ,
, org 100h,

I. :

28

100h
, ( ,
). , , , . cs:ip
.

3.2.1.
, , ( 3.1).
3.1.
(01) CSEG segment
(02) org 100h
(03) _start:
(04)

mov ah,9

(05)

mov dx,offset String

(06)

int 21h

(07)

int 20h

(08) String db 'Test message$'


(09) CSEG ends
(10) end _start

, (01) (09) :
( ) segment ( , ,
);
CSEG ends (END Segment ) .
(02) , ,
100h. COM.
3.1 AFD Pro. ,
1DF1h (. 3.1). (04)
:
CSEG
CSEG

1DF1h:0100h (. . cs = 1DF1h, ip = 0100h)

cs ip!
. AFD
<F1>, CodeView <F8>, , ;
- <F8>+<Step> <F7>+<Trace>. , (. 3.2):
ax = 0900h (, ah = 09h, al = 0, . . mov ah,9
9 ah, al. al , , 15h,
ax 0915h);
ip = 102h (. . ). , mov ah,9 2 : 102h 100h = 2.

3.

29

. 3.1. 3.1 AFD Pro

. 3.2. mov ah,9

( <F8>/<F1>) dx
ip. dx "Test message$"
, . . 109h, ip 105h ( ). , mov dx,offset String 3 (105h 102h = 3) (. 3.3).
, :
mov dx,offset String

:
mov dx,109

;109 , CodeView
; 'h' . .

I. :

30

. 3.3. mov dx,0109

? , , - (MASM/TASM) offset String


String ( ). , , :
mov dx,109h

.
. ,
(07), 3.1:
...
(07)

int 20h

(08)

int 20h

(09) String db 'Test message$'


(10) CSEG ends
(11) end _start

int 20h (, ,
(07)). .
. CodeView, , . . , ,
. , , 0A09h. ,
dx. , dx 109h, . , .
,
CodeView.
Memory () CodeView ( AFD ) (. 3.2 . 3.4).

3.

31

3.2. CodeView
1
0A09

0000

CD 20 FF 9F 00 9A F0 FE

= .

:
1 (0A09) , (
);
2 (0000) ( (:));
3 (CD 20 FF ... F0 FE) ,
, 0A09:0000;
4 (= .) ASCII ( ), .

. 3.4. , ,
3.1 CodeView

2 () ,
dx (5). 4 Test
message$, 3 Test message$
... dx (. 3.5)! ,
() !
, dx CSEG ( (01) (09) 3.1). : int 21h. DOS 9 (mov ah,9) dx (mov dx,offset String).
, ah . ( -

I. :

32

), ,
.

. 3.5. Test message$

3.3.
09h 21h ,
dx. . 3.3.
.
,
, .
3.1.
3.3. 09h 21h

ah = 09h

dx = ASCII- , $

3.3.1. ASCII?
, , ASCII-, ASCII. ASCII- 0 255 DOS, , , . (
ASCII- . 3).

3.

33

.
- , . , . , .

3.4.
(\003\prog03.asm) ,
( 3.2).
3.2.
(01) CSEG segment
(02) org 100h
(03) _beg:
(04)

mov ax,0B800h

(05)

mov es,ax

(06)

mov di,0

(07)
(08)

mov ah,31

(09)

mov al,1

(10)

mov es:[di],ax

(11)
(12)

mov ah,10h

(13)

int 16h

(14)
(15)

int 20h

(16)
(17) CSEG ends
(18) end _beg

. .
(. 3.6),
.
, . . . (04)
(05) es 0B800h,
( !). (06)
di . 0B800h. (08)
(09) ah (31 -
) al ASCII- (01 "").
(10) 0B800:0000h ( ) ASCII- (31 01 -

I. :

34

). mov (10). [ ] , ,
, ( , , 0B800:0000h).

. 3.6. Prog03.com

.
(04) (05). es, , , ds . .
.

.
. (10) 35 .
, Pentium 100 20 (!) !

3.5.

! I .
, . :
;
;
Intel 8086/8088/80186;
;
:
org ;
mov

();

add

sub

inc

int

3.

35

09h 21h ( );
10h 16h ( ).
, ,
. 75% ,
, , , . , , , . ,
I. - , , ,
. !
,
II " ".
!

II


4.1.
3.1. - :
(01)

...

(02)

mov ah,9

(03)

mov dx,offset My_string

(04)

int 21h

(05)

...

(06) My_string db '!$'


(07)

...

(03) dx .
: mov dx,offset My_string. , mov
. :
mov cx,125

(03) offset.
? : mov dx,My_string?

4.1.2.
"offset" .
(MASM/TASM) (03), offset My_string () . mov dx,My_string ( mov dx,word ptr My_string,
), dx (),
( ""). , dx 16- , . , ,
. : mov dl,My_string ( mov dl,byte ptr My_string). , dl
"", . . dl 8- .
mov dl,byte ptr My_string mov dx,word ptr
My_string. Byte , word ( ).

40

II.

. , 8-
(dl), byte. 16- (dx) word.
-, .
, . .
"!$" ds () dx ().
ds? ,
COM- ( ), , ,
( ds). ds
( ). COM ,
, . COM-
64 (65 536 ). , "" ,
, 64 .
. Norton Commander (
III).
36 . ,
Norton Commander ( Norton Commander
).
Volcov Commander .
Norton Commander, 64 000 (
Norton). Volcov Commander "" ,
. Volcov , Norton.
.
21h ds . , :
...
mov dx,offset My_string
mov ax,10h
mov ds,ax
mov ah,9
int 21h
...
My_string db 'Hello!$'
...

, "Hello!", - "", dx () , - ds (. 4.1).


, 09h 21h , ds:dx. . 4.1 ,
ds 10. ,
Memory1 , 0A09:010Ch,

4.

41

Hello!, .
, . 21h ds 10. ,
, ds:dx
0010:010Ch, .

. 4.1.

,
, , ( ),
ds:
...
mov ax,cs
mov ds,ax
...

. 4.1 .
4.1. 09h 21h

AH = 09h

DS:DX = ASCII- , $

, .

II.

42

4.2.
? ,
. , , 09h 21h
( 4.1).
4.1.
...
mov ah,9
mov dx,offset Str
int 21h
mov ah,9
mov dx,offset Str
int 21h
mov ah,9
mov dx,offset Str
int 21h
...

3 Str.
, . ...
loop (. 4.2).
4.2. loop

loop

loop

8086

cx (). 4.2 ,
( 4.1).
4.2.
...
(01)

mov cx,3

(02) Label_1:
(03)
mov ah,9
(04)
mov dx,offset Str
(05)
int 21h
(06)
loop Label_1
...

4.

43

(01) cx ,
3 0. (02) ( . Label
). ( (03)(05)) .
(06) loop cx ,
, Label_1 (02).
. (07),
cx .
4.1. (02)(06)
.

4.2.1.
, , ,
, . . (03)
(05), loop. , . .
09 21h . 4.3 4.2.
4.3.
...
(01)

mov ah,9

(02)

mov dx,offset Str

(03)

mov cx,3

(04) Label_1:
(05)

int 21h

(06)

loop Label_1

...

, . , ,
.
, .
. 4.2 , 4.3.
, , Label_1, . 4.1,
, , loop, int 21h. , . , .
,
. , 10h 16h, ax , , 4.3.

II.

44

. 4.2.

4.3.
, . loop,
, cx . cx , , . . .
,
, - .
.
. 4.3 , .
4.3. jmp

jmp

Jump (
)

8086

jmp
( 4.4).
4.4.
...
(01)

mov ah,9

(02)

mov dx,offset Str

4.
(03)

int 21h

(04)

jmp Label_2

45

(05)
(06)

add cx,12

(07)

dec cx

(08) Label_2:
(09)

int 20h

...

(05)(07) . , jmp
(08), .

4.3.1.
dec , , loop. 4.5
, 4.2, - (
).
4.5.
...
(01)

mov cx,3

(02) Label_1:
(03)

mov ah,9

(04)

mov dx,offset Str

(05)

int 21h

(06)

dec cx

(07)

jnz Label_1

...

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

4.4.
3,
"" ( 4.6, \004\prog04.asm).

II.

46
4.6.
(01)
(02)
(03)
(04)
(05)
(06)
(07)
(08)
(09)
(10)
(11)
(12)
(13)
(14)
(15)
(16)
(17)
(18)
(19)
(20)

CSEG segment
org 100h
Begin:
mov ax,0B800h
mov es,ax
mov di,0
mov al,1
mov ah,31
mov cx,2000
Next_face:
mov es:[di],ax
add di,2
loop Next_face
mov ah,10h
int 16h
int 20h
CSEG ends
end Begin

, ,
. , .

4.4.1.
(01) (10) (15) (20) . . (11) , "" , (14) "". ,
(10)(14), . 2000 , cx 2000 ( (08)).
(12) 0B800:DI ,
ax ( + ). , .
di 2, .
2? , 2 :
. al,
ah, (12), di () 2. di .
cx 1 . , , (14).
.
, ,
. , . . , .

5.1.
, , TASM, . TASM :
Near jump or call to different CS

2
assume cs:CSEG, TASM .
?
, assume , cs CSEG. .
MASM . assume , MASM
.
TASM. , :
loop Label_1
jmp Label_2
call Procedure

"", , .
, COM-,
( CSEG). ,
, DSEG, (link.exe), COM-
( COM-!), . ,
:
assume cs:CSEG, ds:CSEG, es:CSEG, ss:CSEG

"" , cs, ds, es, ss


CSEG. , , , ,
. .

II.

48

5.2.
.
I.
.
, , " ...", ,
: " !", ,
, .
? 09h 21h
10h 16h ( 5.1).
5.1.
...
(01)

mov ah,9

(02)

mov dx,offset Mess1

(03)

int 21h

(04)

mov ah,10h

(05)

int 16h

(06)

mov ah,9

(07)

mov dx,offset Mess2

(08)

int 21h

(09)

mov ah,10h

(10)

int 16h

(11)

int 20h

...
(12) Mess1 db ' ...$'
(13) Mess2 db ' !$'
...

, , .
, , . , .

(01)(03) (06)(08) . , dx . 16h


(04), (05) (09), (10) . ,
.

5.

49

, , ,
call (. 5.1) ( 5.2).
5.1. call

call

Call

8086

5.2. call
...
(01)
(02)
(03)

mov dx,offset Mess1


call Out_string
call Wait_key

(04)
(05)
(06)

mov dx,offset Mess2


call Out_string
call Wait_key

(07)
...

int 20h

(08) Out_string proc


(09)
mov ah,9
(10)
int 21h
(11)
ret
(12) Out_string endp

(13) Wait_key proc


(14)
mov ah,10h
(15)
int 16h
(16)
ret
(17) Wait_key endp
...
(18) Mess1 db ' ...$'
(19) Mess2 db ' !$'
...

, . ( ) . .

II.

50

, ? , .
.
(01) dx Mess1. (02) , Out_string.
?
() ( (03)) Out_string
( (08)). dx , . .
Mess1 (. 5.1).
(09), (10) 09h 21h
. (11)
, (03) (ret . return ).
, (. 5.2)!

. 5.1.

. 5.2. 0114h

5.

51

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

, (stack).
. 6 , ,
ss:sp, .
, (
(03)) . ,
:
Out_string proc
...
Out_string endp

:
;
proc (procedure) ;
endp (end procedure) .
, . . ,
, ""!
.
Out_string

5.3.
4, (\005\prog05.asm).
5.3.
5.3.
(01) CSEG segment
(02) assume CS:CSEG, DS:CSEG, ES:CSEG, SS:CSEG
(03) org 100h
(04) Start:
(05)
mov ax,0B800h
(06)
mov es,ax
(07)
mov al,1
(08)
mov ah,31
(09)
mov cx,254
(10) Next_screen:
(11)

mov di,0

II.

52
(12)

call Out_chars

(13)

inc al

(14)

loop Next_screen

(15)

mov ah,10h

(16)

int 16h

(17)

int 20h

(18) Out_chars proc


(19)

mov dx,cx

(20)

mov cx,2000

(21) Next_face:
(22)

mov es:[di],ax

(23)

add di,2

(24)

loop Next_face

(25)

mov cx,dx

(26)

ret

(27) Out_chars endp


(28) CSEG ends
(29) end Start

(01)(08), (15)(17) (28), (29) .


.
(09) cx 254, , . (10) (14) "" ""
. di , ( (11)).
(12) , ,
al ( "" 01). ! 01. di 2001, .
, al.
al 02 "", ( (13)).
1 02 (
(14)). . 254 .
. (19) cx ( dx), . .
. (21) (24) "" "" ,
2000 ( -

5.

53

80 25). (20) cx. cx ( (25)) (26).


, : .
254 , 2000 . : 2000 254 = 508 000. , , , . . ,
.
. AFD.

5.4. AFD
AFD, ,
:
32- ;
808680186 ,
8087;
PE NE (Windows).
:
;
, , .;

.
DOS , . AFD http://www.Kalashnikoff.ru, 64 .
, , , !


6.1.
(, stack)
() .
, . ,
"" :
0000
0001
0002
...
FFFE
FFFF

.
, , ,
jmp, call . . .
0FFFFh, () 0000h. - call, call . ,
, .
ss:sp. , , , - COM- sp 0FFFEh,
ss, , CSEG (, , cs, ds, es).
. . 6.1 .
6.1.
CSEG segment
assume cs:CSEG, ds:CSEG, es:CSEG, ss:CSEG
org 100h
begin:
call Our_proc

6.

55

int 20h
Our_proc proc
ret
Our_proc endp
CSEG ends
end Begin

ss:sp. sp=0FFFEh, . .
(. 6.1).

. 6.1.

. CodeView <F8>,
AFD <F1>. sp ! 2.
int 20h. , call Our_proc,
. 103 (. 6.2).
<F8>/<F1>. sp . 2,
0FFFEh. ret "" 0103h .
call int 20h. , . 0FFFEh
0FFFEh (. 6.3).
. ,
.

II.

56

. 6.2.

. 6.3. .

, ,
(. 6.1 6.2).
6.1. push

push

Push

8086

6.2. pop

pop

Pop

8086

6.

57

, . ,
, . ( 6.2).
6.2.
...
(01)

mov ax,345h

(02)

push ax

(03)

mov ah,10h

(04)

int 16h

(05)

pop ax

...

ax 345h (01), (02),


(03), (04). 10h 16h ax , . . ax , .
, (05), 345h ax. ax
345h, , , . . , : ax,
bx, cx:
...
push ax
push bx
push cx
...

, :
...
pop cx
pop bx
pop ax
...

,
, . :
...
mov ax,1234h
mov bx,5678h
push ax
push bx
pop ax
pop bx
...

II.

58

. 6.4.

ax 5678h, bx 1234h (. 6.4).


( 6.3).
6.3.
...
call Our_proc
int 20h
...
Our_proc proc
mov ax,15
push ax
mov ah,9
mov dx,offset Str
int 21h
ret
Our_proc endp
...

, "" ax Our_proc. , ret,


, 15 ,
15. 15 .
, , "" (. . 6.5 6.6).

6.

59

. 6.5.

. 6.6.

( ) ss:sp ( : ). , ,
, ss sp
, .
cli sti (. 6.3 6.4).
6.3. cli

cli

Clear interrupt

8086

II.

60

6.4. sti

sti

Restore interrupt

8086

, ""
! . cli sti.
.
? , . . . -
, .

. , 18,2 . - ! , , , .
, , , ? , . , , ,
,
(, , /
/). , , , , " " , - .
. , , :
...
(01)

mov ax,100h

(02)

mov ss,ax

(03)

mov sp,200h

...

, , (02). ss 100h, sp
200h. , ,
, , , , sp=0FFFEh. ,
ss=100h, sp=0FFFEh. .
. ss=100h, sp=200h! , . , 0100h:0FFFEh (
). ? , , "".
:
ss:sp, cli, , ,

6.

61

(Pentium) , . . .
, ,
"";
ss:sp .
, ;
, . ,
COM- , ss ,
, sp = 0FFFEh. 100h (org 100h).
. , ,
2000h , sp 2200h. 100h
( ) (. .
100h (org 100h), 2000h 100h). , , . (, 100h
), . !
6.4 .
sti.

6.4.
...
cli
mov ax,0B900h
mov ss,ax
mov sp,100h
sti
...

, , : " ss:sp?"
,
, ,
( , ),
, .

6.2.
6.2.1. nop
, (. 6.5).
6.5. nop

Nop

No operand

8086

II.

62

,
, 1 . , "" , . , , , , ,
. ""
, .
Hacker's View, : http://www.Kalashnikoff.ru.
: 90h.
,
(Volcov Commander, Hacker's View), ,
, :
90h
90h
0CDh
20h

6.2.2.
( 6.5). (\006\prog06.asm).
6.5.
(01) CSEG segment
(02) assume cs:CSEG, es:CSEG, ds:CSEG, ss:CSEG
(03) org 100h
(04) Begin:
(05)

mov sp,offset Lab_1

(06)

mov ax,9090h

(07)

push ax

(08)

int 20h

(09) Lab_1:
(10)

mov ah,9

(11)

mov dx,offset Mess

(12)

int 21h

(13)

int 20h

(14) Mess db ' - ! $'


(15) CSEG ends
(16) end Begin

6.

63

, " ". , - sp, . (09)(12)


. ! .
, CodeView, TurboDebuger, AFD - "":
, " ", int 20h (. 6.7). DOS, , . . ,
(. 6.8)! " "
. !
? :
(. . , ).
" " .
?
?
?
. . , . ! ,
! !

. 6.7.

. 6.8.


7.1. 6
. , 7.1
.
7.1. 6
...
(01)

mov sp,offset Lab_1

(02)

mov ax,9090h

(03)

push ax

(04)

int 20h

(05) Lab_1:
(06)

mov ah,9

(07)

mov dx,offset Mess

(08)

int 21h

(09)

int 20h

...

- ?
6, nop 90h.
(02). ax 90h (
nop). sp Lab_1 (01).
, , , Lab_1. ,
! MASM/TASM, ,
(05), () ( 109h).
(01) , sp,
, . , 109h
mov ah,09, . . Lab_1 .
! (03) "" 90h, . . nop. ? , , "" .

7.

65

sp , , . 7.1. int 20h 2 .


Hacker's View. int 20h 0CDh, 20h.
, "" COM- .
, (,
Volcov Commander), CD 20.
COM (, prog.com). 2 . COM-.

. 7.1. AFD Pro

, int 20h 2 . push ax (03)


90h, nop.
sp int 20h, nop. ! int 20h ( )
nop, ! . . 7.1 .
, " ".
.
, CodeView, AFD, Turbo Debugger . :
. , ,
, (
ss:sp), . - . , ,
. , ,
! ,

II.

66

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

7.2.
10h 16h,
. , .
ax.
? cmp (. 7.1
7.2).
7.1. cmp

cmp ,

Compare

8086

7.2. cmp
...
(01)

mov ah,10h

(02)

int 16h

(03)

cmp al,'Y'

(04)

jz Yes_key

...
(05) Yes_key:
...

(02) , - . 10h ax
, . (03) ,
<Y>. :
cmp al,'Y'

ASCII- . .
MASM/TASM . , ,
cmp al,'Y'

cmp al,59h

7.

67

<Y>! , cmp
.
, , ,
, ( 7.3).
al,59h.

7.3.
...
mov al,'2'
mov dh,'d'
...

al 32h, dh 64h. !
(04) Yes_key (05), <Y>. jz ( . jump if zero , ) , .
. , ,
.
, ( 7.4 7.5).
7.4.
...
mov ax,15
cmp ax,15
jz Our_lab
mov ah,3
Our_lab:
...

7.4 , Our_lab. mov ah,3 .


7.5.
...
mov ax,15
cmp ax,16
jz Our_lab
mov ah,3
Our_lab:
...

II.

68

7.5 Our_lab, . .
cmp ax,16 . mov ah,3 ,
, , .
, , - . <> <>, . , . ,
! 7.6 .
7.6. <> <>
...
Next_key:
mov ah,10h
int 16h
cmp al,''
jz F_pressed
cmp al,''
jz F_pressed
jmp Next_key
F_pressed:
mov ah,9
mov dx,offset Mess
int 21h
int 20h
Mess db ' <> <>!!!$'
...

, jz je ( . jump if equal ,
) .
7.6 , 7.7.
7.7. je jz
...
int 16h
cmp al,''
je F_pressed
...

je - jz. ,
.
je jz !

7.

69

7.3.

jmp ( ) .
. , : goto.
goto 20 20

je jz . , - . , : cmp
al,''. :
if Key = "" then goto 20

, - -. , , .
( ), ,
, . , (, , ,
, .), . ,
. "".
?

7.4. ASCII

ASCII.
ASCII? , ,
10h 16h, ax.
- al:
cmp al,'Y'

, (.../A...Z), (0,..., 9)
, , , <F1><F12>. , , <F1>:
cmp al,'F1'

, 'F1' 2 ,
al 1 .
ASCII. ,
<F1>, al 0, ah .
. 7.2 ASCII-
.

II.

70

7.2. ASCII

ASCII

<F1>, ..., <F10>

3Bh, ..., 44h

<Alt>+<F1>, ..., <Alt>+<F10>

68h, ..., 71h

<Shift>+<F1>, ..., <Shift>+<10>

54h, ..., 5Dh

<Ctrl>+<F1>, ..., <Ctrl>+<F10>

5Eh, ..., 67h

, <F1> 3Bh, <F2> 3Ch, <F3> 3Dh


. .
7.8 , <Shift>+<F4> (
<Shift> , , <F4>).
7.8. ASCII
...
(01) No_ext:
(02)
mov ah,10h
(03)
int 16h
(04)
(05)

cmp al,0
jnz No_ext

(06)
(07)

cmp ah,57h
je Shift_f4

(08)

jmp No_ext

(09) Shift_f4:
...

, <F1>, <Alt>+<F1> . . al
0, ah . (04)(07) . (05) No_ext, ,
(: <A>, <>, <>, <Enter> . .).
"" . (06) ,
<Shift>+<F4>. <Shift>+<F4>, , , Shift_f4 (09) ( Shift_f4, , -). -
, , -
No_ext (08).

7.

71

, , <Shift>+<F4>.
. 7.3 , , . . 10h 16h al.
7.3.

<Enter>

0Dh (13)

<ESC>

1Bh (27)

<> (<Spacebar>)

20h (32)

<Tab>

09h (9)

. ASCII
3.

7.5.
(\007\prog07.asm), 8. ( 7.9).
7.9.
CSEG segment
assume cs:CSEG, ds:CSEG, es:CSEG, ss:CSEG
org 100h
Begin:
call Wait_key
cmp al,27
je Quit_prog
cmp al,0
je Begin
call Out_char
jmp Begin
Quit_prog:
mov al,32

II.

72

call Out_char
int 20h
; === ===
; --- Wait_key --Wait_key proc
mov ah,10h
int 16h
ret
Wait_key endp
; --- Out_char --Out_char proc
push cx
push ax
push es
push ax
mov ax,0B800h
mov es,ax
mov di,0
mov cx,2000
pop ax
mov ah,31
Next_sym:
mov es:[di],ax
inc di
inc di
loop Next_sym
pop es
pop ax
pop cx
ret
Out_char endp
CSEG ends
end Begin

, ! - ,
. (

7.

73

-) -
http://www.Kalashnikoff.ru. ,
http://RFpro.ru.

, ,
.
? ,
? , !
, ! ,
? .
:
, , ( 50
200 320 ++);
;
, .
:
;
() , ;
- .
, (, , .), . ,
, , , .
: . Windows.
, Windows. Win32 . DOS , Windows .
: , , , ,
, , , , ?
, .

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


8.1.
, 7 . ,
, . - , . :
20h 32, <>;
100h 256, ;
1Bh 27, <Esc>;
21h 33, MS-DOS
. .
( 8.1).
8.1. 7
...
(01)

call Wait_key

; ...

(02)

cmp al,27

; <Esc>?

; Quit_prog (quit , prog (program) )


(03)

je Quit_prog

(04)

cmp al,0

; ? (<F1>-<F12> . .)

(05)

je Begin

; ...

;
(06)

call Out_char

(07)

jmp Begin

; ...

;, <Esc>
(08) Quit_prog:
(09)

mov al,32

; al <>

; al ( ).
; "" Out_char,
; . <>

8.
; .
(10)

call Out_char

(11)

int 20h

(12)

...

; DOS...

(13) ; --- Out_char ---

; ()

(14) Out_char proc

; , ...
(15)

push cx

(16)

push ax

(17)

push es

(18)

push ax

; ax, . . ...

(19)

mov ax,0B800h

; es

(20)

mov es,ax

(21)

mov di,0

;di

; 2000 (80 * 25 )
(22)

mov cx,2000

(23)

pop ax

; (. 18)...

(24)

mov ah,31

; , 2000 (
; 22)
(25) Next_sym:
; ( 31)
(26)

mov es:[di],ax

; 2 ( , )
(27)

inc di

(28)

inc di

(29)

loop Next_sym

;
(30)

pop es

(31)

pop ax

(32)

pop cx

(33)

ret

(34) Out_char endp


...

75

II.

76

(12) . , :
;
ASCII (<F1><F12>, ), ;
ASCII (<A><Z>, <0><9> . .) ;
<Esc> (27 1Bh),
(mov al,32) .

8.2.
MS-DOS
.
, .
3Dh 21h (. 8.1).
8.1. 3Dh 21h

ah = 3Dh

ax =

al = (00 , 01
, 02 , )

jc

ds:dx = ASCII-

, al , . . ,
:
;
;
.
, (al=02)
, - . / - , . ,
" " ("read-only")
(al=2) / (al=02), .
8.2 command.com /.
8.2. /
...
mov ax,3D02h
mov dx,offset File_name

8.

77

int 21h
...
File_name db 'command.com',0
...

, ax : 3Dh 02h.
, :
...
mov ah,3Dh
mov al,02h
...

File_name db 'command.com',0 ,
. , :
...
mov ax,3D02h
mov dx,offset File_name
File_name db 'command.com',0
int 21h
...

, mov dx,offset File_name


. , , .
'command.com' , . , , (. 8.1). mov dx,0106h (mov
dx,offset File_name) File_name
"command.com". dx ,
aprl, insw . ., , ,
"" .
, " " .
, .
, , .
.
, :
File_name db 'command.com'

File_name db 'C:\ASSM\command.com',0

, .
, - .
. :
My_file db 'a:myfile.doc',0

II.

78

. 8.1.

myfile.doc,
A: .
, . :
...
mov ax,3D00h
mov dx,offset Just_file
int 21h
...
Just_file db 'file',0
...

, file (. ) . 3Dh ( ).
- , (
).
jc ( .
jump if carry , ) jnc ( . jump if not
carry , ):
...
int 21h
jc Error
Ok:
...
Error:
...

8.

79

:
...
int 21h
jnc Ok
Error:
...
Ok:
...

, Ok () Error () . je jne, , jc jnc


.
21h ,
, , .
:
. ;
- . ();
.
FILES=XX
config.sys, XX 99. MS-DOS
;
" " / .
, /.
8.3 ,
, .
8.3.
...
mov ax,3D00h
mov dx,offset File_name
int 21h
jc Bad_file
mov dx,offset Mess1
Quit_prog:
mov ah,9
int 21h
int 20h
Bad_file:
mov dx,offset Mess2

II.

80
jmp Quit_prog
...
File_name db 'c:\assm\masm\binr\ml.exe',0
Mess1 db ' !$'
Mess2 db ' !$'
...

. 8.2.

ax . , , , . .
3Dh , ax!
. 8.2.
(
-), 3Eh 21h (. 8.2).
8.2. 3Eh 21h

ah = 3Eh

bx =

, ,
. , . ,
.

8.

81

! , , , ,
(. . ,
-, ). ,
, Handle:
...
mov ah,3Eh
mov bx,Handle
int 21h
;
...

mov bx,Handle. Handle ,


.
, ,
Handle. :
Handle dw 0

. . 8.4 ,
, ,
.
8.4.
...
mov ax,3D00h
mov dx,offset File_name
int 21h
jc Error
mov Handle,ax
; ...
mov ah,3Eh
mov bx, Handle
int 21h
;
Error:
int 20h
...
Handle dw 0
...

3Fh,
40h. bx Handle,

II.

82

, ds:dx
/. 40h . 8.3.
cx

8.3.
,
. , 1:
() .
, 8.5 ( 65 000 (0FDE8h) )
, , (\008\prog08.asm).
8.5.
CSEG segment
assume cs:CSEG, ds:CSEG, es:CSEG, ss:CSEG
org 100h
;
Begin: mov ax,3D00h
mov dx,offset File_name
int 21h
jc Error_file
mov
mov
mov
mov
mov
int

Handle,ax
bx,ax
ah,3Fh
cx,0FDE8h
dx,offset Buffer
21h

mov ah,3Eh
mov bx,Handle
int 21h
mov dx,offset Mess_ok
Out_prog:
mov ah,9
int 21h
int 20h
Error_file:
mov dx,offset Mess_error

8.

83

jmp Out_prog
;=== ===
Handle dw 0
Mess_ok db ' ! !$'
Mess_error db ' '
; :
File_name db 'c:\msdos.sys',0,'!$'
Buffer equ $
CSEG ends
end Begin

.
, , , .
() , ds:dx.


9.1.
9.1 8 .
9.1. 8
...
; CSEG .
(01) Begin: mov ax,3D00h

; , ( ).
(02)

mov dx,offset File_name

(03)

int 21h

(04)

jc Error_file

;ds:dx

; ( , ,
; ), Error_file
; Handle.
; , bx ,
; , ax.
; ( , ax) ,
; (). ax, .
; mov bx,Handle .
(05)

mov Handle,ax

(06)

mov bx,ax

; Handle

(07)

mov ah,3Fh

; 3Fh

(08)

mov cx,0FDE8h

; 0FDE8h = 65000

;ds:dx
(09)

mov dx,offset Buffer

(10)

int 21h

; . ...

(11)

mov ah,3Eh

9.

85

; bx. . . bx ,
; (Handle)
(12)

mov bx,Handle

(13)

int 21h

; dx , .
(14)

mov dx,offset Mess_ok

(15)Out_prog: mov ah,9

; 09h

(16)

int 21h

(17)

int 20h

; dx , ...
(18)Error_file: mov dx,offset Mess_error
;... Out_prog ( , ?)
(19)

jmp Out_prog

;=== ===
(20) Handle dw 0
(21) Mess_ok

; 2

db ' ! !$'

; (22)(23)
(22) Mess_error db ' () '
(23) File_name

db 'c:\msdos.sys',0,'!$'

(24) Buffer equ $


...

$, (24).
, ( 9.2).
9.2. $
(01) CSEG segment
(02) assume cs:CSEG
(03) org 100h
(04) Begin:
(05)

My_lab equ $

(06)

My_lab2 equ $+2

(07)

mov bx,offset My_lab

II.

86
(08)

mov dx,offset My_lab2

(09)

int 20h

(10) CSEG ends


(11) end Begin

(5) (6) ( ). , My_lab 100h (org 100h), My_lab2 102h. . 9.1 ,


$.

. 9.1. $

8 Buffer . , mov dx,offset Buffer dx


CSEG. . .
(22) , . $, . ,
09h 21h , . (23), ,
$. ,
(22) , (23).
(22) Mess_error db ' () '
(23) File_name db 'c:\msdos.sys',0,'!$'

, 09h
(. 9.2):
() c:\msdos.sys !

9.

87

. 9.2.

'0' c:\msdos.sys .
'0' (23)? ds:dx
.
'0'. , , , . c:\msdos.sys!$ !
, . :
Mess_error db ' () c:\msdos.sys!$'
File_name db 'c:\msdos.sys',0

,
.

9.2.
. 9.3 (\009\Prog09.asm).
9.3. ,
CSEG segment
assume cs:CSEG, ds:CSEG, es:CSEG, ss:CSEG
org 100h
; -------------- ------------Begin:
mov dx,offset File_name
call Open_file
jc Error_file

II.

88
; -------------- ----------mov bx,ax
mov ah,3Fh
mov cx,offset Finish-100h
mov dx,offset Begin
int 21h
; ------------- ---------------call Close_file
; ------------ -------------mov ah,9
mov dx,offset Mess_ok
int 21h
ret
; ---------- ----------------Error_file:
mov ah,2
mov dl,7
int 21h
ret
;
; --- --Open_file proc
cmp Handle,0FFFFh
jne Quit_open
mov ax,3D00h
int 21h
mov Handle,ax
ret
Quit_open:
stc
ret
Handle dw 0FFFFh
Open_file endp
; --- --Close_file proc
mov ah,3Eh

9.

89

mov bx,Handle
int 21h
ret
Close_file endp
;
File_name db 'Prog09.com',0
Mess_ok db ' !', 0Ah, 0Dh, '$'
Finish equ $
CSEG ends
end Begin

!
Prog09.asm!

.
. ,
.
10.

III
,
,

10

.

10.1.
9 (
) .
Prog09.asm. , , . . , , .
( 10.1).
10.1. Prog09.asm 9
; ,
;
CSEG segment
assume CS:CSEG, DS:CSEG, ES:CSEG, SS:CSEG
org 100h
Begin:
; (. ).
mov dx,offset File_name
call Open_file
; Prog09.com
jc Error_file
; Error_file
mov bx,ax
;
;
mov ah,3Fh
; ( ) cx...
mov cx,offset Finish-100h
mov dx,offset Begin
; ,
int 21h
; Begin.
call Close_file

III. , ,

94

;
mov ah,9
mov dx,offset Mess_ok
int 21h
ret
; (File_name db 'Prog09.com',0),
;
Error_file:
mov ah,2
mov dl,7
int 21h
ret
;
;
Open_file proc
cmp Handle,0FFFFh

;,

jne Quit_open

mov ax,3D00h
int 21h
mov Handle,ax
ret
Quit_open:
stc

; 1,

ret

; ( jc)

Handle dw 0FFFFh
Open_file endp
;
Close_file proc
mov ah,3Eh
mov bx,Handle
int 21h
ret
Close_file endp
File_name db 'prog09.com',0
;0Ah,0Dh

10. .

95

Mess_ok db ' !',0Ah,0Dh,'$'


Finish equ $

; ()

CSEG ends
end Begin

. 10.1 CodeView , . ds:dx, 3Fh,


.

. 10.1.

ret
:
...
mov ah,9
mov dx,offset Mess_ok
int 21h
ret
; ret ?
...

. , ,
cs:0000h int 20h,
(. 10.2 10.3).
ret ,
. . . , ret , . . ss:sp, .

96

III. , ,

. 10.2. ret

. 10.3. int 20h DOS

, , , COM- , . . sp=0FFFEh. " call" sp 2, . .


0FFFCh. , . : DOS . , DOS
ret COM- , sp=0FFFEh, 2 0000h (. . int 20h)
, .

10. .

97

10.2.
, , Pascal, , Visual
Basic . , , .
. . , "" .
. . " ", ,
( , -).
,
.
?
, , - ,
, -
.
: X Y. ,
Y ? " ", - ?
X, . !
, Y, ( ;
, . .).
,
. , , .
? Yandex., , . .
.

, .
, , Visual Basic for Applications (VBA).

. ,
, . "" , .
, (DrWeb, NOD32, Norton Antivirus, .). ,
. , , ,
, . (!) , .

III. , ,

98

10.2.1.
?
, -
. , , . , ,
. .

?
, , /, , . 500600 . ,
100150 , , 1,53 .

?
, . , 0,5
1 FDISK, . .
, (FAT File Allocation
Table), ! .

?
, COM- ( ).

?
, .

?
, COM-, ( 10.2).
10.2.
CSEG segment
assume cs:CSEG, ds:CSEG, es:CSEG, ss:CSEG
org 100h
Start:
...

; .

CSEG ends
end Start

10. .

99

COM-, .
EXE-, .

.

10.3.
, . . , .
!
,
, API-. , , FAR Manager.

, DOS Navigator.

() ,
. , Norton Guide, , , . , ( DOS ).
, , , .
(
).

10.3.1.
(), (, print_string), . 256 . BIOS () . , 16h:
...
mov ah,10h
int 16h
...

(MS-DOS):
...
mov ah,9
mov dx,offset String
int 21h
...

, , ,
, . , 09h 21h:
21h
...
mov ah,9

100

III. , ,

mov dx,offset Our_string


int 21h
...
Our_string db '!$'
...

"!".
21h, -
, ds:dx
. 09h 21h . ( 10.3).
10.3. 21h
...
cmp ah,9
je Out_str
Go_21h:
...
; () 21h.
...
Out_str:
push cs
pop ds
mov dx,offset My_string
jmp Go_21h
...
My_string db " $"
...

,
09h 21h - . ,
. ds:dx - 21h. , , .
, ( ) . ,
,
(. . , ). , . .

10. .

101

( , ) MS-DOS 20h2Fh IO.SYS/MSDOS.SYS. ,


, , , "". DOS ( 20h)
, "".
.

int ( ), ,
, (mov ah,0/int 16h),
(mov ah,9/int 21h).
( ) - .
, ss, sp
, , . :
- 09h. ( ) 1Ch, 18,2 .

. (, ) . ,
"Divide overflow" ( ) .

( , " ") cli
. , ,
.
sti.
"" sti cli, , . . ( 09h )
, "" .
.
Windows ,
WinAPI. WinAPI . ,
.
Windows.

10.4.
, 10.4 (\010\prog10.asm) ( ).

III. , ,

102
10.4.
CSEG segment

assume cs:CSEG, ds:CSEG, es:CSEG, ss:CSEG


org 100h
Start:
; . 21h,
;
jmp Init
; , , 21h ( ).
; , Int_21h_proc
; 09h 21h.
; .
Int_21h_proc proc
cmp ah,9

;: 09h?

je Ok_09
; , 21h.
;. Ok_09
jmp dword ptr cs:[Int_21h_vect]
Ok_09:
push ds

push dx
push cs

; ds:dx

pop ds
; (My_string) ,
;, 21h
mov dx,offset My_string
pushf

; ...

call dword ptr cs:[Int_21h_vect]


pop dx

pop ds
iret

; ( )

;, , ,
; . !
; 21h

10. .

103

Int_21h_vect dd ?
My_string db ' !$'
int_21h_proc endp
; (
;). ( 27h)
Init:
; (Int_21h_proc) ( )
; 21h. 25h 21h.
; .
; 35h 21h:
;ah
mov ah,35h
;al , ( )
mov al,21h
int 21h
; es:bx () 21h (es , bx )
;
mov word ptr Int_21h_vect,bx
mov word ptr Int_21h_vect+2,es
;, . :
mov ax,2521h
mov dx,offset Int_21h_proc
;ds:dx
;(. . Int_21h_proc)
int 21h
;! , - 21h,
; (Int_21h_proc). ? ,
; ( .
; .).
mov dx,offset Init
int 27h
; 27h DOS ( 20h),
;. dx ,
;( Init). 0000h ,
; Init.
CSEG ends
end Start

III. , ,

104

10.4.1.
,
(. 10.110.3).
10.1. 35h 21h: ()

ah = 35h

es =
bx =

10.2. 25h 21h:

ah =25h

ds =
dx =

10.3. 27h:

ds:dx = ,

( DOS)

10.5.
(. 10.4 10.5).
10.4. pushf

pushf

Push flags

8086

10.5. popf

popf

Pop flags

8086

:
...
(01)
(02)

cmp ax,23
je Ok_ax

...

, (01), .
(02) . , ,

10. .

105

(. . ax = 23). , ax 23. , AFD Code View (


, )
(. 10.4 10.5).

. 10.4. AFD: ZF (Zero Flag)

. 10.5. Code View: ZR (ZeRo)

Int_21h_proc 10.4. :
...
cmp ah,9
je Ok_09
...

III. , ,

106

.
. ,
( )
cs:ip, . ,
iret
.
, ,
. - , 21h. , , ds dx. ,
( Int_21h_proc) , cs:ip .
:
; 21h
Int_21h_vect dd ?

(Define Double word ). , 16- 2 ( ) (dx, ax, es, ss . ., ah, dl, bh, ...
8- , 1 ). Int_21h_vect (2 ), :
mov word ptr Int_21h_vect,ax

1 , :
mov byte ptr Int_21h_vect,ah

, "word" - "", byte "".

10.5.1. ?
,
"" 21h. , AFD, TD, SoftIce ., CodeView.
AFD, http://www.Kalashnikoff.ru.
,
09h 21h. , , 10.5 (\010\test10.asm).
10.5.
CSEG segment
assume CS:CSEG, DS:CSEG, ES:CSEG, SS:CSEG
org 100h
Begin:
mov ah,9
mov dx,offset String

10. .

107

int 21h
int 20h
String db 'My string.$'
CSEG ends
end Begin

10.4.
, 10.5. , . 10.5 .
"" 21h . . 10.6 test10.com, int 21h.

. 10.6. test10.com int 21h

( ) . 21h-
Int_21h_proc prog10.com, ds:dx. . 10.7 , .
. 10.6 10.7 , int_21h_proc :
;
ds:dx, " !";
21h, ;
;

108

III. , ,

. 10.7.

, iret test10.com, int 21h.


21h . , ,
, .

* * *
11 Norton Commander.

11


, - , ,
, . , , . :
print ""

, , . , , . , ,
, , , . , ,
, ? , , , .
, ,
, . . .

11.1.
: Norton Commander (Windows Commander, FAR Manager . .) XMS-.
, ,
. , ,
, , 808680486 , ,
, XMS-, .
(, ), , , Norton Commander.
, .
. ?
, 300 .
, ,
"" FAR Manager, . ,
, .

110

III. , ,

,
COM- (. . 64 ).
" ?" . .
Volcov Commander, COM 64 .
, , ,
. .
, ( 11.1).
11.1. ""
CSEG segment
assume cs:CSEG, ds:CSEG, es:CSEG, ss:CSEG
org 100h
Begin_shell:
;
call Check_video
; -
mov ah,9
mov dx,offset Mess_about
int 21h
;
call Main_proc
; , .
int 20h
;
; ,
include main.asm
; :
include display.asm
; :
include files.asm
; :
include keyboard.asm

11.

111

; , :
include messages.asm
; . ...
CSEG ends
Begin_shell endp

Sshell11.asm ( . ).
, , Sshell Super shell
( ), ,
( 11).
(): include.
- (MASM/TASM): . include , . .
? , ( ), ( , ): main.asm, display.asm, files.asm, keyboard.asm, messages.asm.
?
(Far Manager, Norton Commander . .)
<Shift>+<F4>. ( ). <Enter>, <F2> <Esc>. .
- DOS-, c
http://www.Kalashnikoff.ru/.
, . . , Sshell11.asm. . .
!
main.asm, display.asm, files.asm, keyboard.asm,
messages.asm. !
( MASM 6.11):
ML.EXE Sshell11.asm /AT
( TASM):
TASM.EXE Sshell11.asm
TLINK.EXE Sshell11.obj /t /x
. 1.

Sshell11.com. , . ASM.
, . .

III. , ,

112

11.2.
10h
BIOS () (. 11.1).
11.1. 0Fh 10h:

ah = 0Fh

al =
ah =
bh =

: .
, . , 40 25, 80 25 (
, , Norton Commander), (CGA) ( Digger), .
. 11.2 .
11.2.

/
CGA+

01h

, 16

40

25

03h

, 16

80

25

04h

, 4

320

200

06h

, 2

640

200

VGA+
11h

, 2

640

480

12h

, 16

640

480

13h

, 256

320

200

sVGA
(, 1024 768, 64 ).
, ( ) VBE (
, ). CGA-, EGA-
helpassm.exe, http://www.Kalashnikoff.ru/.

11.

113

, CGA- EGA-.
. :
...
mov ah,0Fh
int 10h
cmp al,3
je Ok_video
...

, 3 (. . 80 25). ,
. , 0h
10h:
...
mov ax,3

int 10h

; 8025

...

, 3.
, ,
( sVGA , ,
8 ).
?
(, . .). , , . ,
"" .
(
). , , , , . , , .
, .
, MS-DOS
.

, . 09h 21h ( ) , . .
05h 10h
(. 11.3).

114

III. , ,

11.3. 05h 10h:


ah = 05h

al =

.
:
, ( ) ,
;
00h 10h
, ;
. , . , , " ", , .
.
.
* * *
. 12 .

12


12.1.
.
- resid12.asm test12.asm.
resid12.com , test12.com.
Resid12.com ,
ASCIZ (ASCII-, 0). Int_10h_proc
10h ( BIOS ()). 10. (88h)
10h, , ,
, , . 88h, 10h, (). :
ah = 88h ;
ds:si = , (ds , si ).

, ds () ,
si (). , COM- cs, ds, es, ss ,
. . ,
, .

12.2.

, , . , . " "
.
- , .
? , "". 10h, ax " " 8899h.
, -

III. , ,

116

. , ah 88h, al 99h. 88h


10h ( ).
99,9%. 10h
, 10h (, , ), . , 10h 8899h ax 8899h ax,
, . . 12.1 10h .

. 12.1. : !

10h. resid12.com , 10h, ,


, 8899h ax. ,
- . ? ah al . ,
, , , ,
9988h. , ,
8899h ax, BIOS , . .
. ax 9988h, , , . Int_10h_proc (
?). ,
ah al ( 12.1).
12.1. 10h resid12.com
...
Int_10h_proc proc

12.

117

pushf

; , . . ...

cmp ax,8899h
jne Next_test

;
; , ...

; ah al , ,
;- .
xchg ah,al
popf
;
iret
; ( )
;ax 9988h!!!
...

xchg (. 12.1 12.2).


12.1. xchg

xchg ,

Exchange

8086

12.2. xchg
...
mov ax,10h
mov bx,15h
xchg ax,bx
...

; ax=15h, bx=10h

, cs ( . code segemt )
, , ip ( .
instruction pointer ) . ,
10h 0010:0400h,
1234h. :
;cs:ip = 1234:0100h
...
[1234:0100h] mov ax,8899h
; cs:ip=1234:0103h
[1234:0103h] int 10h
; cs:ip = / () 10h,
;. . 0010:0400h
[1234:0105h] mov bx,10
; , ...
...

118

III. , ,

iret,
ret.
10h.
.
(resid12.com) .
cs:ip. , .
, (
; AFD <F1>, CodeView <F8>) (. 12.2).

. 12.2.

12.3.
, :
stos, lods, rep. . (, , .).
lods ax/al , ,
ds:si, si .
ax/al? , : lodsb lodsw. Lodsb (b byte, ) al, lodsw (w word,
) ax ( 12.3, . 12.3 12.4).
12.3. lodsb lodsw
...
mov si,offset String ;si String, . . '1'
lodsb

12.

119

; al '1' (31h); si = si + 1, . . si '2'


lodsw
; ax '32' (3332h); si = si + 2, si '45'
...
String db '12345'
...

. 12.3. lodsb

. 12.4. lodsw

III. , ,

120

: lods b,
al, si 1. w, () ax, si .
:
1. ds?
2. lodsw ax '32', '23',
?

('32'), , 2 .
3, 2.

: String
, ,
, .
. COM- .
.
, - . ,
, ( )
. 12.4 .
12.4.
...
Handle dw 1234h
; 1234h.
; : 3412h. ...
...
mov ax,Handle

;ax=1234h

mov al,byte ptr Handle

;al=34h

mov al,byte ptr Handle+1

;al=12h

...
Byte ptr, , , 1 : Handle dw 1234h (dw . define word ( )) . 12.512.7.
, ,
10h , ,
( 12.5).

12.

. 12.5. ax

. 12.6. al

. 12.7. al

121

III. , ,

122

12.5.
...
mov ax,3510h

; () 10h.

int 21h

; es , bx ...

;
mov word ptr Int_10h_vect,bx
; , ,
mov word ptr Int_10h_vect+2,es
...
; ( )
Int_10h_vect dd ?
...

, Int_10h_vect.
, dd ( . define double
word ). - (es bx)!
, ,
.
, lodsb al ,
ds:si (:). ,
:
word ptr

...
mov al,ds:[si]
inc si

;( add si,1)

...

, . : lodsw ax ,
ds:si. :
...
mov ax,ds:[si]
add si,2
...

, (lodsb/lodsw)
( ).
(), . , :
Data_array db ' '

, : stosb/stosw. stosb al es:di,


stosw ( 12.6, . 12.8).

12.

123

12.6. stosw
...
mov di,offset Data_array
mov ax,2030h
stosw
...
Data_array dw ?
; 2030h,
;: mov Data_array,2030h
...

. 12.8. stosw

, "", . ( 12.7).
12.7. "" stosw
...
mov ax,0B800h
mov es,ax
mov di,0
mov ah,07h

; ( )

mov al,01h

;( "")

stows

;, : mov es:[di],ax

...

III. , ,

124

, :
:

...

. , ah , al . , (. .
ah () ), ,
. , ax !
rep,
. , .
stosw, ( 12.8).
12.8. loop
...
mov
mov
mov
mov
mov

ax,0B800h
es,ax
di,0
cx,2000
ax,0720h

; ,
;8025=2000
;07 , 20h

Next_sym:
stosw
loop Next_sym
;
...

, :
1. loop rep .
2. , rep.
3. ( Next_sym).
, rep
( 12.9).
12.9. rep
...
mov
mov
mov
mov
mov
rep
...

ax,0B800h
es,ax
di,0
cx,2000
ax,0720h
stows

;cx counter,
;/
; , .

12.

125

, . .
IBM PC/XT. rep stosw 0.
!
rep ( . repeat ) , loop !

:
stosw , ax
es:di;
rep stosw , ax es:di
, ;
rep, .
. , si, di.

12.4. xor sub



, : xor sub (. 12.9):
xor ax,ax

; mov ax,0

(. 12.10):
sub ax,ax

; ax ax

. 12.9. xor

126

III. , ,

. 12.10. sub

(xor ax,ax/sub ax,ax) mov


, - .
xor . .
. , , xor
sub, .
ax,0.

12.5.

resid12.asm test12.asm (
AFD): .

13

, . , , , "" .

13.1.
:
"" , ;
;
.
, , ,
COM-.
, COM ,
100h. , "-",
"" , , jmp
(. . ).
,
( 100h) .
. , 13.1 13.2.

13.1. ( )
; , 100h
[1234:0100h] mov ax,34
[1234:0103h] mov dx,15

; , ...

[1234:0106h] add ax,bx


[1234:0108h] ... . ...
...
[1234:0500h] int 20h

III. , ,

128
[1234:0502h] ---

; , "-"...
...
13.2.
;"" ( )
[1234:0100h] jmp 0502h
[1234:0103h] mov dx,15

; "-"

[1234:0106h] add ax,bx


...
[1234:0500h] int 20h
[1234:0502h] ---

; .

...

; . , ...

;=== , ===
; "-"
[1234:0700h] mov word ptr cs:[0100h], First_bytes_1
; "-"...
[1234:0705h] mov byte ptr cs:[0102h], First_bytes_2
; 100h jmp 502h, mov ax,34
;(. . ). ,
; " "...
; , !
;... 100h, . .
[1234:0709h] jmp 0100h
...

: . ...

13.2.
. virus13.asm.
.286 , (, ) 8086, 80286.
8086 ! Init
( ).

13. :

129

: DOS DTA
"-". : DTA
?
HELPASSM,
http://Kalashnikoff.ru. , .
, COM- 100h (org 100h).
0 100h? PSP (Program Segment Prefix,
),
, .
80h DTA (Disk Transfer Area,
). DTA
(4Eh 4Fh 21h). ,
, (80h)
. :
FORMAT.COM C:/S/U

cs:0080h L_C:/S/U, L , _ . ,
CodeView :
CV.EXE FORMAT C:/S/U

, cs:0080h (. 13.1).

. 13.1. PSP

PSP? ,
, (L_C:/S/U). , "-", "", ,

III. , ,

130

. L_/S/U.
:
PSP . , , ;
DTA , . 1Ah 21h (. 13.1).
13.1. 1Ah 21h: DTA

ah = 1Ah

ds:dx = DTA

, . . DTA .
: " ".
,
. :
mov dx,offset String

dx String .
:
mov dx,125h

dx . ,
() , 0.
- ,
! ,
, !
13.3
, .
13.3.
...
[1234:0100h] mov dx,400h
; , mov dx,offset String.
; offset String ()
; , .
...
[1234:0400h] ''
; , 400h.
; , .
...

13. :

131

, "-" 100h ,
. , :
1234:0400h + 100h = 1234:0500h. ,
. 100 , 23 000 !
, , ( 13.4).
13.4. 100h
...
;1234:0200h , 100h "-",
; "" ...
[1234:0200h] mov dx,0400h
; "-"
...
[1234:0400h] --; "-"...
...
[1234:0500h] ''
;, !
...

, , "-" mov dx,400h mov dx,500h , . , ? , ? :


( !) "" "-" 100h. 13.5 13.6 , (
).
13.5.
...
; "-"...
...
[1234:0200h] mov dx,400h
...
[1234:0500h] ''
...

; ""

13.6.
...
; 5678h, 0100h
[5678:0100h] mov dx,400h
...
[5678:0400h] ''
; ()!
...

132

III. , ,

: , , , ?
(. . , )
- 7- ( !). 80 25 ( 03). , ,
. ,
( ).
. 13.2.
13.2.

0B800h

00

0B900h

01

0BA00h

02

0BB00h

03

0BC00h

04

0BD00h

05

0BE00h

06

0BF00h

07

.
, ?
300400 . 03:
80 , 25. 2 (/). : 80 25 2 = 4000 (, 4096 ). ? , ! ,
, , , .
Init . , . .
. ,
...
: movs.

13.3. movs
movs . ,
.
stos, .
. 13.3.

13. :

133

13.3. movs

movs

Move string


()

8086

ds:si , , es:di , cx / ( 13.7, 13.8


. 13.2, 13.3).
13.7. movs
...
mov cx,10

mov si,offset Str1

mov di,offset Str2

rep movsb

; , . . movsb.

; Str1 = Str2
...
Str1 db '0123456789'
Str2 db '9876543210'
...

. 13.2.

III. , ,

134

13.8. movs
...
mov cx,5

; ( )

mov si,offset Str1

mov di,offset Str2

rep movsw

; ( ), . . movsw.

; Str1 = Str2
...
Str1 db '0123456789'
Str2 db '9876543210'
...

. 13.3. movs

13.4. ,

, :
"-";
7- (0BF00:0100h).
"" 0BF00:ip. , cs:ip ( ). ,
"":

jmp dword ptr cs:[Off_move]

13. :

135

, Off_move, , cs:ip.
, , Lab_jmp, 7- . . 13.4 AFD
virus13.com .

. 13.4. Virus13.com

13.5.
DTA 7- 0. . COM . 4Eh 21h (. 13.4).
13.4. 4Eh 21h: /

ah = 4Eh

cf = 1: ( )

cx = : 0
(, read-only hidden!)

cf = 0: DTA

ds:dx = .
:
*.*
*.exe
comm???.c??
c:\*.asm

136

III. , ,

cf . cf=1, ,
( 1), cf=0, ( 0). DOS, , .
, 4Eh , , ,
( ), .
( ), DTA . . cf=0 ( ), - .
,
( ), 4Fh 21h
(. 13.5).

13.5. 4Fh 21h:


/

ah = 4Fh

cf = 1: , ( )

cx = : 0
(, read-only hidden!)
ds:dx = ( 4Eh)

cf = 0: DTA

, 4Fh 21h 4Eh.


, .
! .
.
.
! - ,
.

14


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

sshell14.asm!
.
, ,
, . : "...
(Delete_file, files.asm)...".
Delete_file , , files.asm ,
.

14.1.
14.1.1. COM?
, Windows (FLAT)
COM-, (TINY).

14.1.2.
?

. :
TINY "" , , , 16- (. .

III. , ,

138

64 ).
COM,
(, ). ;
SMALL "" , , ;
COMPACT "" ,
, . ;
MEDIUM "" , ,
. , ,
, ( , . .)
, ;
LARGE HUGE "" "" , ,
;
FLAT "" , , ( TINY), 32- .
, 4 294 967 296 (
4 ). , , , Windows.
.model. 14.1 COM .
14.1. .model
; - (TINY).
; ASSUME .
.model TINY
csEG segment
; (ORG) .
org 100h
Begin:
mov ah,9
mov dx,offset Message
int 21h
ret
Message db 'Hello, world!$'
; , .
; 0FFFEh , .
CSEG ends
end Begin

14.

139

14.2. SuperShell
14.2.1.
main.asm. (Hide_cursor,
display.asm). , .
03h 10h (. 14.1).
14.1. 03h 10h:

ah = 3

dx = (dh , dl )

bh = ,

, bh ,
. ,
8 . . -
, , bh 0. dx : dh ,
dl . (. 14.1).

. 14.1.

, .
.
25- . - 3 (25 , 80 ).

III. , ,

140

, ( )
24. , 25 (19h), ""!
02h 10h (. 14.2).
14.2. 02h 10h:

ah = 2

bh = ,
dh = , dl =

14.2.2.
80286+
,
. ,
, , ,
. , Norton Commander Far Manager, <Ctrl>+<O>.
, , , , ?
, 8 . , ? (Save_mainscr,
display.asm). : pusha popa (pusha .
push all ; popa . pop all ). pusha
: ax, cx, dx, bx, sp, bp, si di, , , popa : di, si,
bp, sp, bx, dx, cx ax.
. 14.2 , pusha.
286+. , , - 386+, ,
80386, 80486, Pentium . ., 8086
(PC/XT) 80286 (PC/AT). pusha popa
80286 ( ) .
sshell.asm .286. (MASM, TASM),
() 8086, 80286.
" ?"
.

14.

141

. 14.2. pusha

( ),
(MASM, TASM) , 8086.
, pusha popa ,
. , , .
, :
...
push 0B800h
pop es
...

1 , :
...
mov ax,0B800h
mov es,ax
...

, ax, .
push 1234h 80286+,
, 80186+. 80186
, ,
80286.
(Save_mainscr, display.asm) . (Restore_mainscr, display.asm).

III. , ,

142

14.3. ()
14.3.1.
, . . , , . .
. . ,
"". .
, ( ),
. ,
. .
, .
, ,
. :
MDA (Monochrome Display Adapter );
Hercules ( "");
CGA (Color Graphics Adapter );
EGA (Enchanced Graphics Adapter );
VGA (Video Graphics Array );
MCGA (Multi-Color Graphics Adapter VGA);
sVGA (Super Video Graphics Array ,
).

CGA "". (?) EGA.
"" , 10h 21h.
,
( ,
), . ,
"" 21h .
. , CGA-,
. :
8086. PC/XT .
80286+...

( ) : Height_X Width_Y. .
. Height_X , Width_Y . Num_attr (Main_proc, main.asm).
Draw_frame, display.asm.

14.

143

14.3.2. Draw_frame
. ,
( ).
(main.asm), :
Height_X ;
Width_Y ;
Num_attr .
. .
, . Draw_frame (display.asm).
! , , . 2 . :
Draw_frame

...
(1)
(2)
(3)
(4)
...

mov
shr
mov
sub

ax,Height_X
al,1
dh,11
dh,al

(1) ax , . , (2), shr


al 1 .
shr? :
mov
shr
shr
shr
shr

ax,16
ax,1
ax,1
ax,1
ax,1

;ax
;ax
;ax
;ax
;ax

=
=
=
=
=

10000b, . . 16
1000b, . . 8
100b, . . 4
10b, . . 2
1b, . . 1

, 2.
. . , div (, , ). (3) dh , . . 11. 11 .
, 5 . :
ax = 10
ax = ax/2 = 5
ax = 11-5 = 6

, 6. (). . , -
, :
.
, / .

III. , ,

144

?
, , ,
0B800:0000h 0B800:1000h ( ). ,
. , . . 0
1000h. 2 ( ),
3 160 (80 2 = 160). (, , . . ),
161, 0B800h. , /, ,
"" . ( !):
;dh
mov dh,0
; dl ( )
mov dl,15
; ,
;(. . ), 15 .

2 ( ) ( Linear
):
; 2 , . .
; : +
Linear = dl*2
Linear = Linear + dh*160

Linear 30. , : 0B800:001Eh


(1Eh=30). :
mov dh,8

; 8

mov dl,56

; 56

Linear = dl*2

; Linear = 112

Linear = Linear + dh*160

; Linear = 1392 570h

( ):
Linear = (24 160 + 80 2) 2 = 0F9Eh.
:
80 , 2 (
, ).
24 , 0.
80 ( 1): 80 2 = 160, , (24-) , 24 160.
( 24- + 2).
:
(24- 160 + 80- 2) 2

(24 160 + 80 2) 2 = 3998 0F9Eh.

14.

145

14.4.
, . , (Get_linear,
display.asm) ( 14.2).
14.2. Get_linear
...
; dl 2 (dl=dl*2). 1 (
;; . ).
shl dl,1
mov al,dh

; al ,

mov bl,160

; 160

mul bl

;: al () * 160; ax

; mul , .
mov di, ax

; di

xor dh, dh

; dh

add di,dx

; di .

...

14.5.
. 14.314.5 . 14.3
14.5 , . 14.314.5 .
14.3. shl

shl ,

Shift left

8086

14.3. shl
mov ax,100b
shl ax,1

; ax 1000b

14.4. shr

shr ,

Shift right

8086

III. , ,

146

. 14.3. shl

. 14.4. shr

14.4. shr
mov ax,100b
shr ax,1

; ax 10b

14.5. mul

mul bl

Multiplex

al bl

8086

al bl, ax.

14.

147

14.5. mul
mov al,5
mov bl,2
mul bl

; ax 10

. 14.5. mul bl

, , .
.

15


"" . ,
. :
1. (,
).
2. "A" "a" "" "" .
3. Norton Commander, Volkov
Commander, Dos Navigator.
, 746 !

15.1.
( Init) .
, :
"" ( 9889h ax) "" ( 8998h ax). 21h 9889h 8998h,
(- ah al). Int_21h_proc, ah/al,
, .
.
, int 27h ( 15.1).
15.1.
...
mov
int
cmp
jne
...

ax,9889h
21h
ax,8998h
Set_resident

,
, . , Int_21h_proc

15.

149

21h ! , ,
( , 25h
21h) ( 15.2).
15.2.
...
; 21h
mov ax, 3521h
int 21h
; () 21h
; ()
mov word ptr Int_21h_vect,bx
; ()
mov word ptr Int_21h_vect+2,es
mov ax, 2521h
mov dx,offset Int_21h_proc
;,
int 21h
...

,
int 27h, ,
.
Int_21h_proc 21h (. 15.1).

. 15.1.

150

III. , ,


, . DOS, int 20h,
""! , (Int_05h_proc, Int_21h_proc,
Int_1Ch_proc), , .
21h ,
( Int_21h_proc). , , . "" , -
.

15.1.1.

21h?
DOS, , .
, ,
, "", ,
, .
, 21h , 3Dh ( ) . , ,
21h, . ,
, 3Dh,
, . DOS,
, 21h . , ( )
21h, , , DOS,
.

32- , ( ):
Int_21h_vect dd ?

Int_1Ch_vect dd ?

. .
dd "define double word"
.

15.

151

15.1.2.

2
() .


jmp dword ptr cs:[Int_21h_vect]
dword ptr , "", ,
(:), Int_21h_vect.
cs: , . cs: , . . , . cs:,
:
jmp dword ptr ds:[Int_21h_vect]

, . . ds cs (.
-).
, , , ( resid15.asm). cs,
, , ( ).
([ ]) , "" ,
Int_21h_vect,
.
jmp dword ptr ... " jmp ".


call dword ptr cs:[Int_21h_vect]

, . .
, call
. . , . :
(near) . call .
,
, ,
. , call, .
:
call Near_proc

III. , ,

152

(far) . , . ,
,
.
, , .
, :
call dword ptr cs:[Far_proc]


Far_proc, , . . ,
call.

15.2. ret retf


15.2.1. ret
ret 15.3.
15.3.
;, (ss=1234h, sp=0FFFFh).
...
(1) [1234:0100h]

mov ax,0A0Bh

(2) [1234:0103h]

call Our_proc

(3) [1234:0105h]

mov dx,123h

; Our_proc

...
(4) [1234:0200h]

Our_proc proc

(5) [1234:0200h]

mov dx,offset Message

...
; ( 1234:0105h)
(6) [1234:0250h]
(7) [1234:0250h]

ret
Our_proc endp

...

, (1) 1234:0100h,
Our_proc 1234:0200h (. ). (2), cs
(1234h), ip (0105h).

15.

153

(2)
( !), . . 0105h. 0200h (
). , Our_proc proc : -.
Our_proc, ( 0105h) . , , . .
- , ,
, , ret,
, , .
, . ret. ret
, , . (
"" ), ret 0105h,
. . , call, .
ip

!

( 15.3 0105h).

15.2.2. retf
,
. , , 3456:0400h . , , , (
1234h, 3456h). ( New_proc)
3456h 0400h New_proc, . ( 15.4).
15.4.
...
;
mov word ptr [New_proc],0400h
;
mov word ptr [New_proc+2],3456h
;
call dword ptr [New_proc]
...
New_proc dd ?

; (2 )

...

15.4 New_proc ,
( , -

III. , ,

154

). call dword ptr,


, .
: ,
, ? :
ret: ret retf. retf ( . return far
) , (
ret, ).
(call dword ptr [Far_proc]), , ret, "". 15.5 15.6 .
15.5.
...
[1234:0200h]

call Near_proc

...
; Near_proc ( ,
; )
[1234:4569h]

Near_proc proc

...
; (,
; , , )
[1234:6789h]

ret

[1234:6789h]

Near_proc endp

...
15.6.
...
[1234:0200h]

call dword ptr cs:[New_proc]

...
; New_proc ( )
[3456:0300h]

New_proc proc

...
; (,
; , , )
[3456:0534h]

retf

[3456:0534h]

New_proc endp

...

.
, , ,
, , .

15.

155

, , , ,
. , . , , .

15.3.
. iret
"! . - !
pushf , ?"
call dword ptr [Int_21h_vect]
...
pushf

call dword ptr [Int_21h_vect]

...

pushf
? . ,
, .
: .
int,
. , , 21h, 16h,
10h .
,
() .
, , , . 15.7 09h
() , (
).
15.7. 09h
; 09h, - ,
; - :
...
[0900:0050h]

mov al,bl

; , . , ,
; , (. )
[0900:0052h]

...

[0900:0345h]

iret

...
; , :
...
(1) [1234:0200h]

mov ax,Num_regax

III. , ,

156
(2) [1234:0205h]

cmp ax,17

(3) [1234:0208h]

jne Not_equal

...

09h ,
- , , -
(, ).
, ,
(2). ? , . ,
, DOS .
. .
. ,
(2) . (3)
, , ax 17. 1234h, 0208h
( ).
, 09h,
( ,
10h 16h),
, , ?
(cs), ( ip), . , , 09h ,
. ,
, cs:ip! ,
( 09h).
cs:ip ,
( 09h),
(
, ). " "?
"" . "
", . . ( , , , jmp Init . 15.1.2), .
, 09h. - , ,
, 09h,
.
, 09h ax, , , , , ,
ax Num_Regax (1).

15.

157

: , , . , , 21h, "" , , . ,
. ,
"" , ...
, 09h (. . 09h) :
iret ( . interrupt return ).
ret ,
(cs), (ip) , (ip)
( ret). ret iret.
:
ret ; , ( near
( ));
retf ; , , (
far dword ptr);
iret , . .
iret (cs:ip). 15.7 cs=1234h, ip=0208h, , . .
1. . , , - . ,
.
:
call dword ptr cs:[Int_21h_vect] pushf ?
. retf iret
(. ). () call dword
ptr ... (cs) (ip)
call . iret , . call dword ptr! ,
"". , "".
, !

15.4.
21h?
,
, 4Eh 4Fh. ,
. .

158

III. , ,

4Eh , , -
, DTA , , :
;
;
;
.
4Fh. ,
. MS-DOS.
21h. , , DTA
21h ( 15.8).
15.8. 21h
...
;: - 4Eh 4Fh ( )
cmp ah,4Eh
je Do_not
cmp ah,4Fh
je Do_not
; ,
; 21h " jmp". ,
;. . . ...
Go_21h:
jmp dword ptr cs:[Int_21h_vect]
;, - 4Fh 4Eh...
Do_not:
pushf
call dword ptr cs:[Int_21h_vect]
...

DTA, 21h ,
. , , ,
, .
, Do_not 15.8. 21h. !
21h. ,
int 21h, , "" .

15.

159

! 21h,
.
, DOS. "" 21h.
""
, !
, .
DTA. ?
" , DTA!" . ,
. . DTA 2Fh
21h. , 21h:
int 21h

? 21h int 21h,


, Int_21h_proc.
: ah 2Fh.
, , Int_21h_proc ah 2Fh.
4Fh ah? ! ,
21h 4Eh 4Fh, call dword ptr cs:[Int_21h_vect],
int 21h. ? ,
, ...
DTA . . , 2Ch 21h,
. - .

15.5.
, -. : and, or, xor.
. .
.
, .

15.5.1. or
or () ( !)
, (. 15.1 . 15.2).
mov

ax,1010b

or

ax,1111b

; ax=1111b=0Fh. ()
; .

III. , ,

160

15.1. or

or

. 15.2. or
mov

ah,1000b

or

ah,1001b

; ah=1001b. ,
; , !

15.5.2. and
and () (. 15.2, . 15.3).
mov

ax,1010b

and

ax,0101b

; ax=0000b=0h.
;( , ).

15.2. and

and

15.

161

. 15.3. and
mov
ah,1001b
and
ah,0001b
; ah=0001b. .

15.5.3. xor
xor ( )
(. 15.3, . 15.4).
mov
xor

ah,1010b
ah,1100b

; ah=0110b=06h

15.3. xor

xor

. 15.4. xor

III. , ,

162

xor / :
mov al,0

;al=0

xor al,1

;al=1

xor al,1

;al=0

xor al,1

;al=1 . .

15.6.

, 21h
. - ,
.

15.6.1. 05h
05h (. .
05h) <Shift>+<Print
Screen>. (
BIOS). ,
. 05h. ( Int_05h_proc).

<Shift>+<Print Screen> ... , . Screen.txt.
! .
05h. -.
, 2 : . - !
"", . . , 40h 21h,
Screen.txt. !
...

15.6.2. 09h
, ,
- . /, .
60h -.
, in.

15.

163

ASCII- -. 09h
- ASCII-. .
( 15.9).
15.9. 09h
...
(1) Int_09h_proc proc
(2)

pusha

(3)

in al,60h

(4)

cmp al,58h

(5)

jne No_F12

(6)

xor cs:Num_status,1

(7) No_F12:
(8)

popa

(9)

jmp dword ptr cs:[Int_09h_vect]

(10) Int_09h_vect dd ?
(11) Int_09h_proc endp
...

- <F12> 58h ( - . 3). 60h - .


<F12>, Num_status
09h.
, ,
. . 09h ASCII- .
- ! , ,
, .
"" Num_status,
...

15.6.3. 1Ch
,
18,2 . -
1Ch, .
Int_1Ch_proc ""
"A" "a" "O" "o".
18,2 . :
...
cmp cs:Num_status,0

164

III. , ,

jnz Go_1Ch
...

, "" Num_status. ,
. ,

Int_1Ch_proc ,
Go_1Ch. :
...
Go_1Ch:

jmp dword ptr cs:[Int_1Ch_vect]


...

1Ch. Num_status
,
, . . . 09h, Num_status <F12>.
xor. xor
...

15.7.
, , , - .
,
.

16


AFD Pro.
, . . .
:
, . .

. ;

. ,
,
.
, AFD Pro. , .
http://www.Kalashnikoff.ru.

16.1.
, ?
? , !
. :
;
.
. .
,
? .

16.1.1. 03h
, ,
. :
<Shift>+<Print Screen> 05h;

III. , ,

166

09h;
1Ch 18,2 .
15.
00 1Fh "" BIOS (). ( ). , MS-DOS 20h 2Fh (int 20h
; int 21h . .).
" "? ,
,
20h0FFh (. . , / ). , ( 00 1Fh), , .
03h?
-, , ,
AFD CodeView.
-, 0CCh,
. , int 20h0CDh 20h, . .
.
-, 03h : iret, . .
. , , , . .

03h,
int 3.

03h.
, () . ( <F1>
<F2>),
0CCh, . . int 3. , , , int 3. . ,
"Q" ( 16.1).
16.1.
cseg segment
assume cs:cseg, ds:cseg, es:cseg, ss:cseg
org 100h
Begin:
mov ah,2

16.

167

mov dl,'Q'
int 21h
ret
cseg ends
end Begin

. 16.1 , .
16.1. :

0100h

Mov ah,2

0B402h

MOV AH,02

0102h

Mov dl,'Q'

0B251h

MOV DL,51

0104h

Int 21h

0CD21h

INT 21

0106h

ret

0C3h

RET

, . . , <F1>/<F2> AFD.

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


, Hacker's View.

, AFD. mov ah,2 100h, mov dl,'Q' 102h (. . 16.1). ,


, .
, <F2>. AFD 1
102h ( mov ah,2 ;
0B2h), 0CCh, . . int 3,
mov ah,2. mov dl,'Q', int 3 03h, AFD (-

III. , ,

168

!). <F1>,
(. 16.2).
16.2. <F2>

0100h

mov ah,2

0B402h

MOV AH,02

0B402h

0102h

int 3

0CCh

MOV DL,51

0B251h

0103h

push cx

51h

0104h

int 21h

0CD21h

INT 21

0CD21h

0106h

ret

0C3h

RET

0C3h

03h ?
, 0102h (. . 16.2). <F1>/<F2>. 03h :
1. .
2. (0B2h) 102h.
3. (mov dl,'Q' = 2 =
= 0B251h).
4. mov dl,'Q' ( 104h),
0CCh (. . int 3),
( 0CDh) .
5. mov dl,'Q', int 3, ( 03h).
6. 03h - .
7. ( ).
8. .
<F2>,
(. 16.3).
16.3. <F2>

0100h

mov ah,2

0B402h

MOV AH,02

0B402h

0102h

mov dl,'Q'

0B251h

MOV DL,51

0B251h

0104h

int 3

0CCh

INT 21

0CD21h

0105h

and bx,ax

21C3h

RET

0C3h

0107h

""

""

""

""

, 0105h21C3h.
, 0104h, 0CCh (int 3).

16.

169

, , , 1,
2 . , mov ah,2 0B402h 2 ; ret 0C3h 1 .
""
0B4h, , 0C3h, mov ah,2 ret (
0C3h). ret , mov ah,2.
mov ah,2 (02h)?
02h add dh,[CD51+BP+SI].
4 , "" 02h 0B2h, 51h, 0CDh.
, ... 105h
. 16.3. 21h and. and
(, and ax,11b). ,
21h , 0C3h. 21C3h and
bx,ax! 103h - push cx . 16.2.
: " " , , ,
. . . ,
1 , ( ) . ,
Hacker's View , .
, ,
""? , 03h , . <F2>
(. 16.4).
16.4. <F2>

0100h

mov ah,2

0B402h

MOV AH,02

0B402h

0102h

mov dl,'Q'

0B251h

MOV DL,51

0B251h

0104h

int 21h

0CD21h

INT 21

0CD21h

0105h

int 3

0CCh

RET

0C3h

: ret int 3
. . 16.5 ,
<F2>.
16.5. <F2>

0100h

mov ah,2

0B402h

MOV ah,02

0B402h

0102h

mov dl,'Q'

0B251h

MOV dl,51

0B251h

0104h

int 21h

0CD21h

INT 21

0CD21h

0105h

ret

0C3h

RET

0C3h

: "Program terminated OK" (" ").

III. , ,

170

16.2.
, AFD ?
. : AFD 03h, 0CCh (int 3) . 03h .
.
03h iret. 35h 21h. , ,
Microsoft . .

16.2.1.
, 0000:0000h.
, 4 : (2 )
(2 ), 2 ,
( , , ":"). , 0000:0000h, 0000:0004h,
0000:0008h . . 16.2
21h .
16.2.
...
xor ax,ax
mov es,ax

; es

mov bx,es:[21h*4]

; bx

mov es,es:[21h*4+2]

; es

; 21h
mov Int_21h_offset,bx

mov Int_21h_segment,es

; 21h
mov ah,2
mov dl,'!'
pushf

; pushf ...

call dword ptr [Int_21h_offset]


...

; int 21h

16.

171

Int_21h_offset dw ?
Int_21h_segment dw ?
...

, , . . . :
mov bx,es:[21h*4]
mov es,es:[21h*4+2]

, , , , .
, , , 21h*4+2. , .
: 21h*4+2=134 (86h). , , , . . -. , , mov
es,es:[21h*4+2] mov es,es:[86h]. ,
, , :
mov ax,(23+5)*3
mov cx,34h+98/2

, , .
? ? :
. , es 21h:
mov es,es:[21h*4+2]

;21h ; +2 .

mov es,es:[86h]
- , , es. , , . :
...
, mov ax,[bx+di] ,
. . bx di , ! -, bx di ? ax ,
bx di.
[21h*4+2] es? ,
es, 21h, - .
es , es,
21h*4+2, - , , es. , , (. . ) es ( 16.3).

III. , ,

172

16.3. es
...
xor ax,ax
mov es,ax

; es

...
mov es,es:[21h*4+2]

; es

...

16.3.
. , 03h iret, "" . 03h ( 16.4).
16.4. 03
...
xor ax,ax
mov es,ax
mov bx,es:[03h*4]

; bx

mov es,es:[03h*4+2]

; es

...

iret ( iret 0CFh) :


mov byte ptr es:[bx],0CFh

, 03h . ,
. ( int 20h)
(. dbg16_01.asm).
int 20h , . . 20h ,
.
-,
"!DEBUG.ASM". :
1. .
2. "!DEBUG.COM".
3. DOS ( | | cmd) Far Manager.
4. AFD CodeView.
5. , call nop.
6. AFD 4 <F2>,
"Program terminated OK".

16.

173

7. CodeView 4 <F10>, "Process XXXX terminated normally".


8. .
9. . nop, !
...
, ,
.
? . 16.6.
16.6. ret int 3

0120h

int 21h

0CD21h

INT 21

0122h

int 3

0CCh

RET

, .
, 16.5.
16.5.
...
mov ah,3Fh
mov bx,Handle
mov cx,offset Finish-100h
mov dx,offset Begin
int 21h

; ...

ret

;... 16.6

...

.
, ,
?
int 3 (0CCh). ,
. int 3 ret!
, int 3 ()?
-, 016, dbg16_0?.asm. , , .
,
Windows 9x.

17


17.1.

, ,
. , 7- , . .
, ,
-
. , , , mov dx,offset Message mov dx,400h. "-" , , Message. ,
400h , - .
ip mov .
. , 17.1.
17.1. ip
...
; ,
; call (. . pop ax).
call Label_1
Label_1:
; .
pop ax
; ax ().
...

17.

175

call Label_1 , (. 17.1, 17.2 17.3). ,


mov dx,offset Message call Label_1. ,
dx ( ), "". , ,
Label_1.
,
, .
.

. 17.1.

. 17.2.

III. , ,

176

17.2.
, virus17.asm. Init , Get_ip (. . 17.1).
Get_ip.
, . . , Get_ip 0203h ( 17.2).
17.2.
...
(1)
(2)
(3)
(4)
...

[1234:0200h]
call Get_ip
[1234:0203h] Get_ip:
[1234:0203h]
pop ax
[1234:0204h]
sub ax,offset Get_ip

. 17.3 , , .

. 17.3. ax

(1) 0203h, (3) 0203h. , () . , , : mov ax,cs,


ip. / ip !
: (4) 203h
Get_ip . (4) :
sub ax,0203h

;sub ax,offset Get_ip ax=203h-203h=0

17.

177

,
, 1000h (
).
( 17.3).
17.3. "-"
...
(1) [1234:1200h]

call Get_ip

(2) [1234:1203h] Get_ip:


(3) [1234:1203h]

pop ax

(4) [1234:1204h]

sub ax,offset Get_ip

...

(1) 1203h. Pop ax .


:
sub ax,203h

;sub ax,offset Get_ip ax=1203h-203h=1000h

ax "-", . . 1000h. ,
!
, .
, . . 20, ,
, . , "" .
, ax "-".
,
"" , ax, . . "-".
( 17.4).
17.4.
...
; 7- , . . ,
; , "".
push 0BF00h
pop es
;es , ,
mov di,offset Open_file
;di ( (. -))
mov si,di
;si (), . .
; "-"...
add si,ax

III. , ,

178
mov cx,offset Finish-100h

;. . cx =
rep movsb

...

, . , offset , , 09h.
( -) , di
() Open_file, . . mov ax,3D02h (
mov, ).
7- .
("") . jmp.
- . , : ret, retf iret ( 17.5).
17.5. retf
...
(1)

mov bx,offset Lab_return

(2)

add bx,ax

(3)

push cs

(4)

push bx

(5)

retf

(6) Lab_jmp:
...

. 17.4 17.5 , ( cs).


, retf,
. retf 2 (4 ):
, . . , ,
. , , .
, .
, . (1)(4). , , , , . (1), (2)

17.

179

. "", ax.
Lab_jmp (, , ). , (5).
: , "-"?
.

. 17.4.

. 17.5.

180

III. , ,

17.2.1. "-"
, "-", , :
First_bytes db 90h, 90h, 90h, 90h, 0CDh, 20h

:
90h nop;
0CDh int;
20h 20h.
:

nop
nop
nop
nop
int 20h

6 "-",
jmp . , , "-".
, , ,
100h "" . , - , , - .
nop, int 20h.
, .
- ( COM-) (
virus17.com). : , ,
6 100h, , "-" .
. , 100h, . -
First_bytes ,
(. 17.6 17.7).
-,
First_bytes db 90h, 90h, 90h, 90h, 0CDh, 20h

First_bytes db 4 dup (90h), 0CDh, 20h

dup ( . duplicate) , , . . , . , 6 .
:
Array db 1500 dup ('1')

Array 1500 , 1,
. "-

17.

181

", , dup,
.

. 17.6. 100h

. 17.7. 100h

17.2.2. "-"
, 100h ( "-" , ) ( 17.6).

III. , ,

182
17.6. 100h
...
mov ax,100h
jmp ax

; , ax

...

. 18 ,
, ,
, .

18


18.1.

/ , Get_linear
display.asm 14,
( 18.1 18.2).
18.1. (14 )
; display.asm, Get_linear, 17
...
push ax

push bx
push dx
shl dl,1

;: dl 2 (dl=dl*2)

mov al,dh

; al ,

mov bl,160

; 160

mul bl

;: al()*160; ax

mov di,ax

; di

xor dh,dh

; dh

add di,dx

; di

pop dx

; ...

pop bx
pop ax
ret
...

III. , ,

184

18.2. (13 )
...
push ax
push dx
xor ax,ax
xchg dh,al

;: dx = dl, ax = dh

mov di,ax
shl ax,6

;dh * 64

shl di,4

;dh * 16

add di,ax
add di,dx
shl di,1

;di * 2

pop dx
pop ax
ret
...

, 1 . .
, . . shl, mul,
ax.
:
= (COL 80 + RAW) 2.
:
= (COL 64 + COL 16 + RAW) 2.
:
= ((COL shl 6) + (COL shl 4) + RAW) shl 1.
!
div () mul () ,
.

. ,
, .

18.2. 17
17 .
, .
? , ,
- , - . , , -

18.

185

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

18.3. Super Shell


, (sshell8.com) , , <Ctrl>+<F5> <Esc>.
...

18.3.1.

Draw_frame.

. Windows . Windows
"". " ".
.
. : , , 20 , ,
, ,
. ?
ret N, N . , ret N ret, ,
,
. ( 18.3).
18.3.
...
(1)

push 123h

(2)

call Our_pr

(3)

pop ax

...
(4) Our_pr proc
...
(5)

ret

(6) Our_pr endp


...

Our_pr (2), (1). ? ,

III. , ,

186

09h
.
Our_pr , ( 123h). , . .
. (3).
. , , 20 ?
? ,
. , - ,
.
ret N, N . ( 18.4).
18.4. ret N
...
(1)

push 123h

(2)

call Our_pr

...
(3) Our_pr proc
...
(4)

ret 2

(5) Our_pr endp


...

ret 2 , sp 2, . . "" , .
?
,
, :
-, ;
-, ,
;
-, ;
-, .
, - , ( ) . , Draw_frame?
. . 10 . , ( 18.5).

18.

187

18.5. Draw_frame
...
push 23

push 78

push 1F00h

push offset Mess_head

push 1E00h

push offset Mess_down

push 1D00h

push 0

push 0

push 0

; ?

call Draw_frame

...

, push 23, push 0 2 ,


1. :
push 23

- 2

push 78

- 2

push 1F00h

- 2

push offset Mess_head

- 2

... . ...
:

- 20

, Draw_frame
. , :
ret 20

,
20 (10 ), .
!
,
(. 18.118.3).
:
?
bp,
.
.
. ,
. .
( 18.6).

188

III. , ,

. 18.1.

. 18.2.

. 18.3.

18.

189

18.6. bp
...
(1)

push offset Message1

(2)

push offset Message2

(3)

call Print_string

...
(4) Print_string proc
(5)

mov bp,sp

(6)

add bp,2

(7)

mov ah,9

(8)

mov dx,[bp]

(9)

int 21h

(10)

mov dx,[bp+2]

(11)

int 21h

(12)

ret 4

(13) Print_string endp


...
(14) Message1 db '!$'
(15) Message2 db ' !$'
...

, 09h 21h. , , , .
, ?
" !", "". , , :
. , , ,
. (8) Message2, (10) Message1.
!
. 18.4.
, ( (5), (6))
bp , bp 2.
, "" ,
(3). call . , . .

III. , ,

190

bp 2, .
. : , (12). 4 , , ret 4.

. 18.4.

", ! ! 10, 50, 100


, . , !"
. ! .
( ) equ
( . equivalent ). ( Finish EQU $?) ,
. , 18.7
equ.
18.7. equ
...
(1)

push offset Message1

(2)

push offset Message2

(3)

call Print_string

...
(4) Print_string proc
(5)

mov bp,sp

(6)

add bp,2

18.
(7)

mov ah,9

(8)

mov dx,Mess1

(9)

int 21h

(10)

mov dx,Mess2

(11)

int 21h

(12)

ret 4

191

(13) Print_string endp


...
(14) Message1 db '!$'
(15) Message2 db ' !$'
(16) Mess1 equ [bp+2]
(17) Mess2 equ [bp]
...

:
"", " ". (16), (17) . MASM/TASM
mov dx,Mess1
mov dx,Mess2

mov dx,[bp+2]
mov dx,[bp]

. ,
. , " ": . ,
(data.asm):
Height_X

equ [bp+18]

Width_Y

equ [bp+16]

Attr

equ [bp+14]

. .
(DRAW_FRAME,
display.asm):
mov ax,Height_X
mov ax,Attr

. .
, !

, :
Heigt_X , Height_X equ
[bp+18]. : ret 20, . . 20 . ()

III. , ,

192

, , . : / , . ,
. , Windows , ! ,
!

18.3.2.
. Other.
, ""
"". . , , , ( )
,
(. ). , ,
, .
, Other , . , . , 8 ( , , 8 ).
. 8
? , !
, :
push offset Mess_head

. :
; ( 0, )
push offset Mess_head
push 1E00h

, .
, ? ...
, ,
( ). , . 16 , 20. .

18.3.3.

, , ,
:
Mess_quit db '',0
Mess_quitl equ $-Mess_quit

!
mov dx,offset Mess_quitl

18.

193


mov dx,0009

? mov ax,23+5*2.
. , - Mess_quit , - (MASM/TASM) . ...

18.3.4. Copy_scr / Restore_scr (display.asm)


(), , (
). Far Manager <F5>, <Esc>.
, , , . ,
- . , . , , . : <Ctrl>+<O>.
: Copy_scr ( )
Restore_scr () (display.asm).
: dh (),
, dl () (
). ax ,
dh. ( Get_linear) ( 18.8).
18.8.
...
xor dl,dl

; dl. dh = , dl = 0

call Get_linear

...

(, ).
160 ( 18.9).
18.9.
...
mov bl,160

; ,

mul bl
mov cx,ax
...

; cx ( cx )

III. , ,

194

al .
bl al, ax, cx. . , . .
(dl 0 79; dl ).
, .
. (
, ) ( 18.10).
Mul bl

18.10.
...
mov si,di

;ds:si

xor di,di

;es:si

;
mov Num_copysi,si
mov Num_copydi,di
mov Num_copycx,cx
push 0B800h

pop ds
push 0BA00h
pop es
rep movsb

;...

...

,
. (. Restore_scr.)

18.3.5. scas
, (
) (. 18.1).
18.1. scas

scas

Scan string

8086

, movs stos, :
,
( ). es:di ( 18.11).
scasb scasw. scasb
scasw

18.

195

18.11. scas
...
;es:di
(1)

mov di,offset String

;cx /
(2)

mov cx,offset String_len

; (9)
(3)

mov al,9

; , al
(4)

repne scasb

...
(5) String db 1,2,3,4,5,6,7,8,9,10,11,12
(6) String_len equ $-String
...

cx ( /) String, . . 12.
al , . (4) di
, (. . 10). , , :
1. repne? rep.
, repne ( . repeat if not equal , )
() , , al/ax,
() .
, repe ( . repeat if
equal , ).
2. repe?
, ,
repne ( 18.12).
18.12. repne
...
;es:di
(1)

mov di,offset String

;cx /
(2)

mov cx,offset String_len

;
(3)

mov al,1

; , , al
(4)

repe scasb

III. , ,

196
...

(5) String db 1,1,1,1,1,6,1,1,1,1,1,1


(6) String_len equ $-String
...

(4) di
6 (. . 1), .
, , al, , je Label ( Label, ).
(repe) ,
, al/ax.
3. , 18.11 al 13?
, 12 String 13, , di String.
4. , 18.11 cx , , 7?
, scasb 7 , 9
( al). , di 8 String, . ,
jnz Label (, ,
).

18.3.6.
scas, (Count_strmid, display.asm). ?
ASCII- 0. ,
. , ( 18.13).
18.13.
...
(1)
(2)
(3)
(4)
(5)
(6)

push cs
pop es
mov di,si
xor al,al
mov cx,0FFFFh
repne scasb

;es=cs
;di=si
;al=0
; ( )
; 0 ...

;0 ! di
;si=
;di= +1
(7)

sub di,si

;di=di-si-1 =

18.
(8)
(9)
(10)
(11)
(12)
...

dec
shr
mov
sub
mov

di
di,1
ax,40
ax,di
dl,al

197

; 2
; 2 = 40
;ax=40- =
;dl=, .

si , . scas es:di, di si (
(3)). al (4), cx .
, ,
, cx. (6)... ,
'0' (7). .
: si , di
+ 1. , di si
((7), (8)):
di = di si 1 = .
, (. 18.5).

. 18.5. 2. di = / 2

(9).
80 ( 3), 80 , . . :
di = ,
dl = (80/2) (di/2).
dl , .
.

198

III. , ,

18.3.7.

18.14.
18.14. (Print_string, display.asm)
...
Print_string proc
(1)
call Get_linear
...

Next_symstr:
(2)
lodsb
;
(3)
or al,al
; 0 ( ?)
(4)
jz Stop_outstr
; ...
; (ah) (al)
(5)
stows
(6)
jmp short Next_Symstr
; ...
(7) Stop_outstr:
(8)
ret
Print_string endp
...

ds:si
, dx (dh , dl
()), ah .
dx . , ?
-, . ,
, , ? , , .
-, : / , ? , .
-, . 8086/8088 .
.
, , 0. , (,
09h '$'). , . .
, 0 .

18.

199

. !
, , (MAIN_PROC, main.asm).
Quit_prog .
""/"". , , .
, <Ctrl>+<F5> (MAIN_PROC, main.asm).

18.4.
,
Far Manager, HELPASSM.
, " ", ,
,
. .
, (,
Draw_frame, Print_string), .
! ,
. !

19


19.1.
.
, , .
, 21h.
(, )
LOG-.
21h . 19.1.
19.1.
ax

ax = 4B00h

ah = 39h

ah = 3Ah

ah = 3Bh

ah = 3Ch

ax = 3D02h

ah = 41h

Microsoft 21h
ds:dx . , - .
19.1 19.2.
19.1.
mov ah,39h
mov dx,offset Directory
int 21h

19.

201

19.2.
mov ah,41h
mov dx,offset File
int 21h

4B00h. ,
ds:dx, . , . . .
.
MS-DOS Windows
(. 19.2).
19.2. MS-DOS

000001b

000010b

000100b

001000b

010000b

100000b

Windows MS-DOS
, Windows , : , , . .
, . :
100001b " " "";
000110b "" "".
, .
, "" " " .
. 19.1 ,
3Ch.
ds:dx, cx.
"" "".
100010b, 22h.
, , " ".
() ,
. "", "".

202

III. , ,

. 19.1.

?
COM 100h. 0 0FFh
PSP (Prefix Segment Program). PSP . ,
0 int 20h, 80h DTA
.
, PSP (. . ""
100h ). , 100h . ,
, , ,
. - , PSP ( ,
).
:
1. , 100h,
0. . .
2. ,
.
3. PSP , . .
, 100h .
, .
, .
,
21h , LOG- (c:\report.txt). ,
21h ( 19.3).

19.

203

19.3. 21h
...
cmp ax,4B00h

; ?

je Start_f
cmp ah,39h

; ?

je Create_dir
...
; - ,
; 21h ...
jmp short Go_21h
Start_f:
; LOG-.
mov si,offset Start_filemess
call Move_string

; ...

jmp short Go_21h

; 21h...

Create_dir:

; ...

mov si,offset Create_dirmess


call Move_string
jmp short Go_21h
...

, - . , - .
, 39h.
Create_dir ( ). . si Create_dirmess:
...
Create_dirmess dw Create_dirmessl
db ' ---> '
Create_dirmessl equ $-Create_dirmess-2
...

, , si,
. , :

204

III. , ,

-
, , . :
Create_dirmessl

Create_dirmessl equ $-Create_dirmess-2


$ ( ) Create_dirmess (. .
).
Create_dirmessl . ,
. .
si , Move_string.
bx , .
, : Move_string 0 , (. . PSP),
(, " ---> "), ,
, ds:dx 21h.
, . ,
:\\_ C:\My_dir\file.ext. 0 , .
, - c:\assm\directory,
LOG- :
---> c:\assm\directory

, ,
. - ,
, .
, .

19.2. ?
. , , , . .
21h, 03h.
, . , 21h .
, .
-.
, , .

20


. ! , ,
. , !
. ( ,
!)
. ,
, COM-. , .
, .
, ! ,
Dr. Web, - .
COM- . ?
, C:\assm :
test.com;
dn.com;
nc.exe.
test.com . test.com ,
dn.com. dn.com, , . .
COM-.
PATH ( autoexec.bat) c:\assm,
, test.com , , c:\nc,
COM- c:\nc. !!!
, , ,
, . 24, . , ,
virus20.com , , .
COM-, C:\Windows\Command,
. .
PKLITE, . , -...
COM-.

III. , ,

206

, 16? ,
,
. , ,
, ,
. ? , int 3 (0CCh). , int 3, .
.
: 24 .
, !

20.1.
20.1.1. ret, call jmp
: ret call jmp, jmp ret?
. , .
. 20.1 .
20.1.

ret

pop ax

jmp ax
call proced

move bx,offset lab_ret


push bx

""

jmp proced
lab_ret:
jmp label1

push offset label1


ret

, (Init) :
...
push offset Init

;3

ret

;1

...

, , ,
Init . , ,
, .

20.

207

20.1.2.
Infect_file. , , .
( 20.1).
20.1.
...
mov ax,cs:[1Ch]

or ax,ax

; 0, ...

jnz Error_infect

;... , 64

mov bp,cs:[1Ah]

; (. . )

...

, , COM- 64 ?
, ,
, . "MZ"
"ZM", EXE, COM. , .
, , test.exe 450 test.com.
, EXE-, .
command.com, MS-DOS
7.0 95 . COM
, DOS.
, command.com, ,
, command.exe?
. . , , , .
, . 4Fh
4Eh , DTA 1Ah . 65 535,
. ( 1Ah) , (
1Ch) . , .
, ("MZ" "ZM"). ? , EXE-
64 , COM.
.
, .
:
1. / ( 3D02h 21h).
2. ( 3Fh 21h).
3. , .

208

III. , ,

.
, .
+4 . ,
1122h

cmp word ptr [bx+4],1122h

1122h : 2211h.
, .
, - +4
? , , ? , .
, ,
? ,
.
, , 10
20 , , .
, .
. ""
"-" .
4202h 21h (. 20.2).
20.2. 4202h 21h:

ax = 4202h

jc

bx =
cx, dx = ,

cx dx 0,
. .
, (). , , , ,
7.
, :
.
, ,
, ;
.
3000 , , 1500 , .

20.

209

,
"" "-" ( 20.2).
20.2.
...
mov ax,4202h

; / .

mov bx,Handle
xor cx,cx

; 0 .

xor dx,dx
int 21h
jc Error_infect
...

/ ,
,
40h.
( 20.3).
20.3.
...
mov ah,40h

; bx .

; "" "-"
mov cx,offset Finish-100h-F_bytes
mov dx,100h

; .

int 21h
jc Error_infect
...

"" "-",
, .
.
"-" , . , ,
,
.
"-" (
100h) , , ,
"" 100h.
: 6 ,
( 20.4).

210

III. , ,

20.4. "-"
...
; 6 "-"...
mov ah,40h
mov cx,F_bytes
mov dx,offset Finish
int 21h
...

, , "-", , "-"
, ,
.
6 , ""
, ,
Init. , , 6 "-".
6 ? , bp (. ). "-",
( 20.5).
20.5. "-"
...
push Init
ret
...

"-" , , 3000 , push , , , 5000 , , , .


! . . 6 "-"
(- !) 100h.

20.1.3.
, , :
1. COM-.
2. 6 .
3. 64 , (
1). .

20.

211

4. +4 1122h, ( 1). .
5. "" .
6. 6 "-".
7. .
8. Init .
9. ( ).
10. 6 +1122h ,
.
11. .
12. 6 "-" , "" "-" (. 6).
13. "-".
-
.
: . , COM-,
. . !

20.2.
! ! .
?
, , ,
, , .
: " , ?" , . , , , , , . , , ,
, . . .
, , , "" . .
DIR , , (, , ...). , ,
, , .
, , . ,
, - . !
: . ,

212

III. , ,

. , . , , . , " ".
, , . , -, :
? , , - -, ?
, ? ?
" , ?" .
: ,
. .
, , , , .
, ", " .
, COM-
. . :
, COM EXE,
COM- EXE-. ,
( ). . ,
, , ,
, , , .
, , , .
, , ! 21 .

21


21.1. SuperShell
21.1.1.
"", ,
, . . , , , . :
1. .
2. '.' 1, ( 4).
3. .
4. .
5. .
6. , .
7. , ( 4).
8. , .
9. 20 , ( 8). 20
, 10.
10. .
11. <Esc>, 12. ,
10.
12. : , .
13. , , <Y> <y>,
10.
14. <Y> <y>, .
, , .
1

. ,
. 'CD .', .
. DIR
.

III. , ,

214

21.1.2.

, Draw_frame (Main_proc,
main.asm). . .
,
. .
, ? , Mess_head Mess_down:
Mess_head
Mess_down

db 1Eh, ' Super Shell, 1.0 ',0


db 1Dh, ' , , 2010 ',0

.
, , ,
.
. (Draw_messfr,
display.asm) , , ah ,
. ( 21.1).
21.1.
...
;SI
mov ah,[si]
;
inc si
;
call Count_strmid
;
call Print_string
;
...

. 21.1
.

. 21.1.

21.

215


(Draw_frame, display.asm) . ( 21.2).
21.2.
...
push 10b

; , .

call Draw_frame

...

( ) , .
.

21.1.3. test
, , ? , cmp .
, , cmp . .
, , , . 1.
Draw_frame ( 21.3).
21.3.
...
; , ,
push 1

call Draw_frame
...

Draw_frame 21.3 Other. , , cmp:


cmp Other,1

, . . Other=1, .
. , ,
, . . , 0 ( 21.4).

216

III. , ,

21.4.
...
push 10b
; push 2
call Draw_frame
...
cmp Other,2
...

, , , ,
( 21.5).
21.5.
...
push 11b
; push 3
call Draw_frame
...
cmp Other,3
...

, , , , .
( , ) Draw_frame
, , , , .
: cmp , , (Other)?
and cmp. 21.6 , .
21.6. cmp
...
; ax Other
mov ax,Other
push ax
; , ( )
and ax,1
;, ax 1?
cmp ax,1
pop ax
mov Other,ax
; Other
je Ravno
;,
...

21.

217

, mov pop (
),
, 21.6.
: ? ,
, , 7 .
, ? !
, !
, , ... ,
test (. 21.1).
21.1. test

test ,

Test ,

8086

21.7.
21.7. test
...
mov ax,10100001b
test ax,1

;, .

jnz Ravno

;,

...

, cmp je/jz ,
. test .
, jne/jnz. , . . , ,
je/jz ( 21.8).
!
21.8. test
...
mov cl,100101b
test cl,1000b

;,

jz Ne_ravno

;,

...

III. , ,

218

, Other 8 .
"" "", . . "" " ". , , Draw_frame. ,
, .
, Other
, .
.
, ,
. , , .
21.9 -,
.
21.9. Other
...
mov ax,Other

test al,1

; 0?

jz No_copyscr

; , .

...

. 21.2 .

. 21.2. test

21.

219

21.2. DOS
21.2.1.

MS-DOS. 640 . .
, .
, DOS
.
, , ()
.
? : , , , .
, . ( ) ,
.
, 4Ah 21h
(. 21.2).
21.2. 4Ah 21h:

ah = 4Ah

jc , :

es =

ax =

bx = 16-

, , cs . 4Ah , es , . . 21.3
.
21.3.

Finish

220

III. , ,

,
.
: Finish. . , (Prepare_memory, main.asm) ( 21.10).
21.10.
...
mov bx,offset Finish
;bx=
; bx ,
; 16 , 4
shr bx,4
inc bx
; bx ( )
mov ah,4Ah
; /
; , . . , ,
; .
int 21h
...

4Ah
(. 21.4).
21.4.

Finish

Finish

640 ,
, Finish

640
Finish.

, , 1000h 16- () 65 536


( 21.11).
21.11. 65 536
...
mov ah,48h
mov bx,1000h

21.
int 21h
...
mov Seg_files,ax
...

221

. . 21.5.
21.5. 48h 21h:

ah = 48h

jc , :

bx = 16-

ax =
: ax =

65 536 . 21.6.
21.6.

Finish

Finish + 65 536

, Finish +
65 537

. 21.3 , 4Ah 21h.

. 21.3.

222

III. , ,

21.2.2.
64 ?
. :
, .
, , DIR .
. ,
. , , , .
? :
1. . , 5.
2. .
.
3. . , 5.
4. , ( 3).
5. ,
,
.
6. ( Number_files) (Out_files, files.asm).
, .

22


,
, . ,
http://RFpro.ru.
1. ?
,
.

.
- (,
MS-DOS),
Hacker's View,
.
2. . ?
CF (Carry Flag). 1,
. .
PF. 1,
, . .
.
AF. 3- .
.
ZF (Zero Flag). 1, 0,
0 .
SF (Sign Flag). 1,
( , . .
( )).
TF (Trass Flag). 1,
,
1.

224

III. , ,

IF (Interrupt Flag). 1,
.
DF (Direction Flag).
: 0,
1,
1.
OF (Overflow Flag). 1,
, , . . , .
3. , MS-DOS.
?
http://www.Kalashnikoff.ru.
helpassm.exe.
, RFpro.ru, . !

23

PSP DTA.
( DOS)
. , , :
( MS-DOS DOS);
;
" " ;
;
(
);
, .
,
, ,
( LOG).
(,
, , / .) LOG-,
. , , LOG- (, , COM-, Hacker's View).
. LOG- , . :
RESID23.COM c:\assm\log_file.txt

C:\assm\log_file.txt, .
, " ". .
, , LOG-
A:\super\file.log. LOG-, , . . , , , ? ? ?

226

III. , ,

23.1.
, . , .
. :
SYS.COM C: A:

SYS.COM C: A: , C: A:
, SYS.COM .
SYS.COM : :. ?
, , , PSP 80h. PSP, , , COM-. , COM 100h (org 100h), 80h , DTA. , , .

?
, - .
80h ?
, 80h,
. , . , , (20h). ,
.
0Dh ( <Enter>). . 23.1.
23.1.

80h

81h

<> (20h = 32)

82h

0Dh (13)

, SYS.COM :
SYS.COM C: D:

80h (. 23.2).

23. PSP DTA. ( DOS)

227

23.2.

80h

06h

81h

<> (20h = 32)

82h

43h 3Ah 20h 44h 3Ah

87h

0Dh (13)

43h 3Ah 20h 44h 3Ah ASCII- "C:_D:" ( "_" ).

6 , , 81h, .
. :
afd resid23.com params

params (. 23.1).

. 23.1. DTA

23.2.
( MS-DOS)
,
. :
PATH C:\WINDOWS;C:\WINDOWS\COMMAND
COMSPEC=C:\COMMAND.COM

228

III. , ,

TEMP=C:\TEMP
PROMPT=$P$G

... .
, .
, . ,
, path. , , .

SET, . . 23.2 Windows 2000.
SET .
:
, | |
| .
.
DOS , , PSP 2Ch, .
. ,
.

. 23.2. DOS

23. PSP DTA. ( DOS)

229

, , ,
, . , COM- , , 130 , 350 . ? , 27h, , dx
. , , dx,
. . 23.3 COM.
23.3.

0000h

PSP. int 20h

002Ch

DOS

0080h


DTA

00FFh

PSP

0100h

(:
Begin)


( ). ,

. ,

0134h

, ,
(: Init)

,

27h

( , , .)

,

27h

0154h

int 27h (
DOS)

,

27h

0156h

, ., .
,
, .
int 27h

,

27h

. 23.3 .

III. , ,

230

. 23.3.

, PSP .
(256 ), . , : + 256 PSP.
, .
, .
, , .
,
. PSP, DOS,
().
32 , , , 50100 .
DOS, , ?
, MS-DOS
. 640 .
, , ,
, - .
PSP 2Ch DOS. ,
.
, . ,
- ( 23.1).
23.1.
...
mov es,word ptr cs:[2Ch]
mov ah,49h
int 21h
...

; .
; .
; ...

23. PSP DTA. ( DOS)

231

. . 23.4.
23.4. 49h 21h:

ah = 49h

jc , :

es =

ax =

. , , (. . 49h),
, .
, DOS,
env23.asm, . DOS (
), .

23.3.
. ,
.
?
PSP , ASCII- , ( )
LOG-. ? , ,
, , " ", . . ,
.
, . , . , , ,
80 , . , . , , <Backspace>.
, LOG- "".
, PSP. , PSP, . ,
, 256 (100h) .
, 0 , . 00F6h ,
( ). , , , , .

III. , ,

232

LOG-?
, :
<Enter>;
, (: <F1>
<F10>, .);
80 , , ( ).
Store_sym ( 23.2).
23.2. Store_sym
...
; di :
(1)

mov di,cs:[0F6h]

; 79?
(2)

cmp di,79

;, . .
(3)

jb OK_store

(4)

push di

(5)

push ax

(6)

call Save_string

(7)

pop ax

(8)

pop di

(9)

OK_store:

(10)

stosb

; .

(11)

inc word ptr cs:[0F6h]

; .

(12) ret

; .

; ...

...

23.3.1.
,
(3). , (2), (3) ,
79, , di. ,
OK_store. , , . . , . je (
. jump if equal , ) ,
, jb ( . jump if below , ) ,
, , (. . ,
di 9). . 23.5,
23.3.

23. PSP DTA. ( DOS)

233

23.5.

JB (Jump if Below)

JBE (Jump if Below or Equal)

JNB (Jump if Not Below)

, ( JAE)

JA (Jump if Above)

JAE (Jump if Above or Equal)

JNA (Jump if Not Above)

, ( JBE)

23.3.
...
mov ax,34
cmp ax,35
...

:
JNE;
JAE;
JNA;
JB;
JBE.
:
JE;
JA;
JNB.

.

23.3.2.
( CF) : stc clc
(. 23.6 23.7).
23.6. stc

stc

Set carry flag

8086

III. , ,

234

, .
23.7. clc

clc

Clear carry flag

8086

? ?
. , ( 23.4).
23.4.
...
call Find_symbol
jc Not_found
...

- .
, ,
, . ,
- ( 23.5).
23.5.
...
call Find_symbol
cmp ax,1
je Not_found
...

ax=1, . , . , .
:
/
add, sub, mul .;
/ .
(. 23.8, 23.9).
23.8. std

std

Set destination flag

8086

23. PSP DTA. ( DOS)

235

23.9. cld

cld

Clear destination flag

8086

? ?

(lods, stos, movs .). ,
, 0 4000, 4000 0 ( ,
). , , . ,
( ). , , , , . ,
, "". , lods, stos .,
, "".
, ( 09) - ( , ). . , ,
, :
cld

; !

: , ,
.
, .

23.3.3. " "


, (. .
LOG- ). ,
LOG- ? 10h. , . ,
( 23.6).
23.6. 10h
...
(1) Int_10h_proc proc
(2)

cmp ax,0FAAFh

(3)

jne Next_step

(4)

xchg ah,al

; ?

III. , ,

236
(5)

iret

(6) Next_step:
(7)

cmp ax,0FBAFh

; LOG-?

(8)

jne Run_int

(9)

push cs

(10)

pop es

(11)

mov di,offset File_name

(12)

iret

; es LOG-
; di LOG-

(13) Run_int:
(14)

jmp dword ptr cs:[0F8h]

(15) Int_10h_proc endp


...

(2)(5) , 10h
, ah/al, , , , . ,
.
(6)(12). 10h 0FBAFh ax, , , ,
LOG-. ?
, LOG. , . , :
0FAAFh.

Resid23.com c:\newfile.txt

, ,
. ,
?
0FBAFh 10h, . , 10h ( ,
10h) es , di LOG- ( 23.7).
23.7.
...
mov ax,0FBAFh

; LOG-

int 10h

; es , di LOG- .

...

10h, , ax 0FBAFh, es:di LOG- . ,

23. PSP DTA. ( DOS)

237

,
, , LOG-.
!
23.8 10h
(Int_10h_proc).
23.8. 10h
...
cmp ax,0FBAFh

; LOG-

jne Run_int
push cs

; es LOG-

pop es
mov di,offset File_name

; di LOG-

iret
...

23.4.

, . . ,
, .
- .

24


!
, 20. ,
!

24.1.
80386/80486.
, 80386/80486. . 24.1
.
24.1. 386+

eax

32
ax

16
8

ah

ax
al

ah

al

, eax 32- .
65 535 65 535 (. . 65 535 ). 16 (ax, bx, cx .).
32-. ,
. 32- ,
.
eax.
, ebx, ecx, edx, edi, esi, ebp.
32- :
.386
.486

24.

239


.8086
.286

, 32- 80386.
, - (MASM/TASM), 386+.
(.386), - . , TASM 5.0 MASM 6.13 ( http://www.Kalashnikoff.ru).
32- :
mov eax,0

;eax=0, ax=0

mov eax,15h

;eax=15h, ax=15h

mov ax,0FF00h

;ax=0FF00h, eax=0FF00h

mov eax,12345678h

;eax=12345678h, ax=5678h

, .
:
...
(1)

mov Variable,12345678h

(2)

mov eax,Variable

(3)

mov ax,word ptr Variable

...
(4) Variable dd ?
...

(1) Variable 32- 12345678h.


, dd ( . double
word ) ( (4)). (2) eax ,
32- 12345678h. ,
. 12345678h , . . 78563412h. 32- "".
, 32- , ( (3)). ,
, (3) ax
5678h. , . .
.
, ax ( (3)).
Variable word ptr. , ax (). Word ptr , dw, 16- . 16- 32- ,
dd, word ptr .

240

III. , ,

24.1.1. 16- 32-


16-
AFD Pro 1.0, 808680286.
, 80386+,
.
, 80386+. , , CodeView,
MASM 6.13, TurboDebugger Borland Turbo Assembler
SoftIce, .
. 24.1 24.2 , AFD CodeView 32 . . 24.3 , 32 CodeView.

. 24.1. 32- CodeView

. 24.2. 32- AFD

24.

241

. 24.3. 32- CodeView

24.1.2. use16/use32
- : use16.
cseg segment use16

; 16-

use16 , 16 , .
, .386 , 32- (use32),
32- Windows. 16-
, 32-
. , , use16. , .386. .
use16, -
use32 (. . 32- ) :
mov dx,offset Message

( use16) :
mov edx,offset Message

24.1.3.

, ,
, ?
. ,
antivr24.asm display.asm , -

III. , ,

242

. ( ),
.
display.asm , , ,
. , , , . , . .
, #include stdio.h, include display.asm.
, stdio.h. , , , - .
.
, Hide_cursor
, , , .
,
. ,
! , , .

24.2. .
, Init, .
, 21h
int 99h, 21h- 99h-.
.
. " " , , . ,
20. . :
! , 20, .
, , PSP, ss:sp, , 21h ( 24.1).
24.1. PSP
...
(1)
(2)
(3)

cli
mov cs:[0],ss
mov cs:[2],sp

(4)

; PSP

;
;

24.
(5)
(6)
(7)
...

243

push cs
pop ss
mov sp,0FEh

, cli ( (1)).
, ss:sp
0 (. . PSP ) ( (2)(3)). , . . .
,
( 24.2).
24.2.
...
push ds
pop es
push cs
pop ds
...

, 4Bh ( )
3Dh ( ), ds , dx
. , ds es, ds
cs. es:dx. ,
dx. , , , ,
, , .
, ,
.
Check_prog, ,
/ COM- ( 24.3).
24.3. Check_prog
...
(1)
(2)
(3)
(4)

cld
mov di,dx
mov al,'.'
mov cx,65

(5) Next_sym:
(6)
repne scasb
(7)
jne No_com
...

; !
;
; 65

; es:di, .
; ?

III. , ,

244

scasb , es:di, , al. cx.


, dx / ,
es . , di dx
(es ) ( (2)). al (.), cx
65, . . 65 .
65? , DOS (. . + + + ) 65 .
, , scasb , di
, .
, .
, readme ( ). scasb
, , . , 65 , ,
com+ASCII0. ,
com, .
ASCII 0, ,
"com" "COM".
- .
, .
, . ,
. , ,
, + ASCII 0:

com+ASCII 0

COM+ASCII 0

, (. .
), , .
,
, "" (. . ASCII 0). , :
prog.cOm

prog.CoM

" ", COM-. . : .


ASCII, 3,
, , , , ,
. ,
.
24.4 , .

24.

245

24.4.
...
mov ebx,es:[di]

; ebx +0

cmp ebx,006D6F63h

; 'com'0 ?

je Got_file

;!

cmp ebx,004D4F43h

;, 'COM'0 ?

jne Next_sym

;!

...

, 32- ebx, . ,
, . , cmp , "com". :
, . . .
. , /
COM, . Check_file.
/
20 ( 24.5).
24.5.
...
push es

; ...

pop ds
push cs
pop es
mov cx,65

; 65 ...

mov si,dx
mov di,20

;... PSP, 20- .

rep movsb

; .

push cs

pop ds
...

19 ( Draw_frame). .
6 . , 2
1122h . ( 68h (. . push)) ( 24.6).

III. , ,

246

24.6.
...
mov bx,ax

; bx

mov Handle,ax
mov ah,3Fh
mov cx,6
mov dx,10
int 99h

; .

jc Not_infected

; !

mov ah,3Eh

; .

mov bx,Handle
int 99h
cmp byte ptr cs:[10],68h

; - 68h ( push)?

jne Not_infected

; - !

mov eax,dword ptr cs:[12]

; ...

and eax,0FFFFFF00h

;: ( ,
; )?
cmp eax,1122C300h
jne Not_infected

;! !

call Cure_file

; . ...

...


"" (. 24.6). Cure_file, . :
1. 64 . (
, - ),
, - 28 .
2. , es,
Bytes_read. Kill_zarazu,
.
, , , . . .
and,

24.

247

24.3.
, .
, .
,
. , , .

-, ,
.

25


25.1.
1. ?
(FPU, Floating Point Unit
) ,
, (
).
2. ?
(, , , , .) . ,
FPU. , , .
3. ?
. 80486DX, . ,
Pentium, .
4. ,
,
?
, . - .
5. ?
-, . .
6. ? , ?
.
7. ? .
-, , . .

25.

249

-, . ,
, .
-, , ,
.
8. ?
. ,
. , .
9. ? ,
, PRINT 25*4, .
, . , . .
.
10.
?
, - . ""
. , ...
11. ?
! . , , , , .
. . ,
, , , . ,
http://RFpro.ru. !

25.2.
, , , .8087 (.287,
.387). , .
, : 8086 (.8086),
8086 80286 (.286) . . 25.1 ,
- (MASM/TASM), .
25.1.
; ,
; 8086!
.386

250

III. , ,

; 386 , 8087,
; 80287 .
.287
...

TASM , . - : ": 386 287!"


! , , 486, 8087.
! .
8 ( 8 ) .
. .
.
: st(0), st(1), st(2), ...,
st(7). st(0) st.
mov . .
finit ( . FPU initialization ).
, f, . finit . , , , 8 st.
, , .
1680- . ,
st(0)st(7) . , 16- 64-.
st(0) . st(0) , , , , .
.
, fild ( . FPU integer load
st(0)), st(0)
( 25.2).
25.2.
...
FILD Number1
...
Number1 dw 10
...

25.

251

, , st(0) ( ). ,
, . st(0) 10. 3 ( ) ( 25.3).
25.3.
...
(1) FILD Number1
(2) FILD Number2
...
Number1 dw 10
Number2 dw 3
...

! (1) st(0)
10. (2) st(0) st(1),
st(0) 3. !
, st st(1),
FADD.
FADD

fadd ( . FPU addition


) , st(0) st(1), st(1) st(0).
,
(. 25.1). , .
25.1.

st(0)

st(1)

st(2)

...
st(7)

st fild Number1 (. 25.2).


25.2.

st(0)

10

st(1)

252

III. , ,

25.2 ()

st(2)

...
st(7)

fild Number2 (. 25.3).


25.3.

st(0)

st(1)

10

st(2)

...
st(7)

, . , st(0). - fild ...


fadd (. 25.4).
25.4. FADD

st(0)

13

st(1)

st(2)

...
st(7)

? , fild:
fist Result

fist ( . FPU integer store )


, st(0), Result.
, , .
, : AFD
, , : wait, esc . .

25.

253


:
WAIT
ESC

AFD,
. 25.1.

. 25.1.

, , TurboDebugger. , . . , . ,
TurboDebugger , : , , , .
TurboDebugger,
...
: , , st(0) 13! , finit, ? - ? ,
( ) Result
st(0)?
: , . , . .
,
.

254

III. , ,

, ,
: . , xchg ( .
exchange ). :
fild ( . integer load) ( );
fadd ( . addition) ;
fist ( . integer store) ( );
fistp ( . integer store and pop) st(0).
fist Result fistp Result
, st(0) . ,
. .
, .
. , , FPU- (
, ). , 23,8
24, 23 ( )
. , , , , ( ).
? , RC, . ...

25.3.

. 25.4 , Result. . , ,
TurboDebugger, ,
. -.
25.4.
.8087
; 8086 8087
CSEG SEGMENT
ASSUME CS:CSEG, DS:CSEG, ES:CSEG, SS:CSEG
ORG 100h

25.
Begin:
finit
fild Number1
fild Number2

255

;
;st(0)=
;st(1)=st(0); st(0)=

fadd

fist Result

; Result

ret
Number1 dw 10
Number2 dw 3
Result dw ?
CSEG ENDS
END Begin

25.4.

1234. , .
, , 3,
2 . . , and:
...
mov AX,1234
and AX,0004
...

; AND AX,0Fh

- . , 1234 .
:
...
mov ax,4D2h
and ax,4
...

ax? (and ax,0004) 0,


(and ax,0Fh) 2. ? , , .
, . ?
, ,
. :
1234/10=123
123/10=12
12/10=1
1/10=0

;
;
;
;

4
3
2
1

256

III. , ,

4321. 1234 . ,
.
"" ? , ,
1000, 100, 10, ... !
1000, 10.
. 2030 , . , , , (. . , 1234)
, .
10 ?
.
. ,
, .
, .
.
? , ,
.
TurboDebugger
.
, , ! . Windows SoftIce, ,
. ,
,
. , ,
.
, -
!Coproc!.asm,
.
, .
.

25.5.
? . , .

25.5.1.
714Eh 714Fh ( 4Eh 4Fh) 21h ( 25.5, . 25.2).

25.

257

25.5.
...
mov ax,714Eh

;di ,
; ( DTA).
xor di,di
; si .
xor si,si
; . -
mov cx,0FFh
mov dx,offset All_files

; (*.*)

int 21h
; es:di !
mov Handle,ax

...

. 25.2.

714Eh , ,
714Eh. (files.asm).
display.asm. , .
, - . : !

26


IBM- , .

26.1.
IBM-
.
. 26.1 IBM-
.
26.1. IBM PC

4,778

Mono,
CGA

-1840,
1841,
1851...

2060

616

CGA-VGA

-1849

48

40120

1640

EGA-VGA

-1863

SX/DX

412

80500

25120

EGA-VGA

Pentium I

MMX

16

300
1000

60266

VGA-sVGA

Pentium II

MMX

32

300500

sVGA

Pentium III

MMX SSE

64

10

6001000

sVGA

Pentium 4

MMX SSE

128

40

1000

sVGA

Intel Core
Duo, Core
2 Duo,
Core Quad

MMX
SSE I, II, III

512

80

1000

sVGA

(M)

8086/8088

256640

1020

80286

80386

SX/DX

80486

26.

259

. ,
: IBM 486 SX-25, 10 , 32 , MDA .

26.2.
1981 IBM PC (IBM
Personal Computer IBM). , , PCjr (Personal Computer junior), XT (Extended Technology), AT . .
80286 (PC/AT) "".
(,
, : push ), (protected mode). , , . . , 80386.
, .
, , .
80386 . . ,
,
, 4 . , Pentium , "",
(MMX,
SSE).
"" (80486) 386. ,
"", . , 32- (PCI), 32 , .
, 386- .
Pentium ( Pentium I, II, III) 64- .
, MMX SSE.
MMX
. , ,
, , ,
MP3- DVD- . .
SSE Pentium III. , .
( )
MMX SSE, Pentium MMX Pentium III
Pentium.
, Pentium II
MMX.

III. , ,

260

26.3.

< > < >


! , ,
. .

?
, ,
, , , ...
... , . . ""

<Ctrl>+<F3>! , Norton Commander! , , . ,
, ! . ,
, ,
. , ,
(. 26.1).

. 26.1.

:
;
.
.

26.

261

26.3.1.

.
1. . , , DOS,
,
200 .
12 : 8 + "" + 3 . 13 . 13?
, . . ,
, , + . : , , . , 64
5000 !
?
"" .
13 ... .
? , "" - . , !
2. , . 255 . ,
64 : 65 536/255 = 256. (64 ) 256 .
400 ...
, , (
), .
3. 300 ,
.
2 , +
+ 3 .
, , . ,
<> <>, <PageUP>, <PageDown>.
, .
.

. WORD.

III. , ,

262

26.3.2.

, /:
Assm.txt;
;
!.asm.
, (. 26.2
. 26.2). . ,
1234h, 0000h ( , 500!).

26.2.

1234:0000h

Assm.txt

1234:0000h

(1 )

1234:0001h

(2 )

1234:0003h

(2 )

1234:0005h

+ ASCII 0 (assm.txt (8 + ASCCI 0 = 9 ))

1234:000Dh

1234:000Dh

(1 )

1234:000Eh

(2 )

1234:0010h

(2 )

1234:0012h

+ ASCII 0 ( (13 + ASCII 0 = 14 ))

1234:001Fh

!.asm

1234:001Fh

!.asm (1 )

1234:0020h

(2 )

1234:0022h

(2 )

1234:0024h

+ ASCII 0 ( (13 + ASCII 0 = 14 ))

. , ,
, .

" "
< > , ,

0000h.

26.

263

, "", "" ,
.

. 26.2.

" " 0000h. < >, "",


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

27


27.1.
27.1.1. 21h
DOS,
.
: ?
, ,
:
-, ;
-, ;
, , , ,
.
. ,
-.
, . .
. , , , , ,
.
, , 21h. () DOS,
. 27.1.
27.1. 21h DOS

1234:0000h

DOS

( )

27.

265

, MS-DOS
(, 20h, 21h .). DOS
. , . ,
( , . . DOS) DOS, . . .
BIOS, . .
.
. 27.1. , 21h- MS-DOS 1234:0000h.
. ,
int 21h,
21h- MS-DOS, . . 1234:0000h. , , , ,
. .
, progA.com,
21h. ,
. 27.2.
27.2. 21h

1234:0000h

DOS

( )

2345:0000h

progA.com

1234:0000h ( DOS)

. 27.2 , progA.com 21h.


( MS-DOS (1234:0000h)).
int 21h 21h progA.com. 21h progA.com ( 2345:0000h),
, , DOS
1234:0000h. DOS ,
iret, , 21h.
. , , 21h. (int 21h) 3456:0100h. ,
int 21h 3456:0102h, . . , 21h
, . . 2345:0000h,
progA.com. , progA.com (, ,
- , )
DOS.

266

III. , ,

: , ?

, , ,
, . . .
progA.com .
() ( DOS, . . ), 35h 21h .
ProgA.com
21h.
DOS. . : ? , iret, . ? progA.com
, int 21h?
, progA.com, 21h, DOS.
,
() :
jmp dword ptr cs:[Int_21h_vect]
pushf
call dword ptr cs:[int_21h_vect]

iret DOS
, 21h int 21h.
: jmp . , jmp
(, , progA.com ). iret
21h DOS ,
, "" , progA.com ""
21h!
iret progA.com.
: call . iret ! call pushf ...
, 21h ( DOS)
progA.com .
progA.com? , 21h
, . iret
. , iret
,
int 21h.
progA.com int 21h?
. , / , /
, , 21h!
.

27.

267

, progA.com "" 21h, , . . DOS,


1234:0000h. int 21h progA.com, DOS.
progB.com,
21h. . 27.3 , .
27.3.

1234:0000h

DOS

( )

2345:0000h

progA.com

1234:0000h ( DOS)

3456:0000h

progB.com

2345:0000h (progA.com)

(, NC.EXE) int 21h. ?


int 21h ,
21h (3456:0000h) . progB.com , "", () 21h,
( 2345:0000h, . . progA.com). ProgA.com,
, , ,
DOS. ,
"" .

27.1.2.
?
Resid27.com .
. 27.4.
27.4.

1234:0000h

DOS

( )

2345:0000h

Resid27.com

1234:0000h ( DOS)

.
, Resid27.com?
DOS?
?
.

III. , ,

268

, "" ? , , .

21h. (mov ax,9988h/int 21h),
- ( 9999h).
, 9999h ax, , , :
,
21h ( DOS).
.
, , , , .
:
1. cli.
2. (. . DOS).
3. 49h.
4. sti.
! !

27.1.3. ,

. Resid27.com , 21h ( progA.com). , . 27.5.
27.5.

1234:0000h

DOS

( )

2345:0000h

Resid27.com

1234:0000h ( DOS)

3456:0000h

progA.com

2345:0000h (Resid27.com)

: , Resid27.com ?
, int 21h ,
3456:0000h, . . progA.com. , , 2345:0000h. ,
Resid27.com? "". , , .
: Resid27.com,
, 21h?
, .
, progA.com, Resid27.com.

27.

269

, . ""
.
,
, , 21h .
, Volcov Commander , . ,
Volcov Commander. , . :
push ax ( )
push bx ( )
push cx ( )

:
pop cx ( )
pop bx ( )
pop ax ( )

Volcov Commander ,

. ,
Volcov Commander
. , ,
. Volcov Commander
, ,
.

27.2.
?
test27.com, 50 "A". ,
.
1. Resid27.com (. 27.1).
2. test27.com.
3. Resid27.com /u (. . resid27.com /u).
4. test27.com.
5. Resid27.com.
6. Resid27_.com.
7. Resid27.com /u (. . resid27.com /u) (. 27.2).

270

III. , ,

. 27.1.

. 27.2.

, , -. !

28



, , . . ,
.
<PageUp>, <PageDown>, <Home>, <End>, <Insert> ( ), <Ctrl>+<F3>.

28.1.

.
.
( 28.1).
28.1.
...
(01) mov fs,Seg_offset

;fs

(02) xor di,di


(03) mov Current_offset,di
;
(04) mov fs:[di],di
(05) mov bp,2

; 2

...

fs (01), 286. .
es.
,
( 28.2 . 28.1).
28.2.
...
; . 4000 .
(01) mov ah,48h

III. , ,

272
(02) mov bx,250

;250 * 16 = 4000 = 2000

(03) int 21h


(04) mov Seg_offset,ax

; :
; . 64
(05) mov ah,48h
(06) mov bx,4096

;4096 * 16 = 65536

(07) int 21h


(08) mov Seg_files,ax

...

. 28.1.

, , ,
: main.asm other.asm. , , . 28.1.
. 28.1 , : Seg_offset (04)
Seg_files (08). ,
. 0FFFFh
.
28.1.

main.asm

other.asm

Seg_offset

0000h

0009h

0FFFFh

Seg_files

main.asm+ASCIZ

other.asm+ASCIZ

28.

273

28.2.
(2 ), Seg_offset
0000h. 0000h. ,
Seg_offset (. 28.2).
2 (. . ). 0009h.
(other.asm). .
2. . 0FFFFh? , . ! (. 28.3).

. 28.2.

. 28.3.

III. , ,

274

! , ,
. ? : 5 2 = 10. 2 , 2 . ,
Seg_files. .
+ ASCII 0,
(, ) .
/ .
, , . , . , ,
, . : , .

28.3.
, :
Current_file
Start_file
Out_fstat

Current_file , . .
, . .
Start_file ,
. 21 .
, ,
, "" . /
, /.
Start_file ,
.
, ""
, . ,
10h, . , . "".
Out_fstat ,
, . ? , .
, . 28.2.
28.2.
M

28.

275

, , main.asm
"" other.asm, :
main.asmm

, , "m". ,
( ) .
Out_fstat ,
, .
, ?
, , , .
, , . , ,
"" .
, <Insert> , , . . (. 28.4).

. 28.4.

.
(Out_files, files.asm), ,
Start_file ( 21 ). , , ,
, . . , . ( 1). , .
, <Insert>. 2, . ( -

III. , ,

276

) 2. 1 () Out_files. Out_files .
1, ( ), 2 (- ), ,
, . .
, ,
Out_files, .
"" , Out_files,
Out_fstat 0, Out_files ,
, . . ,
: , . .
, Out_files,
Out_fstat 1, .

28.4. <PageUp>
<PageDown>
< >
< > , .

28.5. <Home> <End>


Up_pressed Down_pressed ( < > < >) , .
28.3.
28.3. <Home> <End>
...
; === Home ASCII 49h ===
(01) K_Home proc
; , Up_pressed
; (Carry Flag)
(02) Next_khome:
(03)

call Up_pressed

(04)

jnc Next_khome

(05)

ret

(06) K_Home endp


; === End ASCII 49h ===
(07) K_end proc
(08) Next_kend:

28.
(09)

call Down_pressed

(10)

jnc Next_kend

(11)

ret

277

(12) K_End endp


...

, <Home> <End> ,
< > < > ,
.
, ,
. < > < >
, .

29


4Bh 21h.
. , , . .
, : 4bh1.asm, 4bh-2.asm test.asm. !
.

29.1.

, , :
.
"" , COM-.
.
EPB.
, .
.
, .
ss sp .
, 21h.
21h ()
, () .
, ()
. :
1. ss sp.
2. ( ., ).
3. .
, , .
1.
2.
3.
4.
5.
6.
7.
8.
9.

29.

279

29.1.1.

, . 29.1
. 29.1 .
29.1.
...
(1)

mov bx,offset Finish

(2)

shr bx,4

(3)

inc bx

(4)

mov ah,4Ah

(5)

int 21h

...

, Finish .

. 29.1.

?
, . , , - .
bx () .

III. , ,

280

4
?
, 4Ah ( )
bx 16 . bx ,
1 , 16, . . . bx
, ,
. , bx 16, 16 .
: bx 4 ,
bx 16.

bx (3)?
16 , .
bx ( 16 ),
.

29.1.2. PSP
29.2 . 29.2 .
29.2. PSP (0FFh)
...
(1)

mov sp,0FFh

...

. 29.2. PSP

, COM- , , . . 0FFFEh.

29.

281

Finish! , . .
, PSP. PSP , 256 , .

29.1.3. EPB
EPB (EXEC Parameter Block) . , , . 29.1.
29.1. EPB

()

00h

DOS

02h

06h

FCB

0Ah

FCB

0Eh

EPB

EPB , 29.3.
29.3. EPB
...
(1)

mov bx,offset EPB

(2)

mov C_F,cs

...

EPB ( 29.4).
29.4. EPB
...
; === Exec Parameter Block (EPB) 4Bh ===
EPB:
Env dw 0

; ( DOS)

C_O dw offset Comm_line

; + ...

C_F dw 0

;... +

dd 0

;FCB 1

dd 0

;FCB 2

Len dw $-EPB
...

; EPB

III. , ,

282

. 29.3. EPB

. 29.3 , . 29.1.

(
DOS)
, ( DOS). . , . .
.
( ),
( autoexec.bat).
:
C:\>set
CLIENTNAME=Console
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=MOSHOSTER
ComSpec=C:\WINDOWS\system32\cmd.exe
FARHOME=C:\Program Files\Far Manager
HOMEDRIVE=C:
LOGONSERVER=\\MOSHOSTER
NUMBER_OF_PROCESSORS=2
OS=Windows_NT
ProgramFiles=C:\Program Files
PROMPT=$P$G
SESSIONNAME=Console
windir=C:\WINDOWS

, SET
.

29.

283

, " DOS..." 0,
, , . .
.
( )
,
, EPB 0
( ). , ,
.

DOS?
... , , , , (PATH), (
, DOS 2Ch , ; ).
DOS (, PATH).
. , , . . 23. .
.
, 1 (), 2 ( + ). ,
DOS .


. ,
.
, ( ):
Comm_line db 5,' abc',0Dh

, EPB ( ), (. . 29.1.4):
...
; C_F
mov C_F,cs
...
;
; ( )
C_F dw 0
; (

III. , ,

284
; )
C_O dw offset Comm_line
...

,
Comm_line:
( 0Dh);
;
0Dh.

FCB
FCB, , , . ,
, FCB .

29.1.4.
29.5 . 29.4.
29.5.
...
(1)

pusha

(2)

push ds

(3)

push es

(4)

mov ss_Seg,ss

(5)

mov sp_Seg,sp

...

. 29.4.

29.

285

, ax, bx, cx, dx,


. ., , , ,
,
.
( (1)).
ds es , cs.
( 29.6).
si, di

29.6.

...
push cs
push cs
pop ds
pop es
...

, ( (2), (3)
29.5).
ss:sp. ,
. ,
: ss_Seg, sp_Seg. ...

29.1.5.
( 29.7, . 29.5).
29.7.
...
(1)

mov ah,4Bh

(2)

mov dx,offset File

(3)

mov al,0

(4)

int 21h

...

, 4Bh (1). dx
(2), .
0 4Bh 21h (3).
, .
1, ,
, 3, . 1 3

286

III. , ,

, .
.
(4) .
, .

. 29.5. test.com

29.2. " "


,
" ". , , . ,
( 29.8).
29.8.
...
mov ss,cs:ss_Seg
mov sp,cs:sp_Seg
...

: . . , ds, ss_Seg sp_Seg, cs, , , , .


, , pusha. ,
, ( 29.9, . 29.6).

29.

287

29.9.
...
pop es
pop ds
popa
...

. 29.6.

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

30


30.1. (XMS) .

XMS-. :
XMS- (XMSmem.asm);
c autoexec.bat XMS-,
(XMSblock.asm);
, XMS- (XMScopy.asm).
3 , . , (XMSmem,
XMSblock, XMScopy).
,
:
XMS- himem.sys
, A20,
, ;
(XMS) DOS
. . movs .
;
XMS- ,
. , AFD, CodeView, Turbo Debugger
. . . , -
, , ,
.
, Windows.
, MS-DOS.

30.

289

30.2. XMSmem.asm.
XMS-
30.2.1.
XMS-
, , XMS-
( ).
, , , ,
. DOS/Windows himem.sys.
"" DOS , (640 ). , -
, ( ).
, , himem.sys .
4300h 2Fh (. 30.1).
30.1. 4300h 2Fh:
himem.sys

ax = 4300h

al = 80h

. 30.1. himem.sys

, 30.1 (
-).

III. , ,

290

30.1. himem.sys
...
; himem.sys ...
mov ax,4300h
int 2Fh
cmp al,80h
je Himem_loaded

; al = 80h, himem.sys .

; , himem ...
...

,
. Prepare_XMS, , .
XMS- ( DOS int 21h), "
call" .
() XMS-
4310h 2Fh (. 30.2).
WinAPI.
30.2. 4310h 2Fh:
XMS-

ax = 4310h

es = , bx =

.
,
XMS- (,

):
call dword ptr XMS_Addr

30.2 , XMS- .
30.2. XMS-
...
mov ax,4310h
int 2Fh
mov word ptr XMS_Addr,bx
mov word ptr XMS_Addr+2,es

; XMS-

30.
mov ah,88h

291

; XMS-

call dword ptr XMS_Addr


mov dword ptr Number_dec,edx

...

. 30.2. XMS-

, ( !)
32- edx.
,
Windows NT/2000/XP. "" MS-DOS 5.00
. , XMS- ,
CMOS, . ,
, , . DOS XMS-,
SWAP- Windows ,
, , .
DOS/Windows.
,
Out_dec.

30.3. XMSblock.asm.


. .
,

III. , ,

292

09h XMS- (. 30.3).


dx
( 30.3).
30.3. XMS-
...
mov ah,9
mov dx,1024

; 1024 XMS-

call dword ptr XMS_Addr


or ax,ax

;?

jnz XMS_OK
...
XMS_OK:
mov XMS_id,dx

; id

...

(
. .), ax , .

. 30.3.

, dx
. , . : 3Dh 21h .

30.

293

30.3.1.
, XMS- DOS
. (640 ).
, . , 64 .
XMSblock.asm C:\autoexec.bat . ,
. , . , :
XMS- .

30.3.2.
XMS-
XMS- ( )
( 30.4). .
ds:si XMS-.
30.4.
...
;
XMS_str dd 0
;
XMS_src dw 0
; -
XMS_offsrc dd 0
;
XMS_rec dw 0
; -
XMS_offrec dd 0
...

.
XMS_str ( )
XMS .

294

III. , ,

() .
, ( )
. , XMS-, XMS (. 30.3 XMS_id).
XMS_offsrc ( ) - ( ) ( ).
XMS_rec () .
, ( ) . , XMS-, XMS (. 30.3 XMS_id).
XMS_offrec ( ) - ( ) ( ).
XMS-. XMSblock.asm .
XMS_src

30.4. XMScopy.asm.


:
,
XMS-, !
512 , ,
, 512 640 ;
C:\file.txt C:\filenew.txt. , file.txt C: ( , C:\file.txt). C:\filenew.txt
. , ,
.
.
.
:
1. C:\file.txt :
64 ;
;
, ,
;

30.

295

, . ,
.
2. , C:\filenew.txt:
64 ;
C:\filenew.txt;
;
, ...
, , DOS.
. ,
, -.
,
RFpro.ru.

31



31.1. Super Shell

.
. XMS- . 30. .
, , . .
.
, 21h (, ) (
) ( + = ).
/ .
:
1. , .
2. , ,
, ,
. . 6.
3. , (, , . .), , .
4. ( , . .), .
5. (. 1).
6. , ,
, ,
.

31.

297

:
XMS-;
;
;
COM, EXE BAT ;
;
.
, :
;
(DIR, COPY . .);
- (: prog.asm ml.exe prog.asm
/AT; readme.txt notepad.exe readme.txt . .);
.
, , Windows,
, MS-DOS, .
(, , ), "" , , .
, DOS . , Norton Commander
5.0.

31.1.1.
, . .
(, Hacker's View), .
( ) ,
, , <F3>/<F4>, .
. .
. , , ZIP, RAR . .,
.
, INI- ( ) .

III. , ,

298

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

31.1.2.
.
, , 64 128 (
), ,
() (. 31.1).
31.1. .
(64 )

(128 )

0001 0002 0003 0004 0005 FFFF

( ) ,
5 (""), ( ) , , ( ) 16-
. ""
, "" , "" . . (FFFFh) .
, ,
.
, "" ""
"". (. 31.2).
31.2.
(64 )

(128 )

0001 0002 0003 0006 0004 0005 FFFF

, :
"", "", "", "" . . ,
, . . BIOS ,
.
.
.

31.

299

- .
.
? , 32 . ( ) .

31.2.
31.2.1.

. , : 21h DOS, 1Ch ,
18,2 , 13h BIOS, 25h
26h DOS. , , , , .
, . .
: ,
?
. ,
movs . ,
0000:0000h 256 ( ) 4 ( + ) = 1024 . , 4Bh 21h .
, , Norton Commander,
. , , , . , - , , , ""
. , , .
:
,
;
, "" ,
.
, . ,
, / -

300

III. , ,

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

31.2.2.
-
, MSDOS 21h, BIOS 13h. 13h
, .
, . , . . . DiskEditor Norton.
, . . - . , . , .
, BIOS 13h DOS 25h
( ) / 26h ( ) , . 13h . , . ,
- ,
, , , ( , ).
. / ,

31.

301

, /
, .
, . :
/ ;
/ ;
/ .
,
. , 99% , .
, MSDOS 13h. BIOS.
,
.

32


32.1. ?
, .
. DiskEdit
Norton Commander (Norton Utilities). , .

32.1.1.
, , , , . ,
(. ). ,
, . ,
. , , ,
.
:
, , .
, , FDISK
( ) , .
( , D CD-ROM ), (, D, E , F CD-ROM . .).
, , . , , . . , , .
13h .

32.

303

, -
, :
. . : Norton Utilities, Nuts&Bolts
.;
.

( , . . );
. , DiskEdit Norton Commander DOS
Navigator.
,
,
.

32.1.2.
(BOOT-), 13h, 25h (
) / 26h ( ) DOS.
, ,
,
. , (,
, ),
, Hacker's View.
(. 32.1).
32.1.

00h

""

03h

0Bh

512, 128, 256, 1024

0Dh

0Eh

(FAT)

10h

(FAT) ,

11h

13h

III. , ,

304

32.1 ()

15h

0F8h, 3,5
CD-ROM 0F0h

16h

FAT

18h

( 13h)

1Ah

( 13h)

1h

( , 0)

24h

( 0)

26h

27h

2Bh

( )

36h

(FAT, FAT32, VFAT . .)

Boot- , , .
, FORMAT.COM , "Non-system disk or disk error" ( ),
( ).
, , Boot-,
.
ScanDisk,
Norton DiskDoctor .

32.1.3. (FAT)
(File Allocation Table,
FAT). , 100- .
, . ,
. 31.1.2.
,
. , , ,
. :
, ;
, , ;
.
, , , , ,

32.

305

, .
, , , , . FFF0h 16- FAT (FAT16)
FFFF:FFF0h 32- (FAT32).
,
.
, FAT, , .
, , FAT
, .
. , , .

32.2.
, , , , . ,
,
FAT. 0E5h.

. 0E5h, , ,
,
.
. , , , . ,
, FAT! . !
, , , . :
,
, , . . ( , SWAP-).
.
100- . , ,
, . .
: , . FAT ,
"", (, DiskEdit). .

306

III. , ,

32.3.
32.3.1.
FAT, FAT32
.
, ( - ),
. , , ( ) ( ).
,

.
, , - ( SmartDrv).
,
, FAT, .,
. ,
, . Reset,
.

DiskEdit. , , . ,
DiskEditor. FAT FAT32.


(
)
1.1. MASM 6.106.13
-.
Microsoft Macro Assembler 6.106.13,
MS-DOS,
Windows.1 ,
.
http://www.Kalashnikoff.ru
MASM.EXE ( 6 ).
.
MASM.EXE Windows ,
.
, MASM (,
. 2 ).
BIN .
ASM- , .

1.2.
- (MASM, TASM, WASM, NASM .)
OBJ. (ASM) (COM/EXE).
, . include
( ).
1

Microsoft (http://www.microsoft.com/downloads/en/default.aspx)
Microsoft Macro Assembler 8.0 (MASM) Package (x86). .

310

, ,
(. . , ), .
, ( ) ,
( OBJ), ,
() (. . 1.3).

1.3.

, - c ( OBJ).
(),
-.
.
() COM EXE (OBJ). . (COM) 64
MS-DOS ( Windows),
. ,
MS-DOS, EXE-. I
COM.
COM, EXE MS-DOS -
. , , .
, - ,
, . ,
, ( ).
,
( COM EXE), .

, ,
: . MASM 6.006.13
ml.exe, /AT
. MASM (
) (LINK.EXE),
COM.

1.

311

1.3.1.
Microsoft (MASM)
, PROG.ASM.
MASM 6.116.13,
:
> ML.EXE PROG.ASM /AT

: PROG.OBJ PROG.COM.
PROG.OBJ, , , ,
PROG.COM . . /AT - (MASM),
, , ,
(LINK.EXE)
COM.
!
/AT !



Tlink32.exe , :
Fatal: 16 bit segments not supported in module prog.asm

TASM32.EXE TLINK32.EXE
, Windows!
TASM.EXE TLINK.EXE
( MASM 6.116.13).
LINK :
LINK : warning L4021: no stack segment

EXE .
, EXE. COM, EXE,
COM-, COM-
.
EXE-, .
,
COM. COM-, 1.
(TASM) :
**Error** prog4.asm(15) Near jump or call to different CS

CSEG segment :
ASSUME CS:CSEG, DS:CSEG, ES:CSEG, SS:CSEG

: (
, : - .),
(--, ).
, , , COM-, ,
EXE. COM-, 1.


3.1. ASCII
. 3.1 ASCII- 00h 7Fh,
( DEC), ( HEX) ( BIN) .
- - ,
. - - (OR
10000000b).
- . . 3.4.
/ .
:
DOS
09h 02h 21h MS-DOS;

.

00h 7Fh ( 0 127).
3.1. ASCII- 00h 7Fh, ,

DEC

HEX

BIN

00

00000000

Null
DOS, : "" (ASCII 20h)

01

00000001

02

00000010

03

00000011

04

00000100

(<Ctrl>+<D>)

314

3.1 ()

DEC

HEX

BIN

05

00000101

06

00000110

07

00000111

DOS:

:

08

00001000

0Eh

<Backspace> (
)
DOS:
:

09

00001001

0Fh

<Tab>
DOS:
(
8 )
:

10

0A

00001010


DOS:
:

11

0B

00001011

12

0C

00001100

13

0D

00001101


DOS:

:

14

0E

00001110

15

0F

00001111

16

10

00010000

17

11

00010001

18

12

00010010

19

13

00010011

20

14

00010100

21

15

00010101

22

16

00010110

3.

315

3.1 ()

DEC

HEX

BIN

23

17

00010111

24

18

00011000

25

19

00011001

26

1A

00011010

27

1B

00011011

01h

<ESC>
DOS, :
( )

28

1C

00011100

29

1D

00011101

30

1E

00011110

31

1F

00011111

32

20

00100000

4Bh

<>

33

21

00100001

02h

"

34

22

00100010

28h

35

23

00100011

04h

36

24

00100100

05h

37

25

00100101

06h

&

38

26

00100110

08h

'

39

27

00100111

28h

40

28

00101000

0Ah

41

29

00101001

0Bh

42

2A

00101010

09h

43

2B

00101011

0Dh

44

2C

00101100

33h

45

2D

00101101

0Ch

46

2E

00101110

34h

47

2F

00101111

35h

48

30

00110000

0Bh

49

31

00110001

02h

50

32

00110010

03h

51

33

00110011

04h

52

34

00110100

05h

316

3.1 ()

DEC

HEX

BIN

53

35

00110101

06h

54

36

00110110

07h

55

37

00110111

08h

56

38

00111000

09h

57

39

00111001

0Ah

58

3A

00111010

27h

59

3B

00111011

27h

<

60

3C

00111100

33h

61

3D

00111101

0Dh

>

62

3E

00111110

34h

63

3F

00111111

35h

64

40

01000000

03h

65

41

01000001

1Eh

66

42

01000010

30h

67

43

01000011

2Eh

68

44

01000100

20h

69

45

01000101

12h

70

46

01000110

21h

71

47

01000111

22h

72

48

01001000

23h

73

49

01001001

17h

74

4A

01001010

24h

75

4B

01001011

25h

76

4C

01001100

26h

77

4D

01001101

32h

78

4E

01001110

31h

79

4F

01001111

18h

80

50

01010000

19h

81

51

01010001

10h

82

52

01010010

13h

83

53

01010011

1Fh

84

54

01010100

14h

3.

317

3.1 ()

DEC

HEX

BIN

85

55

01010101

16h

86

56

01010110

2Fh

87

57

01010111

11h

88

58

01011000

2Dh

89

59

01011001

15h

90

5A

01011010

2Ch

91

5B

01011011

1Ah

92

5C

01011100

2Bh

93

5D

01011101

1Bh

94

5E

01011110

07h

95

5F

01011111

0Ch

96

60

01100000

29h

97

61

01100001

1Eh

98

62

01100010

30h

99

63

01100011

3Eh

100

64

01100100

20h

101

65

01100101

12h

102

66

01100110

21h

103

67

01100111

22h

104

68

01101000

23h

105

69

01101001

17h

106

6A

01101010

24h

107

6B

01101011

25h

108

6C

01101100

26h

109

6D

01101101

32h

110

6E

01101110

31h

111

6F

01101111

18h

112

70

01110000

19h

113

71

01110001

10h

114

72

01110010

13h

115

73

01110011

1Fh

116

74

01110100

14h

318

3.1 ()

DEC

HEX

BIN

117

75

01110101

16h

118

76

01110110

2Fh

119

77

01110111

11h

120

78

01111000

2Dh

121

79

01111001

15h

122

7A

01111010

2Ch

123

7B

01111011

1Ah

124

7C

01111100

2Bh

125

7D

01111101

1Bh

126

7E

01111110

29h

127

7F

01111111

DOS, :

. 3.2 ASCII ( 80h FFh) IBM cp866


, .
DOS-
.
3.2. ASCII ( 80h FFh) IBM cp866 ,

DEC

HEX

BIN

DEC

HEX

BIN

128

80

10000000

192

C0

11000000

129

81

10000001

193

C1

11000001

130

82

10000010

194

C2

11000010

131

83

10000011

195

C3

11000011

132

84

10000100

196

C4

11000100

133

85

10000101

197

C5

11000101

134

86

10000110

198

C6

11000110

135

87

10000111

199

C7

11000111

136

88

10001000

200

C8

11001000

137

89

10001001

201

C9

11001001

138

8A

10001010

202

CA

11001010

139

8B

10001011

203

CB

11001011

3.

319

3.2 ()

DEC

HEX

BIN

DEC

HEX

BIN

140

8C

10001100

204

CC

11001100

141

8D

10001101

205

CD

11001101

142

8E

10001110

206

CE

11001110

143

8F

10001111

207

CF

11001111

144

90

10010000

208

D0

11010000

145

91

10010001

209

D1

11010001

146

92

10010010

210

D2

11010010

147

93

10010011

211

D3

11010011

148

94

10010100

212

D4

11010100

149

95

10010101

213

D5

11010101

150

96

10010110

214

D6

11010110

151

97

10010111

215

D7

11010111

152

98

10011000

216

D8

11011000

153

99

10011001

217

D9

11011001

154

9A

10011010

218

DA

11011010

155

9B

10011011

219

DB

11011011

156

9C

10011100

220

DC

11011100

157

9D

10011101

221

DD

11011101

158

9E

10011110

222

DE

11011110

159

9F

10011111

223

DF

11011111

160

A0

10100000

224

E0

11100000

161

A1

10100001

225

E1

11100001

162

A2

10100010

226

E2

11100010

163

A3

10100011

227

E3

11100011

164

A4

10100100

228

E4

11100100

165

A5

10100101

229

E5

11100101

166

A6

10100110

230

E6

11100110

167

A7

10100111

231

E7

11100111

168

A8

10101000

232

E8

11101000

169

A9

10101001

233

E9

11101001

170

AA

10101010

234

EA

11101010

320

3.2 ()

DEC

HEX

BIN

DEC

HEX

BIN

171

AB

10101011

235

EB

11101011

172

AC

10101100

236

EC

11101100

173

AD

10101101

237

ED

11101101

174

AE

10101110

238

EE

11101110

175

AF

10101111

239

EF

11101111

176

B0

10110000

240

F0

11110000

177

B1

10110001

241

F1

11110001

178

B2

10110010

242

F2

11110010

179

B3

10110011

243

F3

11110011

180

B4

10110100

244

F4

11110100

181

B5

10110101

245

F5

11110101

182

B6

10110110

246

F6

11110110

183

B7

10110111

247

F7

11110111

184

B8

10111000

248

F8

11111000

185

B9

10111001

249

F9

11111001

186

BA

10111010

250

FA

11111010

187

BB

10111011

251

FB

11111011

188

BC

10111100

252

FC

11111100

189

BD

10111101

253

FD

11111101

190

BE

10111110

254

FE

11111110

191

BF

10111111

255

FF

11111111

3.2. ASCII
ASCII . 3.3. ASCII ah 00h 16h,
al 0.

, * () ,
.

3.

321

3.3. ASCII

<F1>

3Bh

<Alt>+<F1>

68h

<Ctrl>+<F1>

5Eh

<Shift>+<F1>

54h

<F2>

3Ch

<Alt>+<F2>

69h

<Ctrl>+<F2>

5Fh

<Shift>+<F2>

55h

<F3>

3Dh

<Alt>+<F3>

6Ah

<Ctrl>+<F3>

60h

<Shift>+<F3>

56h

<F4>

3Eh

<Alt>+<F4>

6Bh

<Ctrl>+<F4>

61h

<Shift>+<F4>

57h

<F5>

3Fh

<Alt>+<F5>

6Ch

<Ctrl>+<F5>

62h

<Shift>+<F5>

58h

<F6>

40h

<Alt>+<F6>

6Dh

<Ctrl>+<F6>

63h

<Shift>+<F6>

59h

<F7>

41h

<Alt>+<F7>

6Eh

<Ctrl>+<F7>

64h

<Shift>+<F7>

5Ah

<F8>

42h

<Alt>+<F8>

6Fh

<Ctrl>+<F8>

65h

<Shift>+<F8>

5Bh

<F9>

43h

<Alt>+<F9>

70h

<Ctrl>+<F9>

66h

<Shift>+<F9>

5Ch

<F10>

44h

<Alt>+<F10>

71h

<Ctrl>+<F10>

67h

<Shift>+<F10>

5Dh

<F11>

85h

<Alt>+<F11>

8Bh

<Ctrl>+<F11>

89h

<Shift>+<F11>

87h

<F12>

86h

<Alt>+<F12>

8Ch

<Ctrl>+<F12>

8Ah

<Shift>+<F12>

88h

< >

4Bh

<Alt>+< >

9Bh

<Ctrl>+< >

73h

<Ins>

52h

< >

4Dh

<Alt>+< >

9Dh

<Ctrl>+< >

74h

<Alt>+<Ins>

A2h

< >

48h

<Alt>+< >

98h

<Ctrl>+< >

<Del>

53h

< >

50h

<Alt>+< >

A0h

<Ctrl>+< >

<Alt>+<Del>

A3h

<PageUp>

49h

<Alt>+<PgUp> 99h

<Ctrl>+<PgUp>

84h

<Alt>+<BS>

0Eh

<PageDown>

51h

<Alt>+<PgDn> A1h

<Ctrl>+<PgDn>

76h

<Alt>+<Tab>

A5h

<Home>

47h

<Alt>+<Home> 97h

<Ctrl>+<Home>

77h

<Ctrl>+<Tab>

94h

<End>

4Fh

<Alt>+<End>

<Ctrl>+<End>

75h

<Shift>+<Tab>

0Fh

9Fh

<Enter>

<Alt>+<A>

1Eh

<Alt>+<H>

23h

<Alt>+<O>

18h

<Alt>+<V>

2Fh

<Alt>+<B>

30h

<Alt>+<I>

17h

<Alt>+<P>

19h

<Alt>+<W>

11h

<Alt>+<C>

2Eh

<Alt>+<J>

24h

<Alt>+<Q>

10h

<Alt>+<X>

2Dh

<Alt>+<D>

20h

<Alt>+<K>

25h

<Alt>+<R>

13h

<Alt>+<Y>

15h

322

3.3 ()
<Enter>

<Alt>+<E>

12h

<Alt>+<L>

26h

<Alt>+<S>

1Fh

<Alt>+<Z>

2Ch

<Alt>+<F>

21h

<Alt>+<M>

32h

<Alt>+<T>

14h

<Alt>+<Enter>

1Ch

<Alt>+<G>

22h

<Alt>+<N>

31h

<Alt>+<U>

16h

*<Alt>+<Enter>*

A6h

<Alt>+<\>

2Bh

<Alt>+<[>

1Ah

* <Alt>+</> *

A4h

* <Ctrl>+</> *

95h

<Alt>+<,>

33h

<Alt>+<]>

1Bh

* <Alt>+<*>*

37h

* <Ctrl>+<*>*

96h

<Alt>+<.>

34h

<Alt>+<'>

28h

* <Alt>+<-> *

4Ah

* <Ctrl>+<+> *

90h

<Alt>+<;>

27h

<Alt>+<`>

29h

* <Alt>+<+> *

4Eh

* <Ctrl>+<-> *

8Eh

<Alt>+</>

35h

<Alt>+<=> 8Ch

* <Ctrl>+<.> *

93h

<SysRq>

72h

3.3. -
. 3.4 - . -
60h in.
- - (OR 10000000b). - .
15.
3.4. -

<Esc>

01h

16h

<Right Shift>

36h

<F6>

40h

1!

02h

17h

\|

2Bh

<F7>

41h

2@

03h

18h

2Ch

<F8>

42h

3#

04h

19h

2Dh

<F9>

43h

4$

05h

[{

1Ah

2Eh

<F10>

44h

5%

06h

]}

1Bh

2Fh

<F11>

57h

6^

07h

<Enter>

1Ch

30h

<F12>

58h

7&

08h

<Ctrl>

1Dh

31h

<Num Lock>

45h

8*

09h

1Eh

32h

<Scroll Lock>

46h

9(

0Ah

1Fh

,<

33h

<Home>

47h

0)

0Bh

20h

.>

34h

48h

3.

323

3.4 ()

-_

0Ch

21h

/?

35h

<PageUp>

49h

=+

0Dh

22h

***

37h

*-*

4Ah

BS

0Eh

23h

<Alt>

38h

*+*

4Eh

Tab

0Fh

24h

<Space>

39h

<End>

4Fh

10h

25h

<Caps Lock>

3Ah

<PageDown>

51h

11h

26h

<F1>

3Bh

<Insert>

52h

12h

;:

27h

<F2>

3Ch

<Delete>

53h

13h

'"

28h

<F3>

3Dh

<Left Win>

5Bh

14h

`~

29h

<F4>

3Eh

<Right Win>

5Ch

15h

<Left Shift>

2Ah

<F5>

3Fh

<Menu>

5Dh

-
-,
(. 4.1).
4.1. -

help

i80386, i80486

32- Intel

A
ASCII- 66, 71, 163
69, 76
ASCII- 32, 313, 318, 320
B, C, D
BOOT- 302, 303, 304
COM- 15
DTA 129, 130, 135, 136, 158, 159, 225,
226, 229, 231, 232
E
EPB 278, 281283
EXE- 15
F
FAT 304306
FCB 284
H
himem.sys 288290
M
MASM 47
Masm.exe 4
309
P, T, X
PSP 225, 226, 229, 231, 232
TASM 4, 47, 312
XMS- 109, 288295

97, 238, 242247,


299, 300
297, 298
4
309, 310
15

2325, 39
2325

149152

170172
142, 183, 184
25, 112, 113, 132, 139,
140, 144, 193, 194
113
CGA+ 112
VGA+ 112
113, 114, 132, 135,
139, 140, 162, 194
132
97, 98, 128, 129, 131, 132,
134, 136, 176182, 205211,
299, 300

4, 223

326

278287
302304
:
BAT- 297
COM- 297
EXE- 297
278287

115

:
297
260
283
13
310
, 139, 140

137, 138
, 142

109, 110, 111, 113


100103, 106
61
, 137, 142145
:
DOS 282, 283
MS-DOS 225229, 231, 232
:
$ 85, 86, 87
add 19, 22
and 160, 161
assume 47
call 49, 54, 55, 151
clc 233, 234
cld 234, 235
cli 59, 101

cmp 66
dec 21, 22, 45
div 143, 184
equ 190192
fadd 251, 252
fild 250252
fist 252, 253
inc 20, 22
int 31
iret 155157
JA 233
JAE 233
JB 233
JBE 233
jc 78, 79
je 68
jmp 44, 45, 69
JNA 233
JNB 233
jnc 78, 79
jz 67, 68
lods 118, 122, 124, 125
loop 42, 43
mov 13, 17
movs 132134
mul 146, 184
nop 61, 64, 65
offset 39
or 159, 160
org 27
pop 56, 58
popa 140
popf 104
push 56, 58
pusha 140
pushf 104
rep 118, 122, 124, 125
repe 195
ret 9496, 152, 153, 157, 185, 186
retf 153155, 157
scas 194, 195
shl 145
shr 145
stc 233, 234

std 234, 235


sti 59, 101
stos 118, 122, 124, 125
sub 19, 22, 125, 126
xchg 117
xor 125, 126, 161, 162
232
159
118, 122, 124, 125
233235
4, 15, 23, 31, 51, 53, 54, 63, 65,
106, 107, 165170, 172, 173, 240, 241

279
306
288295
:
25
25

26
:
44, 69, 232
44, 69
48, 49, 58, 99
32, 60, 99104, 107, 108,
115, 155, 264267
MS-DOS 13, 14, 224
148, 155158, 162,
163166
.

:
17
125, 126
13, 17, 238, 239
18, 27
250
284
67
- 18

327

99, 115, 200204, 230232,


235, 236, 299
115117
264269

26, 27, 40, 54, 59


23, 2629,
3133, 39
302304
:
23, 25, 313, 318
9, 25, 26, 313, 318
9, 14, 18, 24, 26,
313, 318
- 162, 163, 313, 322
26, 28, 39, 40, 59, 174179
248251, 253256, 289
51, 54, 55, 57, 65, 106, 185187,
189192
286, 287
:
198, 199
192
226, 227

196, 197

:
300
170172
302, 303
304306
4

:
297, 298
305
273277
87, 89, 260, 291, 292
( . . 328)

328

():
256, 257
81, 82
207210
296, 297
76, 77, 7981, 8487, 89
296, 297
296, 297
260
261263, 272
297299
296, 297, 305

87, 89
271, 272
291, 292
67, 104, 106
78, 79
104, 223
,
43, 46
42
43, 46
241, 242

Вам также может понравиться