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

( paging)

,
( ). (page),

(page frames).
( ) , 2,
. .
, - ,
, .
(p,d), p
, d p,
.
.
, .
, ,
.
.

, . ,
- , .
.1.
v = (p,d), p
, p', p' d.

. 1.
(page table)
. , ,
,
.
1

.
, .

. .
,
.

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

.
.
( ) . .
inc ; 1
push DS ;DS
xchg , ;
mov ES, ; ES

.
( ) ;
(, , ASCII),
.
mov , 40h ; 40h
mov AL,'*' ; ASCII "*' AL
int 21h ; 21h
limit = 528 ; 528 limit
mov CX,limit ;, limit,

( ).
( ). ,
. 86
, , SI DI. ,
SI DI - .
mov AX,0B800h ;

mov ES,AX ; ES
mov BX,2000 ;
mov byte ptr ES:[], ' ! ' ;

( ).
( ). ,
BX, BP, SI DI ,
. . , ,
BX, SI DI , DS,
, , SS.
mov AX,0B800h ;
mov ES,AX ; ES
mov DI, 80*2*24 ;
mov byte ptr ES: [DI] ,'' ;
mov byte ptr ES:2[DI],'' ;
mov byte ptr ES:4[DI],' ! ' ;

( . dump) :
1. ,
.
2. , ,
, , ,
.
3. , .
4. ,
. , ,
, .

- , .
( ws_BaseMemSize Slave).
, DebugKey
CoreDump. - ".whdl_memory".
- "PROGDIR: ", CoreDumpPath.
.
Fast , ".whdl_expmem".

( MMU), Cia Custom
Chips. Cia Custom
Snoop. ASCII
, ESC- ( CSI -
, 155). , , ESC, (, More, MuchMore, Multiview...). 3

".whdl_register", - "PROGDIR: "


CoreDumpPath. ,
- .
,
. , , .
.
.

ASCII .


, (
, DOS, , .),
, - ,
. ,
(Terminate and Stay Resident, TSR), .
., .,
,
..
, ,
() - ().
, - .

, ,
(, , )
DOS Int 21h 31h ,
.
( ) DOS DX.
, DOS.

ressize=$-main

main - , DX
(rcssLze+10Fh)/16.
S - main .
, 100h , .
, , ..
. 15 = Fh.
16
(, 15 ).
31h, ,
COMMAND., ,
, . , ,
, .
.
, , - ,
, . ,
.
, DOS
4

2Fh.
:

main
( ). jmp
, , ,
.
, .

.
, entry, ,
,
iret. . 2 .

. 2. .
.2., .
, ,
, end ( -
main). .
, .
5

,
(jmp init ).

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

code.
ASSUME , CS DS
.
ORG 100h 256 PSP. PSP ,
.
DS, , ,
.
,
. :
, , .
IP 100h, ORG 100h
.
, ,
jmp entry.
. .3.
, ..
PSP. FFFEh.
, , 64
, .

. 3. .

. .- .
,
byte
data segment byte

,
, - ,
- 16 .
. , .
. .
, PSP,
. ,
. 256 .
, ., .,
DOS CBI . ,
., /t
( TLINK.EXE):
tlink /x /v /3 /t p,p
, ,
- .,
.. , .
., .

256 PSP; DS;


. ,
, 16 17,
.
.- ( )
,
(, jmp, ).


8086/8088 14 ,
, . , , .
CS, DS, SS ES
CS - . ,
(IP), .
DS - .
, , .
SS - .
ES - .
DI. ES .
AX, BX, CX DX
.
, .
, - .
AX - , /,
.
BX - , ,
. , BX .
CX , .
DX - . /,
AX.
8 16- .
SP BP
.
SP - . .
SS.
BP - . ( ,
).
SI DI
,
.

SI - . ,
DS.
DI - . , SI.
ES.

(instruction pointer register) EIP/IP 32/16
.
,
. ,
,
, .
EIP/IP.
(FLAG REGISTER) EFLAGS/FLAGS 32/16 .
.
EFLAGS/FLAGS FLAGS i8086. . 1.2
EFLAGS.

, EFLAGS/FLAGS :
1.
:
o (carry flag) CF 1,
( )
. 7-, 15- 31-
; CF 0 .
.
o (parity flag) PF 1 8 (
8 )
9

