-
-
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 100
1/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
V
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. .................................................................. 276 28.5. ............................................................................... 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
/ ;
,
;
2
, ;
;
, 10,
:
;
;
( Norton Commander, FAR Manager . .) -
XMS-;
(, -
).
, ,
. -, , -
-
, . -
, .
- ,
http://www.Kalashnikoff.ru (
).
.
.
(-), .
.
,
, , , -
, , -.
, !
, . -
II III.
! ,
, ( -
, , , .).
, , , -
, -
http://RFpro.ru.
,
.
3
1. ( MS-DOS)
-
( Windows)?
-, -
. .
, .
-, WinAPI, ,
MS-DOS. WinAPI
, Win-
dows. , -
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 | .
,
, COM- MS-DOS.
Microsoft IBM- :
Windows 2000 Pro Server;
Windows XP Home Edition Pro;
Windows Vista/Server 2008/7.
4
! , Windows. . ? : !
3. , , ?
, , , , Akelpad, - (, Far Manager). ,
, . . -
. Far Manager
(). , ,
, , .
, . 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. , ,
, . , -
, , , -
5
, . ,
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.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.
0 0 26 1A
1 1 27 1B
2 2 28 1C
3 3 29 1D
4 4 30 1E
... ... ... ...
8 8 158 9E
I. : 10
1.1 ()
9 9 159 9F
10 A 160 A0
11 B 161 A1
12 C 162 A2
13 D ... ...
14 E 254 FE
15 F 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 ; ,
I. : 14
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) mov ah,9
(10) mov dx,offset Mess2
(11) int 21h
(12) int 20h
(13) Message db 'Hello, world!$'
(14) Mess2 db ' !$'
(15) CSEG ends
(16) 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
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 bx cx dx
ah al bh bl ch 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 ax,1234h
mov bx,5678h
mov cx,9ABCh
mov dx,0DEF0h
ax = 1234h, ah = 12h, al = 34h
bx = 5678h, bh = 56h, bl = 78h
cx = 9ABCh, ch = 9Ah, cl = 0BCh
dx = 0DEF0h, dh = 0DEh, dl = 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 ,
. .
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 1 0 1 1 0 1 0
"" "" "" "" -.
.
, , "", -
. , 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 + 2
2 + 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) :
CSEG ( ) segment ( , ,
CSEG );
CSEG ends (END Segment ) .
(02) , ,
100h. COM.
3.1 AFD Pro. ,
1DF1h (. 3.1). (04)
:
1DF1h:0100h (. . cs = 1DF1h, ip = 0100h)
cs ip!
. AFD
, CodeView , , ;
- + +. , -
(. 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
( /) 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 2 3 4
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 " ".
!
I I
4
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 ( ).
II. 40
. , 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. 45
(03) int 21h
(04) jmp Label_2
(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) CSEG segment
(02) org 100h
(03) Begin:
(04) mov ax,0B800h
(05) mov es,ax
(06) mov di,0
(07) mov al,1
(08) mov ah,31
(09) mov cx,2000
(10)
(11) Next_face:
(12) mov es:[di],ax
(13) add di,2
(14) loop Next_face
(15)
(16) mov ah,10h
(17) int 16h
(18) int 20h
(19) CSEG ends
(20) 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
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) mov dx,offset Mess1
(02) call Out_string
(03) call Wait_key
(04) mov dx,offset Mess2
(05) call Out_string
(06) 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
:
Out_string ;
proc (procedure) ;
endp (end procedure) .
, . -
. ,
, ""!
.
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
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 ,
AFD . sp ! 2.
int 20h. , -
call Our_proc,
. 103 (. 6.2).
/. 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
sti. (Pentium) -
, . . .
, ,
"";
ss:sp .
, ;
, . ,
COM- , ss ,
, sp = 0FFFEh. 100h (org 100h).
. , ,
2000h , sp 2200h. 100h
( ) (. .
100h (org 100h), 2000h 100h). , , -
. (, 100h
), . !
6.4 .
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
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) ,
. : cmp al,'Y'
ASCII- . -
.
MASM/TASM . -
, , cmp al,'Y'
cmp al,59h
7. 67
! , cmp
al,59h. .
, , ,
, ( 7.3).
7.3.
...
mov al,'2'
mov dh,'d'
...
al 32h, dh 64h. !
(04) Yes_key (05), -
. 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)
, , , . -
, , :
cmp al,'F1'
, 'F1' 2 ,
al 1 .
ASCII. ,
, al 0, ah .
. 7.2 ASCII-
.
II. 70
7.2. ASCII
ASCII
, ..., 3Bh, ..., 44h
+, ..., + 68h, ..., 71h
+, ..., + 54h, ..., 5Dh
+, ..., + 5Eh, ..., 67h
, 3Bh, 3Ch, 3Dh
. .
7.8 , -
+ (
, , ).
7.8. ASCII
...
(01) No_ext:
(02) mov ah,10h
(03) int 16h
(04) cmp al,0
(05) jnz No_ext
(06) cmp ah,57h
(07) je Shift_f4
(08) jmp No_ext
(09) Shift_f4:
...
, , + . . al
0, ah . (04)(07) -
. (05) No_ext, ,
(: , , , . .).
"" -
. (06) ,
+. +, , -
, Shift_f4 (09) ( Shift_f4, -
, -). -
, , -
No_ext (08).
7. 71
, , -
+.
. 7.3 , -
, . . 10h 16h al.
7.3.
0Dh (13)
1Bh (27)
() 20h (32)
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.
, , . ? , ? , ! , ! , ? . :
, , ( 50200 320 ++);
;
, . :
;
() , ;
- . , (-, , .), - . , , , , . : . - Windows. , Windows. Win32 - . DOS - , Windows - . : , , , , , , - , , - ? , .
, , - , - .
, -, . . .
, , . , , . - .
, - . , .
-.
8
8.1.
, 7 . ,
, -
. - -
, . :
20h 32, ;
100h 256, ;
1Bh 27, ;
21h 33, MS-DOS
. .
( 8.1).
8.1. 7
...
(01) call Wait_key ; ...
(02) cmp al,27 ; ?
; Quit_prog (quit , prog (program) )
(03) je Quit_prog
(04) cmp al,0 ; ? (- . .)
(05) je Begin ; ...
;
(06) call Out_char
(07) jmp Begin ; ...
;,
(08) Quit_prog:
(09) mov al,32 ; al
; al ( ).
; "" Out_char,
; .
8. 75
; .
(10) call Out_char
(11) int 20h ; DOS...
(12) ...
(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
...
II. 76
(12) -
. , :
;
ASCII (, ), -
;
ASCII (, . .) -
;
(27 1Bh),
(mov al,32) .
8.2.
MS-DOS
.
, .
3Dh 21h (. 8.1).
8.1. 3Dh 21h
ah = 3Dh
al = (00 , 01
, 02 , )
ds:dx = ASCII-
ax =
jc
, 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
File_name db 'command.com' . , -
, .
'command.com' , . , -
, (. 8.1). mov dx,0106h (mov
dx,offset File_name) File_name
"command.com". dx ,
aprl, insw . ., , ,
"" .
, " " .
, .
, -
, .
.
, :
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
cx , ds:dx
/. 40h -
. 8.3.
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 Handle,ax
mov bx,ax
mov ah,3Fh
mov cx,0FDE8h
mov dx,offset Buffer
int 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
9.1.
9.1 8 .
9.1. 8
...
; CSEG .
(01) Begin: mov ax,3D00h ;
; , ( ).
(02) mov dx,offset File_name ;ds:dx
(03) int 21h ;
(04) jc Error_file
; ( , ,
; ), Error_file
; Handle.
; , bx ,
; , ax.
; ( , ax) ,
; (). ax, .
; mov bx,Handle .
(05) mov Handle,ax ; Handle
(06) mov bx,ax
(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 ; 2
(21) Mess_ok 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.
I I I
,
,
10
.
10.1.
9 (