Title: ??????: ?????????, ??????? ??????????, ?????? ?????????? ????????????, ?????????
1????????? ??????????? ???????????
- ?????? ?????????, ??????? ??????????, ??????
?????????? ????????????, ????????? ??? Windows - ???????? ?????????? ? ???????????? ???????
- ???. ?????? 4 ?? ???????????? ??????????
- ????? (????????????) ?? ???. ???????
- ???????
- ??? ??????? ? ?????? ?? ??????????
21 ???????? ??????????????? ????? ???????????????
i8086
3????????
- a) ?????? ???????? ?????? ?????????? (????????
??????) - AX - ???????-???????????,
- BX - ??????? ???????,
- ?? - ???????,
- DX - ???????-??????????? ????????????
- ?) ??? ???????? ????????
- SI - ??????? ??????? ?????????,
- DI - ??????? ??????? ??????????,
- BP - ???????-????????? ????
- ?) ??? ??????????? ????????
- SP - ???????-????????? ?????,
- IP - ???????-??????? ??????,
- PSW - ??????? ?????? (????? ?????????
?????????) - ?) ?????? ?????????? ????????
- CS - ??????? ???????? ?????,
- DS - ??????? ???????? ??????,
- ES - ??????? ??????????????? ???????? ??????,
- SS - ??????? ???????? ?????.
4??????????? ???????? ??????
0 1 2 3 4 5 6 7
????? ????
????????
????? ????????? ???? ???????? A A? ???
?????????? ????? ????????? ??????????????? i8086
5????? ?????????
?????????????? ?????
??
??????
SI, DI
????
????????
BX, BP
Disp
?????????????? ????? (16)
????????? (32)
???? ?????????????? ???????
?????????? ????? (20)
?????????? ????? (16)
?????????? ??????? SS
?????????? ??????? ES
?????????? ??????? DS
?????????? ??????? CS
6????????? ?????????
- 1. ??????? ????
- CS IP
- 2. ???????? ??????
- BX DI lt????????gt
- BX SI lt????????gt
- BP DI lt????????gt
- DS BP SI lt????????gt
- ES BX lt????????gt
- BP lt????????gt
- SI lt????????gt
- DI lt????????gt
- 3. ??????? ?????
- SSSP
7????? ????????? ????????? (PSW)
? - ???? ???????????? D - ???? ??????????? I -
???? ?????????? ? - ???? ??????????? S - ????
????? 1 - ????? lt 0, 0 - ????? gt 0 Z - ????
???? 1 - ????? 0 ? - ???? ???????? ??
??????? P - ???? ???????? ? - ????
?????/????????.
8??????? ???????? ??????
????????
??? ????????
1 ???? ?????????
2 ????? ????????
2 ????? ??????
?/???????? 100010DW Mod Reg R/M ??.??.???? ??. ??.????
???????? ?/?????? 1100011W Mod 000 R/M ??.??.???? ??. ??.???? ??????
D - 1- ? ???????, 0 - ?? ???????? W - 1-
????????-?????, 0 - ?????
W1 W0
Sr Reg 000 AX 000 AL 00 ES 001 CX 001
CL 01 CS 010 DX 010 DL 10 SS 011
BX 011 BL 11 DS 100 SP 100 AH 101
BP 101 CH 110 SI 110 DH 111 DI
111 BH
Mod - 00 - Disp0 ???? 01 - Disp1
???? 10 - Disp2 ????? 11 -
????????-????????
M 000 EA(BX)(SI) Disp 001
EA(BX)(DI) Disp 010 EA(BP)(SI)
Disp 011 EA(BP)(DI) Disp 100
EA( SI) Disp 101 EA(DI) Disp
110 EA( BP) Disp 111 EA(BX) Disp
9??????? ???????? ??????
- ???????
- 1) mov BX,CX
- 100010DW Mod Reg R/M
- 10001001 11 001 011
- 2) mov CX, 6BX
- 100010DW Mod Reg R/M ??.??.????
- 10001011 01 001 111 00000110
- 3) mov byte ptr 6BX, 10
- 1100011W Mod 000 R/M ??.??.???? ??????
- 11000110 01 000 111 00000110 00001010
8 9
C B
8 B
4 F
0 6
C 6
4 7
0 6
0 A
10?????????
- ??????????? ?????????? ?????? ??????? ?????
- ??????? ??? ??????????, ?????????????? ?????
????????????? ??????? ???????? ??????. ?
???????? ?????????? ?????????? ??????????
????????????? ? ??????????????? ??????? ???????
?????? ??????????????? - ???????????? ??????????? ???????????? ???????
??????????? ?????? ?????????, ?????????? ?? ?????
?????????? ??????? ????????????? - ?????????, ?????????? ????????? ???????????
?????????? ?? ?????????? ????????? ????????. ?
???????? ??? ???????? ? ???????? ????????????? - ?????? ????????????, ?????????? ????? ???????, ?
??? ????? ? ????? ???????? ????????. ???????????
???????????? ????????????.
11?????? ??????? ??????????
- lt?????gt lt??? ???????? gt lt???c?? ????????? gt
-
lt???????????gt - ???????
- 1) m1 mov AX,BX ????????? ?????
- 2) cbw
- 3) ????? ?? ???????
12 ??????????? ????? ?????? ??? ?????????? ??????
- DB lt?????gt ???
(lt?????? ?????gt) ??? ? - lt??? ????gt DW lt ?????????? gt DUP ( lt??????
????? gt ) - DD lt ?????????? gt
DUP ( ? ) - ???????
- a db 12
- db ?
- dw 1234H
- db 5 dup (?)
- b db 'A'
- s dw 4,-1
- k db 00001100b
a
0 C
?
3 4
1 2
?
?
?
?
?
b
6 1
s
0 4
0 0
F F
F F
k
0 C
13???????? ?????? ??????????
- 1. ???????? ?????? ?????????? ????? ???????????
- ?) ? ?????????
- ?) ? ??????? ????????
- ?) ? ??????.
- ???????
- 1) mov AX,10
- 2) mov AX, 6BXDI
- 2. ????? ???????? ????????????
- ?) ????? ???????
- ?) ?????????
- ?) ???? byte ptr, word ptr, dword ptr
- ??????
- mov 0BX,10
? mov word ptr 0BX,10
14??????? ????????? / ?????????????? ??????
- 1. ??????? ????????? ??????
- MOV lt????? ?????????gt,lt ????? ?????????gt
- ???????
- ?) mov AX, BX
- ?) mov SI, 1000
- ?) mov 0DI, AL
- ?) mov AX, code
- mov DS, AX
???????
AX,BX,CX,DX, SI, DI. SP, BP
??????????? ??????
?????????? ????????
15??????? ????????? / ?????????????? ?????? (2)
- 2. ??????? ?????? ??????
- ?CHG lt??????? 1gt , lt??????? 2gt
- ???????
- ?) xchg BX, CX
- ?) xchg BX, 0DI
- 3. ??????? ???????? ??????????????? ??????
- LEA lt???????gt , lt??????? 2gt
- ??????
- ?) lea BX, exword
- ?) lea DI, 6BX,SI
????? ????????
????????
exword
16??????? ????????? / ?????????????? ?????? (3)
- 4-5. ??????? ???????? ?????????
- LDS lt???????gt ,lt??????? 2gt
- L?S lt??????? gt ,lt??????? 2gt
- ??????
- lds SI, exword
- 6-7. ??????? ?????? ????? ? ???? ? ?????????? ??
????? - PUSH lt???????gt
- POP lt???????gt
- ???????
- push SI
- pop 0BX
17??????? ????????? / ?????????????? ?????? (4)
- 8-9. ??????? ????????
- ADD lt??????? 1gt, lt??????? 2gt
- ADC lt??????? 1gt, lt??????? 2gt
- ??????. ???????? 32-????????? ?????
- mov AX,value1
- add AX,value2
- mov res,AX
- mov AX,value12
- adc AX,value22
- mov res2,AX
- 10-11. ??????? ?????????
- SUB lt??????? 1gt, lt??????? 2gt
- SBB lt??????? 1gt, lt??????? 2gt
??.????
??.????
18??????? ????????? / ?????????????? ?????? (5)
- 12. ??????? ?????????
- ??P lt??????? 1gt , lt??????? 2gt
- ???????
- ?) cmp AX,5
- ?) cmp byte ptr 0BX,A
- 13-14. ??????? ??????????/????????? ???????
- INC lt???????gt
- DEC lt???????gt
- ???????
- inc AX
- dec byte ptr 8BX,DI
- 15. ??????? ????????? ?????
- NEG lt???????gt
19??????? ????????? / ?????????????? ?????? (6)
- 16-17. ??????? ?????????
- MUL lt???????gt
- I?UL lt???????gt
-
- mov AX,4
- imul word ptr A
20??????? ????????? / ?????????????? ?????? (7)
- 18-19. ??????? ????????????? ?????
- CBW AL -gt AX
- CWD AX -gt DXAX
-
21??????? ????????? / ?????????????? ?????? (8)
- 20-21. ??????? ???????
- DIV lt???????gt
- IDIV lt???????gt
-
- mov AX,40
- cwd
- idiv word ptr A
22?????? ???????????????? ?????????
- X (AC)(B-1)/(C8)
- ??????? ??????
- A dw 25
- B dw -6
- C dw 11
- X dw ?
??????? ???? mov CX,C add CX,8
mov BX,B dec BX mov AX,A add
AX,C imul BX idiv CX mov X,AX
23??????? ???????? ??????????
- 1. ??????? ???????????? ????????
- short
- JMP near ptr lt????????????? ??? ???
?????gt - far ptr
- ???????
- ?) jmp short Label1
- ?) cycle
- jmp cycle
- ?) jmp BX
-
- ?) jmp dword ptr BX
24??????? ???????? ?????????? (2)
- 2. ??????? ????????? ????????
- lt???????gt lt????????????? ??? ??? ?????gt
- ??????? ????????? ????????
- JZ ??????? ?? "????"
- JE ??????? ?? "?????"
- JNZ ??????? ?? "?? ????"
- JNE ??????? ?? "?? ?????"
- JL ??????? ?? "??????"
- JNG, JLE ??????? ?? "?????? ??? ????? "
- JG ??????? ?? "??????"
- JNL, JGE ??????? ?? "?????? ??? ????? "
- JA ??????? ?? "????" (???????????
??????) - JNA, JBE ??????? ?? "?? ????"(??????????? ??
??????) - JB ??????? ?? "????" (???????????
??????) - JNB, JAE ??????? ?? "?? ????" (??????????? ??
??????).
25???????? ??????? ?? ????? ??? 128 ????
?
- jz zero jnz
continue -
jmp zero - continue ...
26???????????????? ?????????
cmp ... jlt???????gt ELSE
lt???????? 1gt jmp COM ELSE
lt???????? 2gt COM lt???????????gt
27?????? 1. ????????? ??????????? ???????? ?????
- ???????? ????????? ?????????? Xmax(A,B)
- max proc near
- mov AX, A
- cmp AX, B ????????? A ? B
- jl LESS ??????? ?? ??????
- mov X, AX
- jmp CONTINUE ??????? ?? ?????
????????? - LESS mov AX, B
- mov X, AX
- CONTINUE ret
- max endp
28?????? 2. ??????????? ??? (Ex1.asm)
- code segment
- assume cscode,dscode
- c dw ?
- a dw 24
- b dw 18
- begin proc far
- push DS
- mov AX,0
- push AX
- mov AX,code
- mov DS,AX
29??????. ??????????? ??? (2)
- mov ax,a
- mov bx,b
- cycl cmp ax,bx
- je kon
- jl lit
- sub ax,bx
- jmp short com
- lit sub bx,ax
- com jmp cycl
- kon mov c,ax
- ret
- begin endp
- code ends
- end begin
cycl
lit
com
kon
30??????? ???????? ?????????? (3)
- 3. ??????? ??????????? ??????????? ?????????
- 1) ??????? ??????????? ?????
- LOOP lt ????????????? ??? ???
?????gt - ??????
- mov cx, loop_count
- begin_loop lt ???? ?????gt
-
- loop begin_loop
31??????? ???????? ?????????? (4)
- 2) ??????? ???????? ?? ??????????? ????????
- JCXZ lt????? ????????gt
- ??????
- mov cx, loop_count
- jcxz end_of_loop
begin_loop lt ???? ????? gt -
- loop begin_loop
- end_of_loop ...
32??????? ???????? ?????????? (5)
- 3) ??????? ??????????? ????? ? ????????
- L???E lt????????????? ??? ??? ?????gt
- LOOPNE lt????????????? ??? ??? ?????gt
- ??????
- mov CX, loop_count
- jcxz end_of_loop
- begin_loop
- lt ???? ?????gt
- cmp al, 100
- loopne begin_loop
- end_of_loop ...
33???????????????? ??????????? ?????????
- ?????????? ????? ??????????? ????? 1..n.
- ??????? ??????
- S dw 0
- n dw 18
- ??????? ????
- mov CX,n
- mov AX,0
- cycle add AX,CX
- loop cycle
- mov S,AX
S0
i1,n
SSi
mov CX,n mov AX,0 mov BX,1 cycle
add AX,BX inc BX loop
cycle mov S,AX
34???????????????? ????????? ????????
A
- A dw 4,6,-1,7,5
- ??????? 1
- mov AX,0
- lea BX,A
- mov CX,5
- cycleadd AX,0BX
- add BX,2
- loop cycle
4
6
-1
7
5
DS
DS
A
A
4
6
-1
7
5
4
6
-1
7
5
S0
BX
BX
i1,n
??????? 2 mov AX,0 mov BX,0 mov CX,5 cycleadd
AX,ABX add BX,2 loop cycle
SSAi
35???????????????? ????????? ??????
A db 2,3,1,-1,8 db 6,-8,5,4,7 db
8,6,3,1,6 mov BX,0 mov CX,3 cycle1
push CX mov CX,5 cycle2 ...
ABX inc BX loop cycle2 pop CX loop
cycle1
- A db 2,3,1,-1,8
- db 6,-8,5,4,7
- db 8,6,3,1,6
-
- mov BX,0
- mov CX,3
- cycle1 push CX
- mov CX,5
- cycle2 ... ABX
- inc BX
- loop cycle2
- pop CX
- loop cycle1
-
A
2
3
-1
-1
8
6
-8
5
4
7
8
6
-3
1
6
DS
DI
A
2
3
-1
-1
8
6
-8
5
4
7
8
6
-3
1
6
BX
mov DI,0 mov CX,5 cycle1 push
CX mov CX,3 mov BX,0 cycle2 ...
ABX,DI add BX,5 loop cycle2 pop CX inc DI
loop cycle1
36??????
- ?????????? ?????????? ?????????????, ??????? ?
????????????? ???????? ? ??????? - code segment
- assume cscode,dscode
- x dw 1,-1,3,0,15,-4,0
- n dw 7
- ng dw ?
- nl dw ?
- nz dw ?
-
- begin proc far
- push ds
- mov ax,0
- push ax
- mov ax,code
- mov ds,ax
37 ?????? (2)
- mov cx,n
- mov bx,0
- mov di,bx
- mov si,bx
- again cmp xbx,0
- jle less_or_eq
- inc di
- jmp short next
- less_or_eq jl next
- inc si
- next add bx,2
- dec cx
- jnz again
- mov ax,n
- sub ax,di
- sub ax,si
- mov ng,di
- mov nl,ax
- mov nz,si
??????
ng0
ng0
nz0
i1,n
gt0
0
xi ? 0
lt0
ngng1
ngng1
nln-ng-nz
?????
38??????? ???????? ?????????? (6)
- 4) ??????? ?????? ???????????
- ?) ??????? ?????? ?????????
- CALL lt????????????? ??? ??? ????? gt
- ?) ??????? ???????? ??????????
- RET lt?????gt
- ????? ????????? ?????? ???? ???????? ? ????
- lt??? ?????????gt ???? lt ????????? ???????????gt
- lt????
?????????gt - lt??? ?????????gt endp
39??????????? ???????? ?????????? ? ?????????
???????? ?????????
?????????
CALL lt???gt
lt???gt PROC RET lt???gt ENDP
????
????? ????????
2 ??? 4 ?????
40??????? ????????? ?????
DSSI
DF 0
????????
ESDI
DF 0
????????
- ??????? ???? ??? ?????
- ?????????/????? ????? ???????????
- STD
- CLD
41??????? ????????? ????? (2)
DSSI
- 1) ??????? ???????? ?????? LODS
- LODSB ???????? ?????
- LODSW ???????? ?????
- 2) ??????? ?????? ?????? STOS
- STOSB ?????? ?????
- STOSW ?????? ?????
- 3) ??????? ????????? MOVS.
- MOVSB ????????? ?????
- ??VSW ????????? ?????
AX(AL)
ESDI
AX(AL)
DSSI
ESDI
42??????? ????????? ????? (3)
- 4) ?????????? ??????? ??????????
- REP lt???????gt
- ??????
- mov CX,10
- lea SI, A
- lea DI, B
- rep movsb
43??????? ????????? ????? (4)
- 5) ??????? ???????????? ?????? SCAS
- SCASB ????? ?????
- SCASW ????? ?????
- AX(AL)-(ESDI) -gt ?????
- 6) ??????? ????????? ????? CMPS
- ?MPSB ????????? ????
- ?MPSW ????????? ????
- (CSSI)-(ESDI) -gt ?????
AX(AL)
ESDI
DSSI
ESDI
44??????? ????????? ????? (5)
- 7) ?????????? ??????? "?????????, ???? ?????" ?
"?????????, ???? ?? ?????" - REPE lt ??????? gt
- REPNE lt ??????? gt
- ??????
- mov CX,10
- lea SI, A
- lea DI, B
- repe cmpsb
45??????. ????????? ?????? ? ???????? (Ex2_2)
S
ESDI
Flaq0
A B C D E
Tabl
DSSI
i 1,6
S F D Y E
D H F Y U
A B C D R
STabli
???
??
F Y E D K
A B C D E
Flaq0
S Y U F K
Flaqi
46????????? ?????? ? ???????? (2)
- code segment
- assume CScode,DScode,EScode
- Flag DB 0
- S DB 'ABCDE'
- Tabl DB 'ARTYG','FGJJU'
- DB 'FGHJK','ABCDY'
- DB 'ABCDE','FTYRG'
- begin proc far
- push DS
- mov AX,0
- push AX
- mov AX,code
- mov DS,AX
- mov ES,AX
- lea SI,S
- lea DI,Tabl
- mov CX,6
- mov BL,1
- cld
47????????? ?????? ? ???????? (3)
- Cycle push SI
- push DI
- push CX
- mov CX,5
- repe cmpsb
- pop CX
- pop DI
- pop SI
- je Found
- add DI,5
- inc BL
- loop Cycle
- jmp not_Found
- Found mov byte ptr Flag,BL
- not_Found ret
- begin endp
- code ends
- end begin
48??????? ??????????????? ??????
- 1. ?????????? ???????
- NOT lt???????gt ?????????? ??
- AND lt??????? 1gt, lt??????? 2gt ?????????? ?
- OR lt??????? 1gt, lt??????? 2gt ??????????
??? - XOR lt??????? 1gt, lt??????? 2gt ??????????? ???
- TEST lt??????? 1gt, lt??????? 2gt ? ??? ??????
?????????? - ??????. ???????? ?? ????? ? AL ?????? ???
- and al, 10000000B
- 10110001
- 10000000
- 10000000
49??????? ??????????????? ?????? (2)
- 2. ??????? ??????
- lt??? ????????gt lt???????gt, ?L ??? 1
- ???????
- SAL ????? ????? ??????????????
- SHL ????? ????? ??????????
- SAR ????? ?????? ??????????????
- SHR ????? ?????? ??????????
- ROL ????? ????? ???????????
- ROR ????? ?????? ???????????
- RCL ????? ??????????? ????? ? ?????? ????????
- RCR ????? ??????????? ?????? ? ?????? ????????
0
CF
0
CF
CF
CF
0
CF
CF
50??????? ??????????????? ?????? (3)
- ??????. ???????? ????? ? AX ?? 10
- mov bx, ax
- shl ax, 1
- shl ax, 1
- add ax, bx
- shl ax, 1
51?????????? ??????/???????
????
????????? ?????????????
??
?? ? - ?
???. ?????
?????????
??
?????
?????????? ?/?
- IN AL ??? AX, lt????gt ??? DX
- OUT lt????gt ??? DX, AL ??? AX
- ??????
- in AL, 60H
- out 60H, AL