; 0 8
.
o (auxiliary carry flag) AF
, BCD-.
: 1
3 3
; 0 (
) ;
o (zero flag) ZF 1 ; 0
.
o (sign flag) SF ( 7, 15
31 8-, 16- 32- ): 1
1; 0 0.
o (overflow flag) OF
: 1

( 7, 15 31 8-, 16- 32-
); .
2. DF (directory flag) EFLAGS. DF

: DF = 0 ,
; DF = 1 , .
DF CLD ( DF) STD (
DF).
3. IOPL -, ,
, 8086:
o (trace flag) TF
: 1 1
( );
0 .
o (interrupt enable flag) IF
() ( INTR):
1 ; 0
.
o - (input/output privilege level) IOPL

- .
o (nested task) NT
,
. CALL, IRET,
TR TSS.
o (resume flag) RF
.
o 8086 (virtual 8086 mode) VM
: 1
8086; 0 .
o (alignment check) AC
. AM
CR0. IA-32 ( i80486)
, . (
CPL = 3), ,
, 2 4.
o (virtual interrupt flag) VIF ( Pentium)
, V-,
IF. VIF VIP ( CR4.VME = 1).
10

(virtual interrupt pending flag) VIP (


Pentium) 1 .
i8086 VIF (
CR4.VME = 1). , .
(identification flag) ID ,
CPUID.
, ,
CPUID.

:
1) , ,
2)
3)
4)
5)
6)
7)
8)
, , ,
. ,
. , equ =.
num
imd
mov
mov
add
mov

equ 5
= num-2
al,num
al,5
[si],imd
al,5

;5
; imd=3 -
;5 -


: (. 4).
; ax 0000:0000
mov ax,ds:0000h

. 4.
, .
( )
( ).
11

,
.
.
data segment
mas_w dw 25 dup (0)

code segment

lea si,mas_w

;mas_w -

. $.
,
, .
, , , ,
.
( ,
).
, ,
.
. ,
,
,
.
jmp $+3 ; mov
cld
; cld 1
mov al,1

,
,
, . jmp 2
. , , .
,
. ,
.
.
.
mov al,4
mov dl,pass+4
dl
add al,dl

; 4 al
; pass+4
;

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


() .


.. (heap). ,
. 2 :
ALLOCATE FREE.
. ,
. ,
. , .
.
, ,
,
.. .
,
, , .

- , .

13


, .
:
;
CF.
:
rol ,_ (Rotate Left) .
, _.
.
ror ,_ (Rotate Right) .
, _.
.

. 5.
. 5
, :
, CF.
CF
, ,
CF. ( ,
)
(. . 5).
cf :
rcl ,_ (Rotate through Carry Left) .
, _.
CF .
rcr ,_ (Rotate through Carry Right) .
, _.
CF.

14

.6. cf
.6 , ,
, , , ,
.
,

.

. loop
:
JA.
.
: JA short-label .
: Jump if CF = 0 and ZF = 0 .
JA CMP SUB short-label,
( ) , (
). -128 127 .
JA, , .
JAE.
.
: JAE short-label .
: Jump if CF = 0.
JAE CMP SUB short-label,
. (
.) -128 127 .
JAE, , .
JB.
.
15

: JB short-label.
: Jump if CF = 1 .
JB CMP SUB short-label,
, . ( .)
-128 127 .
JB, , .
JBE.
.
: JBE short-label.
: Jump if CF = 1 or ZF = 1 .
JBE CMP SUB short-label,
. ( .)
-128 127 .
JBE, , .
JC.
.
: JC short-label.
: Jump if CF = 1 .
JC short-label, CF (.. =1).
-128 127 .
JCXZ. CX = 0
.
: JCXZ short-label .
: Jump if CX = 0 .
JCXZ short-label, CX 0.
-128 127 .
, ,
(CX) .
JE.
.
: JE short-label.
: Jump if ZF = 1.
JE CMP SUB short-label,
. -128 127
.
JG.
.
: JG short-label .
: Jump if ZF = 0 and SF = OF .
JG CMP SUB short-label,
, . ( .)
-128 127 .
JG, , .
JGE.
.
: JGE short-label .
: Jump if SF = OF .

16

JGE CMP SUB short-label,


. (
). -128 127 .
JGE, ,
.
JL.
.
: JL short-label.
: Jump if SF <> OF.
JL CMP SUB short-label,
, . ( .)
-128 127 .
JL, , .
JLE.
.
: JLE short-label .
: Jump if SF <> OF or ZF = 1 .
JLE CMP SUB short-label,
. (
). -128 127 .
JLE, ,
.
JNA.
.
: JNA short-label .
JNA - JBE.
JNAE.
.
: JNAE short-label .
JNAE - JB.
JNB.
.
: JNB short-label .
JNB - JAE.
JNBE.
.
: JNBE short-label .
JNBE - JA.
JNC.
.
: JNC short-label .
: Jump if CF = 0 .
JNC short-label, CF (.. =0).
-128 127 .
JNE.
.
: JNE short-label .
17

: Jump if ZF = 0
JNE CMP SUB short-label,
. -128 127
.
JNG.
.
: JNG short-label .
JNG - JLE.
JNGE.
.
JNGE short-label .
JNGE - JL.
JNL.
.
: JNL short-label .
JNL - JGE.
JNLE.
.
: JNLE short-label .
JNLE - JG.
JNO.
.
: JNO short-label .
: Jump if OF = 0 .
JNO short-label, OF (..
=0). -128 127 .
JNP.
.
: JNP short-label .
: Jump if PF = 0 .
JNP short-label, PF (.. =0).
-128 127 .
JNS.
.
: JNS short-label .
: Jump if SF = 0 .
JNS short-label, SF (.. =0).
-128 127 .
JNZ.
.
: JNZ short-label .
JNZ - JNE.
JO.
.
: JO short-label .
: Jump if OF = 1 .
18

JO short-label, OF (..
=1). -128 127 .
JP.
.
: JP short-label .
: Jump if PF = 1 .
JP short-label, PF (.. =1).
-128 127 .
JPE.
.
: JPE short-label .
JPE - JP.
JPO.
.
: JPO short-label .
JPO - JNP.
JS.
.
: JS short-label .
: Jump if SF = 1 .
JS short-label, SF (.. =1).
-128 127 .
JZ.
.
: JZ short-label .
JZ - JE.


LOOP.
.
LOOP short-label .
:
CX = CX - 1
if (CX <> 0)
JMP short-label .
LOOP CX 1, short-label, CX
0. short-label -128 +127 .
LOOPE.
.
: LOOPE short-label .
:
CX = CX - 1
if (CX <> 0) and (ZF = 1)
JMP short-label .
LOOPE CMP SUB. CX 1,
short-label, CX CMP SUB
19

. short-label
.

-128 +127

LOOPNE.
.
: LOOPNE short-label .
:
CX = CX - 1
if (CX <> 0) and (ZF = 0)
JMP short-label .
LOOPNE CMP SUB. CX 1,
short-label, CX CMP SUB
. short-label -128 +127
.
LOOPNZ.
.
: LOOPNZ short-label .
LOOPNZ - LOOPNE.
LOOPZ.
.
: LOOPZ short-label .
LOOPZ - LOOPE.

JMP.
.
. .
JMP 5 :
( -128+127 );
( );
( );
( );
( ).
,
, :
short
near ptr
far ptr
word ptr
dword ptr


,
: , ,
.
, ,
, ,
, , .
20

. ..
8 ,
,
.
, , ,
.
3 :
1) ( )
2)
3) .

, ,
.
, .
int ,
, .
- DOS BIOS.
:
00h - , 0;
0lh - , ( TF=1);
02h - ( NMI );
08h - ;
09h - ;
0Eh - ;
10h - , BIOS ;
13h - , BIOS ;
16h - , BIOS ;
IDh - , , BIOS;
lEh - , , BIOS;
21h - , DOS;
22h - , , DOS;
23h - , <Ctrl>/C, DOS;
25h - , ( DOS);
26h - , ( DOS);
60h...66h - ;
68h...6Fh - , ;
70h - ( );
76h - ;
int ,
( )
21

. ""
( AL).

.
80x86 ,
() , .
: .
: , , ,
.
INT ( INTO INT3) ,
( ). INT ,
, .
,
.
;
int_handler
proc
far
mov
ax,0
iret
int_handler
endp

, .
; old_handler
mov
ax,3587h
; = 35h, AL =
int
21h
; DOS:
;
mov
word ptr old_handler,bx
;
;
mov
word ptr old_handler+2,es ;
; ES,
;
mov
ax,2587h
; = 25h, AL =
mov
dx,seg int_handler
;
mov
ds,dx
; DS
mov
dx,offset int_handler
; DX
int
21h
; DOS:
;
; ( , ES 35h!)
[...]
;
lds
dx,old_handler ; DS DX

22

mov
int

ax,2587h
21h

; = 25h, AL =
;

INT 87h , 0 .



.
(
) ( 16- ).
,
, , () .
:
(1- );
16- EGA/VGA (4- );
256- SVGA (8- );
HiColor (16- );
TrueColor (24- / 32- ).
VGA (SVGA) ,
(. . 3.2 . 8.2.3).
, , ,
. ,
. VGA-
( 7- ),
B800h:0000h BF00h:0FFFh.
8 (4 ).
,
:
B800h:0000h 0, 0000h 0FFFh
B900h:0000h 1, 0000h 0FFFh

...........

BF00h:0000h 7, 0000h 0FFFh


, .
2 : ASCII-
. B800h:0000h
( ), B800h:0001h ; B800h:0002h
, B800h:0003h ..
, DOS BIOS, ASCII
.
.7.

.7. , 16 ,
4- . 4-6 .
23

7, ,
( 16 ),
( DOS ).
, . 1.
. , 8h
, , -
; 0Ch .
7 03h 10h int 10h.
1

0h
1h
2h
3h
4h
5h
6h
7h

8h

9h

0Ah

0Bh

0Ch

0Dh

0Eh

0Fh

,
: 80*2 , 80*2
..
, .
,
. , ,
() . "-"
(row, clm) :
VidAdd r= (row*160) + (clm*2)
,
, .
. 0-.
;

; ES 0 , ds
mov ax,0B800h
mov es,ax

; ,
; si, di cx
mov
mov
mov
cld
rep

si,offset msg
di,160*12+36*2
cx,msglen

;
; (36 13 - ),
;
;
movsb
; (*)
;
; ( ;
; DOS )
mov ah,01h
int 21h

; . : 0B0h c; , 0E4h
msg
db
*,0B0h,T,0E4h,E,0E4,S,0E4,T,0E4,*,0B0h

24

msglen = $-msg


. ,
, , ,
. ,
0E4h,
, "(*)", .
.

mov
mov
mov
cld
mov

si,offset msg
di,160*12+36*2
cx,msglen
ah,0E4h

cycle:
lodsb
stosw

;
; (36 13 - )
;
;
; 0E4h
;
; al (al ds:si)
; +
; (axes:di)
; msglen

loop cycle

; .
msg
db
*TEST*
msglen
=
$-msg


.
.
BIOS.
, ,
,
05h int 10h BIOS.
, DOS, 3,
0.

( 0Fh, int 10h) BIOS.
,
( "0" ):
05h;
02h;
BIOS DOS.

05h, int 10h.
"0"-.

.
ES.

05h, int 10h.

c BIOS
BIOS
int 10h.
25

int 10h :
- ( );
- ;
- , ,
.
BIOS ,

.
BIOS [10, 12] ,
.
int 10h.
00h. (. 2) (
06h 07h).
:
AH = 00h,
Al = ( 7 , 1
).
AX, BP, SI, DI.
2
VGA,

0
text
40x25
16
9x16
B8000
07

1
text
40x25
16/8
9x16
B8000
07
2
text
80x25
16
9x16
B8000
07

3
text
80x25
16/8
9x16
B8000
07
6
graphic 640x200 / 80x25 2
8x8
B8000
0
7
text
80x25
3 (Mono)
9x16
B0000
0
10h
graphic 640x350 / 80x25 4 16
8x14
A0000
01
11h
graphic 640x480 / 80x30 2 (Mono)
8x16
A0000
0
12h
graphic 640x480 / 80x30 16
8x16
A0000
0
13h
graphic 640x480 / 80x30 256
8x8
A0000
0
DOS 3 (,

).
02h. .
,
. .
, , ,
. BIOS (.
. 3.2) , . 02h BIOS
DOS .
:
AH = 02h;
26

BH = (0,1,...7), 0;
DH = ;
DL = .
AX, BP, SI DI.

03h. .
.
, . 03h
BIOS DOS .
:
AH = 03h,
BH = (0,1,...7), 0.
:
DH, DL = ,
CH, CL = .
AX, BP, SI DI.
05h. .
( , ).
:
AH= 05h,
AL= (0,...,7).
AX, BP, SI DI.
, , ,
.
06h (07h). ().
, ASCII (AL = 0),
() (AL = ).
() ASCII .
.
:
AH = 06h(07h);
AL = 0 , AL = N (N >0) N ;
BH = ;
CH, CL = (Y,X) ;
DH, DL = (Y,X) .
AX, BP, SI, DI.
08h. .
:
AH = 08h,
BH = (0,...,7), 0.
:
AH = ,
AL = ASCII- .
BP, SI DI.
09h. .
, .
. AL
. 02h.
.
BL . BL ,
. .
:
27

AH =09h,
AL = ASCII- ,
BL = ( ) ( ),
BH = (0,1,...7), CX = .
AX, BP, SI DI.
0Ah. .
, . ,
. ASCII- AL
( 09h).
02h.
:
AH = 0Ah,
AL = ASCII- ,
BH = (0,1,...7),
CX = .
AX, BP, SI DI.
0Eh. .
ASCII ( 02h)
. ASCII: 07h (BEL), 08h
(BS), 0Dh (CR), 0Ah (LF),
.
.
, 1
.
:
AH = 0Eh,
AL = ASCII- ,
BL = ( ),
BH = (0,1,...7), .
0Fh. .
:
AH = 0Fh.
:
AL = ,
AH =
BH = .
BP, SI DI.
10h. 03h. "/".
7 :
.
:
AX = 1003h,
BL = 7- :
0 ,
1 ( ).
, .
13h. .
, . ASCII: 07h
, 08h , 0Ah ,
0Dh , , .
28

:
AH = 13h,
AL = :
0 BL, ,
(.. ,
, );
1 0 , ;
2 (..
2 ASCII- ),
;
3 2 , .
BH = (0,1,...7),
BL = 0 1,
CX = ( , ),
DX = DH.
DL = (, ) ,
ES:BP = .
int 16h
00h (10h). .
-.
AX. , .
-, .
BIOS
Int 09h. 00h ,
. ASCII-, :
AL ASCII- ,
AH - .
ASCII-, :
AL 00h,
AH ASCII-.
:
AH = 00h (83/84-key).
:
AL = ASCII- , /00h,
AH = -/ ASCII- .
10h (AH = 10) 00h
(101/102-key).
ASCII- F11, F12, .
, 00h,
0Ah, 0Dh E0h.
01h (11h). .
, ;
. -
00h Int 16h.
: , .
:
AH = 01h (83/84-key),
11h(101/102-key).
:
ZF = 1, ZF = 0, .
:
AL = ASCII- /00h,
29

AH = - / ASCII-.
11h (AH = 11h) 01h
(101/102-key). ASCII- F11, F12,
. ,
00h, 0Ah, 0Dh E0h.
02h (12h). .
, ,
() BIOS 0000h:0417h.
:
AH = 02h
:
A L=1- .
:
0: 1 Shift
1: 1 Shift
2: 1 Ctrl ()
3: 1 Alt ()
4: 1 Scroll Lock
5: 1 Num Lock
6: 1 Caps Lock
7: 1 Insert
12h (AH = 12h) 02h
(101/102-key). , 02h, 0000h:0417h, ,
, ( 0000h:0418h) :
0: 1 Ctrl
4: 1 Scroll Lock
1: 1 Alt
5: 1 Num Lock
2: 1 Ctrl
6: 1 Caps Lock
3: 1 Alt
7: 1 SysReg
Int 15h:
86h .
Int 1Ah:
00h .

DOS
DOS :
- Int 21h (02h, 06h, 09h),
;
- , , 40h.
02h. .
, DL, ,
. .
. <Ctrl/C>
64- . ASCII- 07h, 08h, 09h,
0Ah, 0Dh. 07h (bell, ) , 08h (backspace, )
, 09h (tab, )
, 8. 0Ah 0Dh
.
:
AH = 02h, Int 21h.
30

:
DL = ASCII ,
AL = ( , DL = 09,
20h).
.
09h. .
(
). $ (
24h), , .
. (07h, 08h, 09h, 0Ah, 0Dh),
(. 02h). Exc. <Ctrl/C>
64- .
40h. .

, BX. 1,
, . CX
, , DS:DX
. 08h, 0Ah, 0Dh
. CF = 0 AX
, CF =1 .
3Fh, 5 6. .
DOS :
. , DOS
.

31