instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/assembl_15/metod(as… ·  · 2015-08-2856 ˆ...

117
/ !" _________________ #.!. _________________ 2005. «ASSEMBLER» «! $"% » & 071900 «’& » () 2005

Upload: lykhanh

Post on 23-May-2018

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

���������� ������ � ���� ����

�������� ���� ���� ������� ���������� ����

������������ ���� ����

������ �������������� ��� �������

�������� / ���� !"��

_________________��� ������ #.!.

_________________ 2005.

���� ��������� �� «ASSEMBLER» ����������� �������� � �������� ���������� ���� � �����

«!���������� $"% � ������»

��� ������� ���&��������� 071900 «'�����&����� ������� �

�������»

'��������� �()

���� 2005

Page 2: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

2

) * 62.50

+��� �������� ���� «Assembler»

%���������� �������� � �������� ���������� ���� �

����� «!���������� $"% � ������» ��� ������� ���&��������

071900 «'�����&����� ������� � �������». – ����: '��. �(),

2004. – … �.

#��� �����: ,��� #.�.

-�&������: .��� � '.�.

%���������� �������� �������� �� ��������� �������

� ������� � ����������� ������ 7 ������ 2004 ., ����� /2

0� . ������� �.(.,���

Page 3: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

3

������ ��

" ������ .............................................................................................. 4 1. !���������� ������&����� Intel ����������� $"% ������

IBM PC/XT ...................................................................................... 5 -������ .................................................................................... 8 #������, ����&�� �������&�� ........................................... 11 #��� .......................................................................................... 13 (���� ���� ............................................................................. 13 -����� ������&�� .................................................................. 14

2. #����� � �������&�� ������&�� � ������ ������������ ������ ....................................................................................... 16

�������&�� ������� ........................................................... 19 *��� �� ������� .......................................................... 23 .������ ������� ................................................................ 24

3. Windows-����� ��� �������� ���� �� ����� Assembler 31 4. #�������� ������� �� ���������� .......................................... 36

#�������� ���������� ............................................................. 36 .�� ��� ����&��� �������� ������� �� ����� Assembler ................................................................................. 44

5. (����� ������� �� ����� Assembler ...................................... 49 6. 0������ � ���������� ������. ............................................... 58

1��������� ����� /1 ..................................................... 58 1��������� ����� /2 ..................................................... 59 1��������� ����� /3 ..................................................... 60 1��������� ����� /4 ..................................................... 68 1��������� ����� /5 ..................................................... 78 1��������� ����� /6 ..................................................... 86 1��������� ����� /7 ..................................................... 97

1'�2-!�)-! ................................................................................ 117

Page 4: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

4

�������� 3 ���� �������������� ����������� $"% �� ���� IBM/PC-

XT ������� � � ������ ���������� ������ � �� �� ��������� ������ ���� 4������ ����, �� ���� ���� ���� ������� � ��5�� �������� ���� �� ����� ���� �� �� (����������), � ����� ����� ����� ��������� ����&���� �������.

+��� �������� ���� !��������� – 4� ��� ����� ���� ������ ������ �����, � ������ ���� ��5��� ��� ���5��� ��������� �������� ������ �, ��� ����, ���������� � ����� 4������ ���� ������ ���� ������ ��������� � ��� ����� � ������� ��� �� ��. .��� �������� ��� 4�� ���������� ��������� ����������� ������ ����� ���� ����&���� �������. !����������� ��, ��������� ��� ������&��, ����� ���� ������� �� � ��� � ������ 4������ ���� �������. +��� !���������, ����� ���, ��������� ���� ����������� �� ��������, �� � ����� � ������� ������� ������� �����. $� �������, �� ������� �� ����� !��������� ������� ��������� ��� � ��������� ��������� � ������� � ���������� ���� ������ � ����������� � ���� �����. )�� ��������� ���������� ����� �������� ������������ ������ &��������� ������� ��� ����� , �� ����� �������� ���������� ���������������� ��������� ����������.

6� ����� �� 4�, �������� ����� !��������� � ������ �� ��� 4���� ��� �� �������������� ��������� , ������� �� ���� ���� ����� ����&��� ����� $"%, ����&����� ������ � ��������� � ���� ��� �� ��, �� � ������ ��������� ��� ��� ��� ��������� ���4������ ��� ������.

Page 5: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

5

1. ���������� ��������������� Intel ������� !�"� #� � ���� IBM PC/XT

-���������� ����������� ��� ������&�����, ��� ��� ��, ������� ������ ������ ����������, � ����� ����&�� �������� $"% �� ���� ��������� ��� ������&�����. " � ��� � �&�����-4����������� ������������ ($"% �� ���� ������&����� Intel ������� ����� �������������� -����, � �� �������� ��� ����������� ���������� ��� ���� ����������� ������&����� ����� Intel.

#�������� ��� � ������� ($"%, ��� ��� ��, �������: ��� �������, ��������� (�����������) �����, �������� ������ ������� , ��������� �� ������� �������� (67% ) � ����� (6�% ) ������, � ����� ��� ����� ������� . 6�������� ������� ������� ���� ��������� �����, �� ���� �����5����� ������� ��������5�� ������� (0) (ROM - read only memory), ������ �� ��������5�� ������� .0) (RAM - random access memory), ��&���� � ���� ���� �����, � ������� ����� ��� ������.

��������� .0) � (0) ������� ��� �������� ��������. 8���������� ��� ��������� ��������� � ������ �� ����, �� ��� ��������� 4������������ �������� .0) ������ ����� (4����� ������ ������), � (0) – ��� (4������� ������ ������).

.��� �� �� ��� ����� (0) ��������� ��&����� ������ ��������� ���������. " (0) �������� ��� �� ������� ��/ � �� BIOS, � ����� ������� ��������� ������� � �����&�, ��������, ��������� ��������, ������� ������ ���� POST � �.�.

.������ ��� ������ .0) ������������� ��� ������ �������� ������ � ������, ������ �� ������������. 1������ ������ ��� ������ ��� ������� ��� ��� ����� ��������� �����, ������ �� ����� ����� � � ����, ���� ����� ������.

,���������� ��&���� (,() � �������� ����������� ���������� ������ ��� ��� � �������� ���������� ��������� (#9'#). ,( ������� �������� ������, ������ �� ������� ����� ��������� �� ������ �� ������. -���� ��� 4��������� ������� ��������� ������������ �������� ���� �����, ������� ������ ,( � �������� ������ #9'#, �������� ���� ��������, � ��5�� ����� ��������������� ����� �� ��� ������� .

"������� ��������� ������ ������� �� ���� � ���� ����� ���� ��&����� � � ���� � ������. #������ ��&���� 80�86 �����&�� Intel ������� ���� ���������: 8086, 80186, 80286, 80386, 80486, Pentium, Pentium II, Pentium III � �.�.

Page 6: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

6

# �������� � 80�86 ��������� �������� ����� ����� AMD, IBM, Cyrix. .��������� 4��� ��&���� � ������ ������� ������ �� �� �� �������� �����: �������, ���������� ��� ������� ������ ��&���� , ��� �����-��� ��������� ��� ���� ������� �� ���� ������� ������. (�� 4�� ���� � ������ ������� ����� ��&����� 8086, ������ ���� � ������ �������� ���������� ��� �������� �������� ��&���� .

#�������� &�������� ��&����� Intel 8086 ��� ��������� �� � � �������� ���� (���.1.1):

− ���� �������� (EU:Execution Unit); − ���� ���� ��� ��� (BIU:Bus Interface Unit).

-��.1.1. #�������� &�������� ��&�����.

'�������� (interface) -4� � ������� ������ , ������� ��5�� ��������� ������� � ��������� ������ ��� �� ���������, ��� � �� ������� �� ���.

" ���� EU ����: ���������-������� ������� ALU, ������� ���� ����� CU � ������ ������ . )������ � ���� EU ������� ��� ������� �����, �������� �������������� � �������� ����&��.

Page 7: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

7

��� ����� ���� BIU - ������� ���� ����� ������, ��� ������ ����� � ������� ������ – ������������� ��� �������� ������5�� ����&��:

− ���� ����� ����� ������� � EU, ������� � ������� ������� ��� ��/ � ��;

− ������&�� ������; − ����� ����� (��5��� ������ � ��5�� ���� ������

����� Queue, ����� �� ���� ������� ������ � �����������). # ���� ������ ����������, ��&���� 8086 ����� �� ����

������ �5� ���������� � ������&��, ������� ��������� ������ , ������� ������ ����� (�������� �����) � ������� ��� . (�&���� ���� ���� �� 20-��������� ���� ������ ����� ��������� �� ������ ����� (��� ������), ����� � 16-�������� ���� ������ �������� ������������ ����� (������ �����), � ����� ����������.

%�����&���� �������� � � ���� ������� ��������� (� ���� ������� ������� ����� ������). #�� ����� ������&�� ��������� �� ���� �� � ��� ASCII (!����������� ����������� �� ��� ����� ������&���). :��� �� ������ ��������� �� ���� �� � � ���� ����������. .���&�������� ����� ������� ������ ����������� ���.

%���������� �����&� ������&��, �� ���� ��5�� � ����� �������, ���� ����� ��� (Bit). ������ �� ���� ��� ���� ����� ������ (Byte) � ������� ���� ��� ���������� ���������� �����&� – ������ ������. 9��� ����� �������� ���� � ���� &������ 0...7 (��� 1.2, �).

7 6 5 4 3 2 1 0

�) 9���

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

�) #� -��. 1.2. 2����&� ������&�� $"%

������ � ��� ������� �������&����������� ������� ����� (Word), ���� ���� ���������� � 0 � 15 ���� � ���� (���. 1.2, �). 9��� � ������� ������ ��������� �������.

:���������� � ��� ������� ������ ����� (Double Word), � �������&��� ���� � – ������� (Paragraph).

����� �����, � ��5�� 16-�������� ���� ������ ��� ������ ��� ����� � 0 ( ��� �� ������ ����� 0) � 65535 ( ��� �� ������ ����� 1). 6������ �� �, �� � ����� ������� �������

Page 8: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

8

���� ����������, �� ����� ��5��� ����� �������� – �����, ���������� � ���� �������, ������ ������. # ���� �����, ��� ����� ��� ��� ���������� ������� ������ ����� ��� ���� �� ����� � ����� ������� ��������� � �����. (4��� ��������� �������������� �������� �������� ���� ������� �������&��������� ������� ���������. " ����� ������, ����� �� ������� ��� (�������) ����������� ���� � ���� � ������� ������ �������&���������� &������.

(�� ��������� ������ ������ � ����� ����� ��� ����� �������� ��� � B ��� b, (��������, 101B), � �������&��������� – ��� � H ��� h �� ��&�. 2��� ���� ���������� � ��� �, � ���������� � ������ ����� �� ���� ������, ��������, 0BA8H. *��� �, !�������� �� ���� ������ ��� ����� ������� ������ ��������� � ��������� �������� ���������, ����� �� ���� ��� ��� ������� ���������� ��� ��� D � O.

��$����" (�&���� 8086 ������� 14 �������&������������ ������ ,

����� ����������� ��� ���� ����� ���������� �����, ������&�� � �������� �������������� ����&��. *����� ������, ������5�� �� �� , ���� ���� ����� �� � �����.

�������� ��� � �� �����. * ��� ������� 16-��������� ������� !8, "8, #8, DX, ������ �� ����� �������� �� � � ����� � ���� ������ :

!8 ����� �� !6 (������� �����) � AL (������� �����); "8 ����� �� "H � BL; #8 ����� �� #6 � CL; DX ����� �� DH � DL; " �5�� ������ ����&��, ��������� ��� ��� ���� �������,

����������� ��������, ����� � �����������. (�� 4�� � ������ ������� � ���� ������ ���������� � ��������. 6��� ������������� ������� ����������� ����&�� ���� �������:

− ������ !8 ������ ��� ������ �������� ������ (������ ����������), ���� ����������� ��� �������� ����&�� �������, ��������, ��� ����� � ����� �������������� � �������� ����&��;

− ������ "8 ������ ��� �������� ������ ������ ������ ������ (��� �� ������), � ����� ����������� ��� ������������� ������;

− ������ #8 ���� ����������� ��� ������ �������� ������, � �� �� ������ ��������, ��� �������� ���� � ������ ��� ������ ��� �������� �������;

Page 9: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

9

− ������ DX ����������� �� ��� ����� ��� ������ �������� ������, ���� ������ ������ � ��������� ������ ����� ������� ���������� ���������, � ����� ����������� ������ � ����������� ����������� ��� ��������� � ������ ������ � ��� �������� � �������.

�������� ��� ���� ���. " ������&����� ��5��� ��� ������ 16-��� �� (2 ����� ��� 1 �� ) �������, ����� ��� ��������� ������� ������&�� ������ . .��� �� ��� �� ������ � ������ � ������� �5� ���������� — 4� ������ "8, ��� ��� �� ������. ��� ����� ������� — 4� ��������� ���� "-, ������ �������� SI � ������ ���������� DI (� � �������� �5� ���� ����� ��������� ���������). .�������� ����� 4��� ���� ������ ���������.

1��� �� ��� ����� ��� 4-� ������ ���� ������ ����� ��� �������� ������ ������, � ������, ������5�� � ������� �� ������, ��� ���5����� �� ���� � 4��� ��������. (�� ������&�� ������ ��� �� � ��������� ������� ��� ���� ������ ��� ��������� ������&���. -���������� ����� �������� ������� 4��� ������ � ����� ������ ���� ����� ������� ��� ������� ��������.

�������� ��������. " ����� ������&����� ������� ������ ��������� �������, � ��5�� ����� ������ ��� ����� ��� ��� � ������� ������� ��������� ������ . $���� ��������� � ������

− CS – ������ ������� ������� (������� ���) ��������� ����������� ����� ������, ������5�� �������, � ���� ��������� ��&����� ������;

− DS – ������ ������&��� ������� (������� ������) ��������&����� ����� ������, �������������� ��� �������� ������;

− SS – ������ ���� ������� (������� �����) ��������� ����� ������, ���������� ��� ��������� ����;

− ES – ������ ��������� ������� (���������� �������) ����� ��� ������������ ������ ������, ����������� ��� �������� ������.

$�� ������ ��������� ������ ������ ��� ����������� ����������� ���� ����� ��������� ������� ������. (������ ����������� ���� ������� ����������� ���� ��������� �� ���� ��5� ������� �������, ��� ��������&�� ������ ������� �� ���� �������� 4� ��������.

������� �� � ���� ���� . )�������� ����� SP – 4� 16-��� �� ������, ����� ��������� ���5���� ����5�� ������ �����. )�������� ����� SP ����� � ��������� ������� ����� SS ����������� ������&����� ��� ����� ���� ��������

Page 10: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

10

������ �����. #��� ���� ������ ����� ����� ������� ����� ������, � ���� ��� �� ���5����� ����, �������� SP ����������� �� 2, ��� �� �� �������� �� �����, ������&���� � ����� ��� �������� ������� SP �� 2.

������� �� � ���� �� �� IP. -����� ��������� ����� IP, ����� ���� ����� ������� �������� �����, ����� ������ 16 ��� � ������ ����� ������ ������, ������5�� ����� ������5�� ������. %�����&���� ��������� ������ IP � ����� � ������� CS ��� ����� ���� 20-��� �������� ������ ������� �������� ������, ��� 4�� ������ CS ������ ������ �������� �������, � I- – ���5���� � ������ �������. ( ���� �, ��� ������&���� �������� ������ �� ������ � ������� ��, ������ IP � ����� ����� �� ���� ���� ������. �� ��������� ��� ��������� ������� ������� IP ������ ������ �������.

������� �� ��. ����� – 4� �������� ����, ��������5�� �������� 0 ��� 1. -����� ��� (������� ) ������� �� ��� ���� ��� ��� (�� 16). *����� ��� ���� ������� ����� ��� ��������, ������� �� 4��� ��� ������� �� ��� ��, ����� ������ �������� �������� ������. ���� ���� ����� ��� ����5�� ������� ������&�����. #������ ������&�����, ��� ��� ��, ���������� �������� �������, �������� ����5�� ����� ������.

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 X X X X OF DF IF TF SF ZF X AF X PF X CF

9��� ������� ��� ����� ������5�� ����������: OF (������� �����������) – �� �� �����&�, ���� �������

������������� �����������, � ���� ��� �;�� ���������� ��� ����� ������ ������ ����������;

DF (������� ����� �����) – ������ �� ����� �����&� ��� � ��������� ���������� ������� ������� ����, � ��� – ��� ����������;

IF (������� ���������� ����� ����) – ����� ���� ���������, ���� IF=1. 2��� IF=0, � ����������� ���� �������� ����� ����� ����;

TF (������� ������� ��) – ���� TF=1, � ��&���� �������� ������� ����� ���� INT 3 ���� �������� ����� ������;

SF (������� �����) – SF=1, ��� ������� ��� ���������� �� �� �����&�. '���� �� ���, SF=0 ��� ����������� �����, � SF=1 ��� ���&�������� �����;

Page 11: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

11

ZF (������� ���� ����������) – ZF=1, ���� ��������� �� �� ����;

AF (������� ���������� �������) – 4�� ��� ������ �� ����� �����&� ���� �������� ����� �������� ������� � �������� ��� ����� ���� ������� ��� ����� ����� ����������;

PF (������� �������) – 4�� ������� ������ �� ����� �����&�, ���� ��������� ����� ����� ���� �����&;

CF (������� �������) – 4�� ��� ������ �� ����� �����&�, ���� ����� ���� ������ ��� ���� �� ������ ���� ����������, � ������ ��� ���� ������ ����&�� ��� ������� ����� ������� �� , ����� �������� � ��������� � ������� �� �� � �� ;

X – ������� �� ����� ����. 1�� ��������, �� �� ���� ������ ����� ������� ���

������ �� ����� ��������������� ��� ��������� ����&���� ��&�����. 0� ����������� ���� �����������, �� ���� ������ ����� ������� ������� ������&����� � ����� �� �������� �������� �������. ���� ������ ����� ������ �� ����� � ������ ����� ���&����� ���������������� ��� 4� ��������. ���� ������ ����� � ������ ����� ��� � ������� ��� ��������� ������ �������� �������.

%�$����", ������� ��$�������� :����, ������ �� ����� ��&����� �� ������� ����,

� ������ ��������, � ���� ������� ����� ������ �� ������ (.(). -����� ������ .( ���� ���� 8 ������ , � ���� 1 ����. (������ ��� ������&�� ������ ��&���� ��������� 16-��������� �������� �������, � 4� ������� ��� ��� ����� � 65536 (FFFFh) ���� ��� 64*

(1* = 1024 ���� = 210 ����) �� �� ������. 9�� ��������� ���

��������� ������ ������� 64* ���� ����� �������. ���� �;�� ��������� ������ � � ����������, � �4��� ��� ������&�� ����� �;��� ������ ��&������ ������� � x86 ����������� ����&�� �������&�� ������. 1��� ����� ���������� �� ������ ������� ( ���� ������ 16, � ���� ���������� � ����&� ��������) � ������ ������ ����� ������� (4�� ����� ������ ���� ����� ������). (�&����� ��������� �������� ����� ����������, ���� ����� ���������� ����������� ������.

!����� ����� ���� ������� ������ ��� ������� ��� �� ������5�� �������. *�� ��&���� ������� �������� ������ �� ���������, ������ � �� ������ ����������� ��������, ������� IP. $�� ����� ���� ����� �������������. (������ ������ IP �������&������������, ������������� ����� ��� ������� 16

Page 12: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

12

� ����� ������ . :��� ������� 20-��� �� ����� (�������� ����, �������5�� ��&���� � ������ 20-���������), ������������ 4 ���� ������� ������&�� �� �������� �� ��������� ������ ( ��� ������ ������� �� ������� CS). #��� ��������� ������� ����� ������ 16 ������ , � ������5���� 4��� �������� 16-��� �� �������� ���� ����� ��� �� ������ ������. %�����&���� �;������� 16-��� �� ������������� ����� � 16-��� �� ��� �� ����� ������5�� �����: � ��������� �������� ������� ������� (��� �� �����) �������� ���� ��� ������ ������� ��������, ����� � 20-��� �� (����� ����� �������) � ����� ���� ���5���� (������������� �����). (�� 4�� 20-��� �� ��������� � ������ ���������� ��� ��������� ������ ������ ������ (���. 1.3).

-��. 1.3. (���&�� �������� ������� (��������) ������

6� ���. 1.3 ��� ���, ��� ���������� ������� &��� � ���������� �����: ��������� ����� �� �������� �� �� �� ��������� ������ , �� ������ �� ������ ������� �� � ����������� � ���5�����. " � � ������, ���, �� �������� ���5���� ��� ������� ������� �� �� � �������� �� ���� ������� : �� �������� ���5���� ���� ������� ������ � (���) �� ������� �� ��� � (���) �� ������� �������. *������ ������� , ����� ��5�� ����� ���� ���5����, ����������� ���� ����� �������� ������� ������, � ���� ����� ������� �������, � �������� ��� ������ �����.

#�5��� ��� ��� �� ��� ���� ������ : − ������ ��� – ������� �������� ������, ����������

������� CS;

Page 13: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

13

− ������ ������ – ������� ������, � ���� �������� � ������ ������, ��������� �������, ���������� ������� DS;

− ������ ����� – ������� �������� ������, ���������� ������� SS.

����� ��5��� ��� ��� ������������ ��������� ������� (ES, FS, GS), ����������� ��� ������&�� ������������ ������ ������.

(�� ������ ����� �� ����� !��������� ������ ����� ��� ������ � ��5�� ������5�� �������&��:

<���� ������>:<�����> ��� <�������� ������>:<������ �������>

%��� " ���� ������� ������� ��������� ������ ��������

������� ������&��. $�� ������� ���������� ��������� ������ ������� � �������&�� ����� LIFO («�������� ������ -��� �� ����»), ���� ��� ����� ����� ��������/�� ������� (stack). ��� – 4� ������ ������ ��� ������ �������� ������, ����� � ���&������� ������� ��� ������ ��� �������� �� � (� �� �����); ��� 4�� ��� ���������� ������ ������� ������� ���� ��� ������ � �� ���� ���������� ���� �� ���� ��5� ������: ��&���� � ���������� ������� ��� ��� � ���� ���� ������ ������ ��������. 6������ ���� ������ ���� ����� � ���� � �����������, 4�� ������ ���� ������� ����� � ���� �� ���������, � ���� � ������ ����� (��) ���������(�) ������. #��� ���� ��������� �� �� ����� ������&�� ����� ������ ��������� ����� SP. (�� �������� 4������ ���� ���� ����� � ����������� ��������� ��������� �����, � ��� �� ������� – ���������, � ���� ���� ���� «������» ����� ������� ����� ������. !���� ������� ������� ���� 4������� ���� ����� ������ ���� (TOS), � ����� ������� ����� – ����� ����� (���� ��������� ������� SS).

����"����& :��� ������� �����&��, ��� ������� ������� ��� ��

����� ���&������� ��&����, ���� ������� ��� ������� ������� ����������� ��� ��, ��������, ������ ��� ��� �� ��� ������ ��� ������ ������� �� ���. ���� ��, ����������5�� �������� ��� �� ����� ��&����, ���� ����� ���������, ������� �� �� ��&��� ��� 4�� �������� �� ����� �� ���� �������� 4�� ��&�����. #�5��� ��� � � �5�� ������ ����� ����: �������� � �����. (�� �� ���&�������� ��������

Page 14: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

14

,( ��� ������, � ���� – ������, ��� ����� � ����� ������� �������. �������� ��������� ����� ����: ������� �� ����, ����������� � �.�., � �������� ������ – 4� ����� �� ������ ���� � ����� ���-��� ������� � ��/ � ��.

(����� � ��&����� ����� ���� ��5��� ������ �� ���� �������, � ���� �������� ��&����� ����� ���� ��������� �������� � ��� ���� ����� �������. (���� ���5����� � ��&����� ����� ���� ���� ���� ������� ������� ��� ������ � ��� , ����������� ��&����� ����� ����, ���� ������� ����� ���� 4�� ������� ����� ���� ����� ����.

6������� ����� ����� ���� ���� ���� ���� IF � TF, ����� ��� �������� ����� ���� ����� ���� ��� ���� ����� ����. 2��� ��� �� ��� ����� ���� �� ��� ������ � ��������� ���� ����� ����, � ������&���� �� ������ ����5�� ������, � ����� ��������� ����� ��������� ����� ����:

− ����5�� �������� ������� ��� ��������� ����; − ����5�� �������� �� ������� CS ��������� ����; − ����5�� �������� �������� ����� IP ��������� ����; − ������ ����� ���� IF � TF. 6 � �������� �������� ����� � ������� ��� ���������

��������� ����� ��� � ������ ��&����� ����� ���� (������ ���� ����� ����). "� ��� ���� ����� ������� ��5��� ������ ������, ����� �� ������ �� ����� �������� ���

− �������� ����� IP; − ������� ��� CS; − ������� ��� . ��� �� , ���� �������� � � �������� ��������

����� � ������� ���, ���� ����� �������� �������� ��� ������� ��������. *����� ���� ����� ���� �������� ���� �� �������� 0...255 (���� ��������), � ����� ����� ����� ���� �������� ����� �������� ����� ���� �� ������ (������ ����� ����� ����). ����� �����, �� ����� ����� ���� ������� ������� ������� ���������, ����� ��������� ������ � ������ 0000h:0000h � ���&������������ ��� ������� ���������.

��'��" ��������� " �� ������� � ���&�����&�� � ����������� �������

���� ���� ��� (�������) ������ ����� !��������� ��������� ������5�� ����� ������&�� ������ :

− ������ ��; − ������; − ��������� �����; − �� �����;

Page 15: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

15

− ��� ��; − ���������; − ��� -���������. -����� �� ������&�� �������� ��� ������ ���� ������ �

������ ���� ������ ��&�����, ��������, PUSH DS MOV BP,SP (�� ����� ������&�� ��� ������ ������� ���� ��� �����

������, ��� – ������: MOV Data,AX 6�������� ����� ������&�� �����������, ��� ������,

������ ���� ��� �� �������� ����������� ������: MOV AH,4CH (�� ������ ���� �� ���� ������&�� ��������� �����

���������� ����� �� ������� ������ ��� �� ��������� ������ � ���5���� �������� BX, BP, SI ��� DI:

MOV AL,[BX]; 9��� – DS, ���5���� – BX MOV AX,[BP]; 9��� – SS, ���5���� – BP MOV AX,ES:[SI]; 9��� – ES, ���5���� – SI " ������ ���������� ��� � ������&�� ������������� �����

� ������ ����� �������� ���5���� � ������� ������� BP ��� BX, ��������,

MOV AX,[BP+6]; 9��� – SS, ���5���� – BP+6 MOV DX,8[BX]; 9��� – DS, ���5���� – BX+8 (�� �������� ������&�� ������������� ����� �����������

��� ����� �������� ������� ���5���� � ������� ������� SI ��� DI ��� ��, ��� � ��� ��� � ������&��, ��������,

MOV DX,[SI+5]; 9��� – DS, ���5���� – SI+5 9�� -��������� ������&�� �������� ��� ������ ���� ���

��������� ����������� ������ ����� ������� ��� ������� � ������� �������, � ����� ���5����, �����5��� �������, ��������,

MOV BX,[BP][SI]; 9��� – SS, ���5���� – BP+SI MOV ES:[BX+DI],AX; 9��� – ES, ���5���� – BX+DI MOV AX,[BP+6+DI]; 9��� – SS, ���5���� –BP+6+DI

Page 16: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

16

2. %������� ����� &��� ����� &��� � �� ���� �����( ���"� ���$����

*�� ��� ��, ��� ��������� ������� �� Assembler-� ��������� ��� ��� ����� ��� ���: ��������� ������� ���������, ��� �� ������, ������� �� ��� ������ ������� ����, � �� ���������� ������ ����. " � ��� � 4��� ��&��� ��������� ������� ��� ������� ��� ������5��� 4������:

1. $��� ����� �� � ������� �� ������: • �������� ��������� ������ � ��� ��������� �������-������� ���� ��������;

• ���������� ���������� �������, ������� ���� ���� � ��� � ������� ����� ���� ����, ���� ����, ������� ���� ���;

• ������� ���� ���� ���� � ������� ����� ������� ������ � ������ ��������� ;

• ���������� �������� ����� � ������ ������; • ����� ���� ��������� � ���5���� �� ������� � ������ ������.

2. $��� ������� ����: • ����� ���� «�����������» ����� ������; • ��� ����� �������&�� ������; • ��������� ������� �������&�� ������; • ��������� ��������� ������� �� ���� �� � ������� ������ ������.

3. $��� ���� ����: • �������� ��������� �����, � ������ ������ � ���������� ���������� ������ �� ������� �����;

• �������� ���� ������; • �������� ���� ������ ������� � ���� ����� ���� �������� ������� �������.

4. $��� ������ � ������ ����: • ���� ����� ���� ��� �� ���� ��� ������� ����� �������;

• ����������, �������&�� � ���������� ���� �������, �� ������ ������;

• �������� �� ��� ������� � �� �������. 5. $��� 4��������&�� � ��� ������:

• �������� ������� �� ��������� ��� �� ������ ����; • ������� ���� ������ ����� � �������;

Page 17: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

17

• ������&�� ���� � ������ ���� ����� �������, ������ ������ ������, ��������� � ��������� ���������� � ����� � ����� � �������;

• �������&�� ������� � &���� ���������� �� ������ ���� �, ��� ����������, ��������� �� ����&�������� ��������.

) �������� � ��5��� ��5�� �������&�� ���������� ��� ������� ���� �����, ����� ������� ����� ������ Turbo Pascal, Turbo # ��� Visual C++. (4��� ��� �������� ��� ����&�� � �� ��� �������, �� �������&��, �������� ���� � ������ ������� ������ ��� �������� ��������� �������. 9����� ����� �� ���� ���� ���&������� ����� ����� ����������.

1. ��� ������ ����� ���� ���

2. ��� ��� ������ �����

3. ��� ��� � ������� �����

4. ��� �� ���� ���

�������&�� ������� TASM.exe

*��� �� �������

Tlink.exe

.������ �������

td.exe

prog.obj

prog.lst

prog.crf

prog.exe

����� �� �������

prog.asm

-��. 2.1. (�&��� ��������� ������� �� ����������

6� ���. 2.1 ��� ����� �5�� ����� ��&���� ��������� ������� �� ����������. 6� ����� ������ ������ ��� 4� ��&����. 6� ��� � ��� ����� �� �������. �� �� ��� ��� ������ ��� ���� ����� �� �������. .�� ��� ���� ����� � ���� � ������ �, ���� � �� ��� ��� ��������

Page 18: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

18

��� � (���&������� ��� � ������� ����). ���� ����� ����� ���������� .asm. (������, ��������5�� �������� ��� �����, ���� ���� ������� ������ ����������.

9����� ���������� �� ����� ��������� ��� ������&���� ����� Intel ����� � � ������:

� «%������������» MASM ����� Microsoft; � Turbo Assembler TASM ����� Borland.

) 4��� ����� �� �5�. (���� �������������� ����� Microsoft (MASM) ������ � � ��� ���� ����, �� � �� ���� ���������� ���� ��� �������������� (��� ������), ������� ���5�� ��� ���� ����� ����� �����. .�� ������� ��� � ��� �, �� �� ��� ��� ���� ������� ���� �����, ����� ���� ��� ����� ����� ��� ��. (���� Turbo Assembler (TASM) ��������� ���, �� ����� � � ������ �����. .��� �� 4��� ����� , ���� ����� MASM, ������� ��� �� �� ��� ������� �������������� MASM. ��� �����, ���� ����� IDEAL, ������� ���� ���� ������ ��������� ��������� ������, ���� 4������ �� ������ ���� ������ ��� �������&�� ������� � ����� � ���� �, ���������5�� �������� ���������� � ���������� ���� ��� �� ��. " 4�� ������ ���� ����������, ���� 5���, �������� � ����� ������� ��� � ������ 4������ ���� ��&���� ��������� ������ �� ����������. " ��&���� �������� ���������� ���� ����� ������ �� ����� Turbo Assembler ����� 4.1.

�� ������� ������, ���5�� ����� TASM ��������� ������ ��� ����� 4����&�� DOS. �� ������� ������ 4����&�� DOS ��������� ������� ����� ��������� ����� ��, ��������� �� ������� 2.2.

(�� ����� DOS-������ ����������� ������5�� ������:

cd «����»

'���������� ��� ������� �� ����5�� ����� �����, ��������� ��������� «����». 2��� �������� «����» ����� ����� ��� «..», � �������� ������ ����� �� �� ��� ���.

�� ���� ��� ����� ����������� ������:

«disk»:

0���� �������� «disk» ����� ���� ����5�� ������ ����� � ����� ���� ���������.

Page 19: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

19

-��. 2.2. 0����� ������ 4����&�� DOS

)���� &��& ���$����" (��� ����� ������ ������� ����� � �������� � ������

����� � ������� �� ������� ���� ��������� ������� ������� ���� �������, ��������� ��������, �������� ���, �������� ��� �������� �� ($"%.

�������&�� ������� ����������� ����� ���� �;���� �����, ����� ������� ���� ������� ����� ������ ������� �������� ���� � ������� ����� ������&��, ��������� ��� ������ � ���� �� � � ������ �������. �� �������� �;���� ����� ������� ���� ������� �� ������ �������&�� ��� ��5� ������� tasm.exe �� ������ TASM. ����� ������� ����� ��� ������� tasm.exe ������5��

TASM [�&��] ���_�����_����� [,���_�;����_�����] [,���_�����_�������] [,���_�����_������������_�����]

(��������, ����������� �����, ��� ������ ��� � �� � ������ ������������. ����� �����, ����������� �������� ������� ����� � ������ ���� ���_�����_�����. $�� ���� ����� ��������� �� ����� � ��������� ����� ���������� .asm. 0� ������ ����� ����� ����� ������� ��� ���� ��� ������������� ��������, �������5�� ����� �;���� �����, ����� ������� � ����� ������������ �����. 2��� �� ������ ��, � �� ���� ��5�� ����� �� ����� ������ ���� �������� �������&�� �������.

Page 20: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

20

2��� ���� ������ ������� �����, � ������� ����� ��� ������5��:

1. 2��� ����� �;���� �����, ����� ������� � ����� ������������ ����� ����� � ������ � ������ ����� ����� (������� �������� ������), � ���� ���� ���� ��� ������� ���� ���� 4��� ���� :

tasm.exe prog.asm , , ,

2. 2��� ����� �;���� �����, ����� ������� � ����� ������������ ����� �� ����� � ������ � ������ ����� �����, � ���� �� ���� ��5�� ������ ������� ����� ������� ����� �� ���� ��5�� ���� , � �������:

tasm.exe prog.asm , ,pr_list , " ���������� �� ����� ����� ������ ����� prog.obj pr_list.lst prog.crf

3. 2��� ��������� ������ ������� ���� , � ���� �������� ���� ������� ����� ��� �������� nul. 6�������:

tasm.exe prog.asm , ,nul. " ���������� �� ����� ����� ������ ����� prog.obj prog.crf

6������������ ������� �&�� �� ���� ���� ��� ����� ����� ���������� TASM. $��� �&�� ������� ��, � �� �� ������ ���� ��� ������&��, ����� � ������ ���� �� ������ �������� �����, ����������� �����.

(����� ��, ���� ��������&�� ������ TASM, ��������� ����������� � ������ �������� ���� ��������� ���� . (��� ��������&�� ������ ������ \TASM\BIN, �� ��������, ���� tasm.exe, ��� � ����� ����� ������� ���� . %�� ��������� ������� tasm.exe ���� �����, � ��� �������� �� ����� �;���� ���, ������� � ������������ ����� ��� ������� 4�� ������. 2��� ���� ����� ������ ���� ��� ������, � ������� �� ���� ������, � ��� ����� � ���������� ��������� ���� ��� 4�� ����� ����� ������� �������, �� ���������� ��������� ���� ����� ������&��. :��� �������� ����� �����&��, ������������ ������ (���� �5� �� �����) ������ \TASM ������� \TASM\PROGRAM, ����� ����� ���5����� ����5�� ������ ���� �����. " ���������� �� ������

Page 21: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

21

������� �����5��� ����� ��������, �� �� ������ ��� ����� ��� ������������ ������� �� �����.

(��� ��� �� ������ ������� ��������� ���� ���� �� �������&��. �� 4� ����� DOS ������� �������:

D:\TASM\BIN\tasm.exe /zi D:\TASM\Programm\<���_�������.asm>

(������� /zi �� ���� �������� �;������ ����� ��������� �������, � ����� ����� ������� ��� ����� ������ ��� ������ ��� ��������� ������� �������. " ���� �� ������ �;������ ���� ����� �������� ���� ������&�� ���� ����&��, � ����� ������, ����������� ��������� ��� ������� �������.

(�� �������� ����� ������ ���� �������� ������, �����������5�� � �����. 6������ ����� � �������� «Error» � ��������� ��� ��, �� ������� ���� �����������, � ���� ������ ����������, ������&�� ��� � . 1��� ����� ������� ��� ���������� �� ����� ����� ��������, �� �� �������, �� ��������� ����������� � ����� ���������� ��� � , ���� ���5�� �� ������� (�� ��, ��� ��������� ��������� �����). 6������ ����� «Warning» �������, �� �������&�� ������������� ��� �����, � �� �� ���� ��� ������� ��������� �����, � 4� ���� �������� �������� �������5�� ����.

�� ���������� ���� ���� ��������� ���� �� ����� ���� � ���������� ��� �����&��. %��� ����� ��� ����������� � �������� ������ ��5���� � �����. $� �������� � ������ ����� ������ �����. 0����� � ��� ���� ����� � �������� ����� ����� ������� ������� ����� � �� ����� � �� ��� ���� �����.

$�� ���� �������&�� ���� ����� ��� �������� . "-��� ��, � �� �������. "- ����, �� ���� ����� ���� ��5���� �� ���� ��� ����� �������� ������ ������� ���� ������ �����. ����� �����&�� ����� �����������, ��������, �� ������, ���� ��� ������� ����������� ����������. (�� �� ������ ���� ��������� ��� ���� ���� ������������ ����� �� ���� �� � �������� ���������� ����������, ���������� �� ��������� ������ ������&��. '���� �� 4��� ���������, ��� �������&�� ���� ����� ������ ��� ������&�� �� ���&�����, ���� ��� ���������� ����� �������. $�� ���� ����� ���������� 1.st; � ��� ����������� �� ���� �� � ���� ����������, ����� ���� ���������� ���.

Page 22: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

22

#���� ����� ������� ����� ������5�� �����:

<������_ ��������><����_�����><���5����><��������_��><�������_��>

0����: <������_ ��������> — �� ��� �������� ���������

���� ��� ��������� �����; <����_�����> – ���� ����� ����� �������. $�� �����

����������� ��� �������&�� ���� � ����� ���� ������� ��������� ������. $�� ����� ��� �� �� ���� ��� ������ ���� ������ �����. " ��� ����� � ������������ ���� �������, �� ��������� ����� ������� � INCLUDE, ����� �� ���� ������� ������ ���� ����� ��� �����. 6�����&�� ��� 4��, ��� � ������ ���������, ����� ����� �������� ��� ���� ��� ���� . ���� �������� ��� �� ����� ���� ����������� � ��������� �������� <������_ ��������> �� �����&�;

<���5����> – ���5���� ������ ����5�� ������ ��������� ������ ������� ���. $� ���5���� ���� ��� ����� � � ���� �����. "������� ���5���� �������� ��������� ��� ������&�� ������� ���;

<��������_��> – ������� ������� ����� ������ ����������, ������� ����� ����� 4�� ����� ���� <�������_��>;

<�������_��> – ����� ��� �� ����� �����.

. �������� ������� ��&���� �������&�� ��� ������ � ��5���� TASM, ���� ������ ��� ����� � ��5������ � ������ � ���������������.

'������ ���� �� ���������� �5�� ������ ���� �������� �������&�� ������5�� ��� :

a. ������� �������� — �������&��, ����� �� ���� ��� �������� ������;

b. �������� �������� — �������&��, ����� �� ��������� �������� �����, � � ������ ���������� ���������� �� �������� ������� ����� �� ��� ������ ��� ������� ������ � �����;

c. ������������ — �������&��, �����, ������ ������� ���� ��� ����� ������ ����� �������, ���� ������� ���������� ��������� �;����� ����� ����� ��������� �����, ������� ��� ��������� ����������.

Page 23: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

23

����� ������� � � ����� �� � ������ ����� ���������� ������. '� ��� ��������, ���� �� ������ ����� ������� �������� �������� ���������.

���������� ���$����" (��� � ��� �� ����� ��������� � ������ �;������

�����, ��� ���������� � ������5��� ��� — ������� �������� (�������) �����, ���, ��� �5� ���� ��� 4�� ��&���, � ���� �� �������. ��� ��� &��� 4� ��� – ������� ��� �� � ������ �;������ ������ �� ������� �������� ���������. -��������� ��&���� ��� �� �������� ����� �� � � ��� — �������&�� � ���� ��, ������ �������� ��� �, ���� ��� ��� �;������� ����� ������� ������ (���������� �� ��� ��� ��������� ������). ����� �;���� ����� �� ����, ��� ����������� ��� ���, �;������� ������� ������ ��������� ����� ������� ������ ��� �����. (�� 4�� ����&�� ���� 5��� ���� ���������� ������ ����� (����� �� ��&����� � ����������) 4��� ������. -��������� ����� ���� 5��� � ������ ������� ������� ����� � ����������� .���. (��� 4� ����&����� ������� ���� �������� ���� ���� ������ � ������� �.

���� ������ ����� ����� ������� ����� ��� ������� ���� 5���:

TLINK [�&��] �����_�;������_���� [,���_�������_�����] [,���_�����_�����] [,���_�����_���������] [,���_�����_����������] [,���_�������_�����]

0����: • �&�� – ������������� ���������, ���� ���5�� �����

���� 5���. #���� ������� ���� ����������� �&�� ��� ���� ���� ��� ������&��. *���� �&�� ����� �������� ��� ��� �� ������5�� ��� � : «-» ��� «/»;

• �����_�;������_���� – ����������� ��������, ������5�� ����� ��������� ���� � ����������� .obj. ����� ����� ���� ��������� �������� ��� ����� «+», ��������:

tlink /v prog.obj + mdf.obj + fdr.obj

(�� ���������� ����� ���� �������� ��������� ���� � ���;

• ���_�������_����� – ������������� ��������, �������5�� ��� �������� ������� �����. 2��� � ��

Page 24: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

24

������, � ��� ������� ����� ����� � ������ � ��� �� �� ������ ���� �;������ ���� ;

• ���_�����_����� – ������������� ��������, ������� ��� ���� ��� ���� 5�� ������ ���&������� ���� � ����� �������. " ��� ������������� �����, ������ ������� � ������� ��� ������ , ���5�� �������;

• ���_�����_��������� – ������������� ��������, ����� ������� ���� ��� ���� � ����� ��������� (.lib). $�� ���� �������� � ������ ����� ���&������ ������� tlib.exe ������ TASM. )������ �� ���� �;������� ���� ����������� ��������� ��� �;������ ������ ��� ����. " ���������� ��� ����� ��� ������� ����� tlink.exe ����� ������ ��� ���� �� �;������ ������ � ���� ���������, ���� ������� ������ 4�� ���������;

• ���_�����_���������� – ������������� ��������, ����� ������� ���� ��� ���� � ����� ���������� (.def);

• ���_�������_����� – ������������� ��������, ����� ������� ���� ��� ���� � ����� � ��������� Windows-��������� (.res). $�� ���� ����������� ��� ���� �� Windows-���������.

#�5��� ��� ������� ������� �������� ������� ����� ���� 5��� ����� � �����.

�� �������� ����������� ������&�� ������5���� �;����� �����, ��������� ������ ��� �������� /v, ����� �� ���� �������� ����� ���������� ���� ����� ��������� �����. ����� ������&�� � ������ �������� � ��������� ���� ��&���� ������ �������.

" �5�� ������, ��� ���� ��, ������ ����� ������� ������5�� �����:

tlink.exe /v <���_�;����_�����>

�� ���� ���$����" .������� Turbo Debugger (TD), ������������ ����� Borland

International, ������� ���� ��� ����� ����� ������ ������ �� �� �� ����� ������ �� ������ Pascal, #, ���������. .� �� ���� ������ � � �� ��� ������:

- ��������� ���� ������� �����; - ��������� ������� ������� �����. .�� ���� ��������� TD � ������ ������5��: - �������� ����������� ������� ����� ����� �����, �

���� ����� ������� ��������� �������, ��� ���� �� ��� �� ��������� ��� �������� �������&��;

- �������� ����������� ������� ������ ����� �����,

Page 25: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

25

� ���� �������� ������� � ��� ������, � ������ ����� �����;

- ������ � ��������� ������� ���������� ������ ������&����� ���� ������� �������� �������.

$� �� ���� ��������� ���� � ������� ����� �������. "��� �����, �� TD �� �� ���� ����� ����� ����� ������� ����� �������. (��� ���������� ������� ������ �����&�� ��� ��� ����������, �� �� ����� ����� ��������, ����� ����� ����� ���� �������� �� � ��������� ������� �� ��������. (��� �� ������� ����� �������� 4�� ��������� �� ����� ��������, � ���� ����� �� � ���, � ��� ������� �����, � � ��� ������ ��������� �����.

(�� ���� ����� ����� ��&��� �������� �������� �����, ��� �������� � ������ �� �� �� ����� ������, ������� ������������ ����� ����� �� ������.

1. " ������ ������� ����� ���� ��������� ��������� ����� ��� ��� � ������, � ���� �������� �������� �������. ����� ����� ���� ���� ������ ��&�����. '�� 4�� ����� ��������� ���� ������� ��&� ������� ������ � ������� ������� � END:

END ���_����� " ��� ������ ��� ������� (������ 1) ����� � ������ ������

«ira» ��&����� main. 2. '������ ����� ����� ���� ��������� �� � �&��� /zi:

tasm /zi ���_�����_�����

(��������� �&�� /zi ��������� ���������� �������� � ��� ��� �������� ���� ������� � �� ���5���� ������� ���, �� �� ��� �������� ���� ���� ������, �������� ���������� �����.

3. -������� ���� ����� ���� ���� ��5��� ��� � �&��� /v:

tlink /v ���_�;����_�����

.�&�� /v ����� ��� �� ���������� ��������� ������� ������&�� ��������� �����.

4. 0����� �������� ������ ���� ���� �� ������� ����� � ��������� �������� ����� �������, ����� ������� ������:

td ���_��������_�����

'�������� ����� �������� �������� ������ BIN ������ TASM. 2��� �� �� td.exe � ���������� ����� ��� ������� ����� ��������� ������ �������, � ������� ����� ������� ������� ���� � 4��� �����, ��������:

Page 26: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

26

td d:\Tasm\Programm\���_��������_�����.���

(�� ��� ����� �������� ������������� ��� ����� �� ������� �� �������� TD �� ��� ����� Module (���. 2.3).

-��. 2.3. .������ ������� �����

" 4�� ��� ����� ��������� ������� ����� �������. (��������� �&�� /zi � /v ��� tasm � tlink, �� ���� ���,

�� ��� �������� ������&�� � ������ � ����� ��� �� ���������� ��� �������� ������. -��� ����� 4����������� ��� ������� ���������� ����� ��� ������� 4��� �&��.

" ��� Module ��� � ����� ��� ���� ����� ������ �������� ( ��� ����������). .� ����� ��� �� ��� �� ������, ������5�� ��������. $�� ������ �������� ��� ��� ����� ( ����� ������ ��� ����� ������� ��� ��&�����). $� ��� ���� ����� �� �� ����� �������. 2��� ��������� �������� ���& ����� ������ �������, � ��� � �����, �� 4� �� ��� ������� ������ � ������� ������������� ������� � END. $� ������ ����� ���� ��5��� ��������� .# ��, �� ������ ������ ������� ��������� ���� ��� ���. " ���� ������ �������� ���� ������ ��� ���� ������� ��&����, ���������, � 4�� ������ ��� ��� � � �������� �� ��� �� ���������� ������ �� ������. .�� ��� ����� 4����� �������� ���� �������� �� ��� ������� ��. " ������ ����� ������ ���� ��� ���� ���� ���� �� �� ���. !��� ���&�� ��� ��� ���� ����� 5����� ����� ���� ����� ���� ���, ��� ������������� ����� ����� ��� ���� F6.

)��� ����� ����� �������� ������ � ��5�� ������� ����. '������ � � ���� ����� ����:

Page 27: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

27

- ��������� ��� – �������� ������ ����� 4����� � ������ ������. "�� ���� ��5��� ������ �������� ��� ��� F10, ���� �� ������� ������ ������ ����� 4� ���� (���. 2.4);

-��.2.4. (����� View ������ ���� TD

- �������� ��� – ��� ���� ��� �������� ��� �� ��� � ���� ���� ����, ���� ����� ��� �������� 4� ���. "�� ��� ����� ���� ���, 5����� ��� ��� � ����� ���� (��� ����� ���� ��� �� � ���� ��� ��� Alt+F10).

#��&����� ������ �� ���������� ��, �� ������ � �� ��� ������� �� ����&���� ���� ���, ���� ������ �� ����� �� �� �� ������&����� (���. 2.5).

-��.2.5. %��� ��� «CPU»

Page 28: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

28

(�� 4�� ���� �����, ��� ��� ��, ����������, ������ ��, �, ��� ������� ��������� ������&���� � �������� ������� � ������ � ��������� &���.

0�������� ������� �� �������� �������� ��� ��� �� ������� ����� (���. 2.6):

a. ����� ������ � ��������; b. �������� � ����; c. �������� � ����5� ������� ������; d. �������� � ����� �� ���� ����� ����.

-��.2.6. "��� ������ ������

!��� ����������� �������� &��������� ���������, ��� ��������� �������� �� �5�� � ������ �������. �� ������� ������� 4�� ������ ������� ������ ��� ��� F9. " �����, �� ������� ���� ������, �������, �� ���� �� � ���� ����� ��������� ������ � ��, ����� ��5��� ���� ����������� ����� ��. !�������� ����� �� ������� ������� ��� � �� ������. �� ������� ��� �� 4�� ������&�� ��� ������ ���� ���������� (Window > User screen), ��������, ���� ��� ��� Alt+F5.

2��� ����� ������� �� ��� ����, � �� 4�� ��� � ��������. " ������ ���� ������� �����-� �������, ��� ���� ���� ���� ������� ������� ����� �������, ����������� ��� ������5�� ������ ������.

"������� �� ����� ����������� ��� ������� �������� ����� �������. " 4�� ������ ��� ������� ������� � �������. (�� 4�� ��� ��������� ��������� ��������� ����� ������. �� ���� ���&�� 4� ������ ���� ������ ��� ��� F7

Page 29: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

29

(Run > Trace into) ��� F8 (Run > Step over). .�� 4�� ��� ��� ���� ������� ��� �� �����; ������ �� ��� ������ �� ������, ��� ���� ����� ���������� ������ ������� ��&����� ��� �� ����� ����. (�� ������ ���� ��� ��� F7 ������� ��5��� �� ������ �� ��&����� ��� ����� ���� � ������ �� � ����. 2��� �� ����������� ��� ��� F8, � �� ��&����� ��� ����� ���� ������� ����� ��� ��� ������ ������ � ���� ����� ���������� ������5�� ������ �������. 0���� ���� �������, �� ���� ��� Module ��� ����� 4�� ������ ����� ������ ��� �� CPU, �� ��� ���� ��� ����� ������� ���� ������ View > CPU (���.2.4).

.�� CPU (���.2.5) ������� ������� ������&����� � ����� �� 5 ���������� ��:

1. �� � ������ ������� ������������ ���� ���. $� �� �� ����� �������, �� � ��� Module, � ��� ������� ���. (�� �� ������ ��� ���� ���� ���� 4�� ���; ����� � ����5�� ������ ��� ��� �����;

2. Registers – �� ������ ������&�����, ������5� ����5�� �������� ������ . ( �������� ���������� ������� ���� i8086. �� � ���� ����� ����� ���� ��������� i486 ��� Pentium, ���� ������ ����� �� ���������. �� 4� ��������� 5������� ��� � ����� ���� ������ ����� ������ ��� �� � ������ ���� � ������ ��� ������ Registers 32-bit-Yes;

3. �� ��� , ���� ������� ����5�� ������� ��� ������&����� �� ���� �� � �� ������������� ��� ������;

4. �� ����� Stack, ������5� �������� ������, �������� ��� �����. !���� ������ ����� ����������� ��������� ������ SS � SP;

5. �� ����� ������ �� ������ Dump, ������5�� �������� ������ ������ � ������, ����� ���������� �� ������� , ��������� �� � ����� ���. " ��� ��� � ����� �������� ���� ���� ������ ������. �� 4� ���� ������� ����, ��� ���� � 5����� ��� � ����� ����, ������ ������ ������.

6������ �� 4��� ���������� �� ��� � ���� �� 4���� ������. )����� ������� � ������� ������ ��� Module, ��� � � ������������ ����� ������� ��� CPU. 6 � �� ���� ���� ������ ��� � ������� ������&�����, �������� ������&�� �� ���� ��� CPU. # ������� ������� �� Module � CPU ��� ������� � ������ ������ ���� View, ���� ������� ������ ������ ����� ���������� �� CPU.

Page 30: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

30

"������� �� ������ ������� ������� �� ���� ������� ������� � ����, ������� � ���� ��� ����� �������. $�� ����� &��������� ������ ��� �� ������, ���� ���������� ���� ��� ������� ����&���� ���� ����� ������� �������. �� ���� ���&�� 4� ������ ������� ����� ��� ����� �� ������ ����� ������� � ������ ��� ��� F4. (������ ������ �������� � ���� ���� �� �������� ������, �� ����� ��. ���� ��� ������ ��� ��� ���������� ��� �� �����.

"������� � ���������� �� � �������� �� ���� ������� ������� � ���� �� �� ��� ����������� �� ��� �������� (breakpoints). (���� ��������� ������� ������� ����� ��� 4�� ���� �������, ��� �� ������� ������� ������ ����� � ������ ��� ��� F2. "�������� ����� ��� ��� ����� ����� & ���. )���� ������ ����� ���� ����� ���� ��� ������ – ��� 4� ���� � ��� ������ ������ ����� � ������ ��� ��� F2. (��� ����� �� ���� ����� ���� ������� ����������� �� �������� ��� ���� F9. 6� ��� � ���� ����� ���� ������� ���� ����. ������ ��� �������� ������� ������&����� � ������, � ����� �������� �������� �������. #������ 4� ��� ��� ��� � ������, ��� ����� ������� � ������5�� ���� ����� ����.

(��� ��� �������� ������� ���� �� 4��� ����� ���, ���� Ctrl+F2.

6� �� � ���������� ��������� ��� ������� ������5�� � ��.

1. " ���������� ����� ���������� (������� TASM) �������� ������ �������, ������5�� ����������� ������&�� �������: �;������ ��, ��5���� �������������� ������, �����&� ��� � � �.�.

2. ,����� �������&�� ������� � ������ ���������� �������������� ���� � �����&�� �;���� �����. (��� �������� ������� �;���� �����, ������� ������� ����� ���. �� 4� ����������� ������� TLINK, ���5�� ���� ������ TASM. .�� �� �� ��� �� ���������� – ���������� ������ �����.

3. -��������� ����� ������� TLINK � ������ ��� ������ ��������� (����������) �����, ����5�� ���������� .exe. �� ������ ������� ����� ����������� Turbo Debugger, ���5�� ���� ������ TASM.

4. (��� ������ � ���������� ������� ��� ��� ������ ��������� ����� � ������ �� ������� �������, � � � ���������.

Page 31: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

31

3. Windows-�(� �*�� � & ���$�����������& �� &+"�� Assembler

+��� Assembler � ������ ����� �� �� ����� �������� ����, ������������ � ����� �������� �� . *�� ��� ��, ������� �� ����� Assembler ���� �� ����� ����� � ��������, � ����� � ��5�� ��������� ���� ����� ���� �������� �� . .���� ��5��� ��� ��� ������-�����, ������� ��5�� � �������&�� ��&���� ��������� �������, �� ������ � �������� ���� ������ ����� ���� �����. ����� ���� ���������� ���� ���� ���� ������ � ��5�� �������� ASM EDITOR, � ����� ������&�� ���� ���� ���� ����� �� ������� ����� � ��5�� ����������� ������ TASM.EXE � TLINK.EXE.

�� ����� �� �������� ASM EDITOR �� ($"%, � ����� ��� ��������� ������ ����� ����� ����� ��������� � ��5���� ���� ��� �����, ���������� ��� ������ �� ������� 3.1:

-��.3.1. -��������� ���� � �����

(��� ������� ���� ����� ���� ���� ���� ������ �� ������� ���� �� ��������� ����� D (���.3.2.). (���� ��� ������ �� ����� ��������� ������� � ������ �����.

Page 32: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

32

-��. 3.2. *��� �� ��������� ��� ������ ��

(��� ��&���� ������ �� ��������� Tasm �� ����� D "��� ��������� ����� ��������� �� �����, ��������� ��� ���������� ����� (���.3.3.).

-��.3.3. #�������� ����� � ������� �������

�� ������� �������� ���������� ��� ��������� ����� ASM_ED.exe, ����� �������� ��������� D:\Tasm (���. 3.3). 6� ������� 3.4 ������ �5�� ����, � ����� ������ File, ���� ������� � ����� � ����������� ��� �������, ��������� � � �� �� ������ ������� ���� �����.

Page 33: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

33

-��. 3.4. %��� ���� ASM Editor

6� ������� 3.5 ������ ������ ������� ������ �� ���������. *�� ��� �� ������� ��5��� ��� ������� ������ ������ �������:

- (�� �� ������ �������� ��� ���������� �������&�� ������� ��� �;������ ����, � ����� � ������&�� ��������� �����. ����� ����� ������ ������� �&�� ������� ��� ���� ����� Turbo Debugger-�, ����� � � ������ �� ���� �� ��� ����� �������� ����. 0����� �������5� ���� ��� �������� �������5� ��� ��� � ����� ��������.

-��. 3.5. %��� ������� ������

- "��� ������ �������� ���, �� �� ������ ����� ��� ��������� ��� ������ ��������� ����� ������� � ���� ��������� ���� ���� � ������. (��� ����� � ���� ��� ��������� �������� �������, ��� ������ ��5���� � ������ �� ���� ������� ����� (���� ������� �� ��� ��� ��� ��������� ����� � ��5� �������&�� � ������&�� ������� ���).

Page 34: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

34

- (������� ������ �������� ������ �� ���� ��� ����� ������� � ��&���� ������ ������� ����� ������ Turbo Debugger ( ����� ������ ��&���� �������&�� � ������&�� ������ � ���� �����), ��� ��������� ��������� ����� �� ���������, ��� ������ ��������� ����� ��� � ��������.

6� ������� 3.6 ������� ��� �5�� �� �������� ��&���� ��������� ������� �� ����� Assembler.

-��. 3.6. .�5�� �� ��� ��������

����� ������� ����������� ���, ���� ������ ��� �������� ����. .�� ��� �� �� �� � ��������� ��� ��� �����. #�5��� ��� ������� ������������ ����� ���� ���� «DOS» � «Windows». *��� 4� ���� �������� �� ������ �� �� ������� ������� ����� ����� (���. 3.7). ����� ������� ��������� ��� ���� �� ������, ��� ������ ����� �� ��������� MS-DOS ����� ������� ����� ������ � ���� �� Windows.

*��� 4�, �� ���. 3.7 ������� ����� ������ ���� ��� ���� (Find) � ������ (Replace). .�&�� Find �� ���� ����� ������� ��������� ����� ��� (���� ������ ��� ��� ������ ������, ��� �������� ����� ��������� ������ �����, ��� ���������), � �&�� Replace ���� ���� �������� ( ��� �����) ������ �������� ����� �� ����� �������� ���� ������. ����� ����&�� ����� ��� � ��������� ����� � ������ ���� ���������� ��� ����������, �� ������ ������ � ����������� ���������.

Page 35: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

35

-��.3.7. *� ����&�� ������ ASM

-������ ASM Editor ������� ����&�� � �� ��������. #�5��� ��� ���� ���� , ������5�� ���� ���� ������&�� (���.3.8)

-��.3.8. "�� ���� ��� ������&��

�� �� � ���� �� ��� ����� ����� �� ��� ���� �������, ���� Tools -> Help.

Page 36: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

36

4. %�������� ���$����" �� �����( ��� (������ �� ����� ���������� ������� ���� ��� � �������

��� ������, ���� ����� ��������� ������. (������ ���� ������ �� �� ��� ��������� ����� ��� -������ . *����� ������ ������� � ������� ���������� �����, ����� �� ����� �������� �������� ����� ��� �������.

(��������� ���������� �� ��� ������� ��� : • ������� ��� ����������, ������� ���5�� ���

��� �������� ����� �������� �����. " ��&���� �������&�� �������&�� ���������� ������������ �� ���� ��5�� ������ ������� ����� ������&�����;

• ������������ (���������) — ��������� ����������� ����� ���������� ������ �������, ����5����� ���� �������&�� ������ ������������;

• ��������, � ���5���� ��������� ���������� ���������� �� �������� ������� ����� ��. ) ������� ��� ���� ������� ������� �����;

• ������ ����������, ������5�� ����� ��� ��, �� ����� � ��� � ����� ���� ���. *��������� ���������� ����������.

%�������� �����( ��� (���������, ���� ���5�� �������, ��� ������� ����

��� �������������� �������&��, �� ���� ��5�� ������ (���.3.1, �), ���������� (���.3.1, �), ������� � (���.3.1, �) ��� ���������� (���.3.1, ).

6� ������� ������� ������5�� ���������: �� ���� — ������������, ��������� ��� � ������ �����

��� ����� � ���������� ����� ������ �������, ���� � ��������;

�� — ������������, ������5�� ������ ������� � � ����� ��������� ������� . " ���������� ������� ���������� ���������� ������� � 4��� ����� ��� ���� ���� ��� ����������� ��������������;

��� ������� (#$%) � �������� — 4� ������������ ��������� �� ���� ��5�� ������� ������, ���������� ��� ������� � ����������;

������� — ����� ������, ���������� ��� ������� � ����������, �������5�� �;����, ��� ������ ���� ����� ����� ��. .������� ���������� ���� ����� ���������� � ���� ��� � ����� ��� ����������, ������� � ���������������

Page 37: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

37

���������� � ������ ����� ���� ����&�� � ������� ������� �� ����� �� .

a) ����� ����� � ���������

�) ����� �������

) ����� ���������� ����������

-��.3.1. #������������� �������&�� ����� Assembler

��������� ��� ���� ��� ��������� ������ ������ � ������:

• �� ��������� ��� �: A-Z, a-z. (�� 4�� ���� ��� � ������� ��� � ��������� 4� � ���������;

• &���� � 0 � 9; • ����� ?, @, $, _, &; • ����������� , . [ ] ( ) < > { } + / * % ! ' " ? \ = # ^. (��������� ���������� ���������� �� ����,

������� ���5�� ��� ������������� ������������ ����� ��������� ��������� ��� � �����, ����5�� ����� ��� ����������.

1�������� � ������: 1. ����� ������� — ����� ��������� ��������� ��� � , ��������5���� ��� ��������� ����� �;��� �������, ��� ��� ����&��, ����� ���������� � ��� ���� ����. '����������� ���� ������ �� �� ��� ��������� ��� � . " ������ � ��� � ��� ������ ��� ��� � ������� ���� ���, &���� � ������� ���&������� ����� — _, ?, $, @. '����������� �� ���� ���������� ��� �� &����. ���� ������������� ���� ���� � 255 ��� � , ���

Page 38: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

38

��������� ���������� ���� ��� �� 32, � �������� ��������. -����� ��� ����� ������ ������������ ��� � ������ ����� �&�� ������� ����� mv. *��� 4� ��5��� ��� ������� ������� ���������� �� �, ���� � �������� �������� � ������� ��� � ��� ����� �� �� �������� (�� � �������� � ��������). �� 4� ����������� �&�� ������� ����� /mu, /ml, /mx;

2. ��� �� �������� — ����� ��������� ��� � , ����������� �������� ��� � ���� �� ����;

3. ��� ���� ��� �� ������5�� ������ ���������: ���� ���, ���� ���, ����������� ���. .������ ����� ����� ��� ������ �� �������� �� ���������� ���� ����� � ����������� ��� ����: ���������� ����� �� ������� ��� � � ������ ����� �������� �����-��� ������������ ��� � , �������� 25 ��� 139; ��� ������ ����� ������ ������ ������� � ����� ����� ������� ���� ������ ����� � �����&, ���5�� �� ���� , ���� ��� �������� “b”; �� ��&� ����� ��������� �������&��������� &���, ���� ���5�� �������&�������� ����, ������ ��� ��������� ��� � “h” � ���� �������&�������� ���� ���������� � ��� �, � ����� ��� ������ ����� ���5�� ���: 0ef15h.

*���� ���������� ������� ������� �;����, ��� ����� ��� ��� ��5� ��� ��������� ������ ����� ��. $�� �;���� ���� ����� ���������. $������ — &�� ��'��� (������� ��� ��, ������� ��� ��� �����), �� ������ �������� ���������� ��� ��������, ���� &�� ��'���, ������ ������� ��� ��� ��� ������ ���������� ��� �������.

.������� � ������ 4������������ ����������, �� ����� ���������� ����� ������� ������, �������5�� �;����, ��� ������ ��������� ����&��. " ���� �5�� ������ ������� ��� ����� ��� ���� ��� ����� ���� ������ ���� ����, ���� ����� ���������. "������ ���������� ����� ���������� �������� � ���������, ������������� ��� ���� ���.

.������� �� ��� ������5�� ��� : 1. !������������� ������� 2. .������� �� �� 3. .������� ��� ����� 4. 1������� �������

Page 39: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

39

5. '�������� ������ 6. .������ �������������� ���� 7. .������ �������������� ������� 8. .������ ���� ���� ���� ��������� 9. .������ �������� �������� ���� ���5�� ������ ��������

10. .������ �������� ���5���� ��������

1. !������������� ������� (���.3.2). * ��� �������: a) ������� “+” � “–”; b) �������� “+” � “–”; c) �������� “*”; d) &��������� ������� “/”; e) �������� ������ � ������� “mod”.

-��. 3.2. #�������� �������������� ����&��

(�����: tab_size equ 50 ;������ ����� � ������ size_el equ 2 ;������ 4������ ... ; ���������� ���� 4������ ����� � � ��������

������ cx mov cx,tab_size / size_el ;������ ”/ ”

2. $������� ������ ������� �� � �������� �� �������� ������� ������ (���.3.3).

-��. 3.3. #�������� ������ �� ��

(�����: mask_b equ 10111011 ... mov al,mask_b shr 3 ;���� ����&�� al=00010111

Page 40: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

40

3. $������� ������� ( � ��5��� �������� “������” ��� “���”) ������������� ��� ����� ���� �������� �������� (���.3.4).

-��. 3.4. #�������� ������ ��� �����

1������ �������� “������” �� ���� ��� &��� � �����&�, � “���” — ����.

(�����: tab_size equ 30 ;������ �����&� ... mov al,tab_size ge 50 ;������� ������� �����&� al cmp al,0 ;���� tab_size < 50, � je m1 ;������ �� m1 ... m1: ... " 4�� ������� ���� �������� tab_size ����� ��� �� � 50, �

��������� al �� �� 0ffh, � ���� tab_size ������ 50, � al �� � 00h. *����� cmp ��� �� ��� �������� al � ����� � ������ �� ��� �� ���� ��5�� ���� flags/eflags. *����� je �� �� � ������� 4��� ��� �������� ��� �� �������� ���� ����� �� ����� m1.

�����&� 1. .������� ��� ����� .������ 0�������

eq '#�'6!, ���� ��������_1 �� � ��������_2 ne '#�'6!, ���� ��������_1 �� �� � ��������_2 lt '#�'6!, ���� ��������_1 ������

��������_2>'#�'6!, ���� ��������_1 �� �� � ��������_2

le '#�'6!, ���� ��������_1 ������ ��� �� � ��������_2

gt '#�'6!, ���� ��������_1 ����� ��������_2 ge '#�'6!, ���� ��������_1 ����� ��� �� �

��������_2

4. (��� ��� �������� ������� ��� ���������� ���� �� ����&��. "�������� ����� ���� ����������, � ����

Page 41: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

41

������, �������� �������� ����� ���� ���� ������� ���������� (���.3.5).

-��. 3.5. #�������� �������� ������

(�����: flags equ 10010011 ; mov al,flags ��������� al ��� flags � �� ����� ����� ��� �� ���� xor 01h ; ; ���� ����&�� al=10010010

5. )������� ������� [ ]. ��������� ������� � �������� ���� ���������� ��� �������� ������ �������� ��������_1 �� 4���� ������� � ��������_2, ����������� ����� (���.3.6)

-��. 3.6. #�������� ������� �������

(�����: mov ax,mas[si] ;��������� �� � � ������ mas+(si)

������ ax " ���������� � ���������� ����� ������ ������5��

���������: ��� ������ ���� ���� �������� �������, � � ��� ���� ����� ������ �����. 0����� ����������� ������� �������� ������� mas + (si) ������� ��������� ������5� ��������: �������� ���5���� ��� ������ ����� mas ���� �������� ������� si.

6. $������ ��������� ���� ptr ����������� ��� �������������� ��� �������� ���� ����� ��� ���������, ����������� ��������� (���.3.7).

-��. 3.7. #�������� ������� �������������� ����

��� ���� ��������� �� �� ������5�� ��������: byte, word, dword, qword, tbyte, near, far.

(�����: d_wrd dd 0 ...

Page 42: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

42

mov al,byte ptr d_wrd+1 ;��������� �� ����� �� � �� �� �

(��������� d_wrd ����� ��� � �� �� �. :� ������, ���� ������� ���������� ���5���� �� � ��� ���������, � ���� � ���� �� ���5�� ��� ���� (��������, � ����)? 2��� ��������� ������� 4� ������ mov al,d_wrd+1, � ��������� ����� ��5���� ��� ������� ��� ������ . .������ ptr �� ���� ��������� ��� ������ ������������� ��� � ������� ������.

7. $������ ��������� ������ : (� �����) ����� ���� �������� ���������� ����� ��������� ������� ���� ���� �������� ���� ���5��: “��� ������� �������”, “��� �������” �� �� ���� ��5�� ������� � SEGMENT ��� “��� �����” (���.3.8).

-��. 3.8. #�������� ������� �������������� �������

%� ��� ������� ���� ��� ������ �� �������, �������� �������� ���� ��������� �� ����������. %�����&���� ��������� � ��������� ��������, �� 4�� ���� � ������ ��������, � ���������� ����� ����������� ��������� � ����� ������ �� �������� �� �������� �� �� �����. 6��������� �� ���� ����� (���������) ������ ����� ��, ���� ������� ������&����� �� �, �� �� ��������� ������ ��� ������ � ��������. #����� ����� ������������� ������, ����� ������� ��������� ������ ������� ����������� ���� cs:ip, � ������� ����� � ������ — ���. �� 4� � ������������ ������ “:”. ��������� ����������, ������� �� 4�� ������, �������� �� ���� ��5�� ������ �� ������� ������ �������.

(�����: .code ... jmp met1 ;��� ���������, ����� ��� ind �����

����� �����

Page 43: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

43

;��� �������� ������ ind db 5 ;������� ��� ������ ������� ����� met1: ... mov al,cs:ind ;�������������� ������� �� ����

������� � ;�������, ������������ ����� ������� ��� $������ �������� ���� ��������� . (����) ����� ����� ����

��������� ���� ���� ����������� ���������, ���� � ���������� ��������.

8. $������ ���� �� �������� ���������� ����� ������� seg � ��5��� ���������� ����� ������� ��� ��������, ������ � ��� ��� �������� �����, ����������, ��� �������, ��� ����� ��� ������ ��� ������� ��� (���.3.9).

-��. 3.9. #�������� ������� �������� ��������

���� ���5��

9. $������ ���� �� ����� ������� offset �� ���� ������� �������� ���5���� �������� ������ ��������� ������ � �������, ���� �������� �������� (3.10).

-��. 3.10. #�������� ������� �������� ���5����

(�����: .data pole dw 5 ... .code ... mov ax,seg pole mov es,ax mov dx,offset pole ;������ ���� es:dx ����� ����� pole *�� � ������ ��� �� ��, �������� ������

���������� ��� ��������� �������� ��5��� ������ �� ���� �� � �� ����������� (��. ����. 2).

�����&� 2. .������� � �� �������� .������ (�������

length, size, width, mask, (, ), [, ], <, > 1 . 2

Page 44: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

44

.������ (������� : 3 ptr, offset, seg, type, this 4 high, low 5 +, - (�������) 6 *, /, mod, shl, shr 7 +, -, (��������) 8 eq, ne, lt, le, gt, ge 9 not 10 and 11 or, xor 12 short, type 13

.����&�� � ����� ��� ����������� ��������� ����� ������ ��� � ����� . '�������� ������ �������� ���� ����� ������� �� ������ ����, ����� ����� ��� ����� ��������.

������"� �������" ���������& ���$����" �� &+"�� Assembler

�� ������ ������, ������5�� � ���� ������� ��� ���, ������ � �����, ���������� MASM � TASM ��� ������� ������ ���� ��������� ������� ���������. �� ���� ����� �����5����� � ������� ����� ������ ����� ������ ��� ������� � �������� ����� ������ MODEL, ����� ������� ����� ���� ���� �����5����� ������ � ������� ����&�� ������� � ASSUME (�4��� ��� ������ ���� ���5����� ������� �������&�� ������� � ASSUME ��� �� ������ ���). $�� ������� � � ��� ��� �������, ����� ������ ������ ���� ���5����� ������� �������&�� ����� ��������������� �����, � ���������� ��������� (��� � � ���&������� ��� ds ��������� �� �� �).

(�����: masm ;����� ����� TASM: ideal ��� masm model small ;����� ������ .data ;������ ������ message db '" ����� � � �������&��������� &����,$' .stack ;������ ����� db 256 dup ('?') ;������ ������� ����� .code ;������ ��� main proc ;����� ��&����� main mov ax,@data ;������ ����� ������� ������ ; ������ ax

Page 45: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

45

mov ds,ax ;ax ds (���������� ����� �) ... mov ax,4c00h ;��������� 4c00h ������ ax int 21h ; �� ����� ���� � ����� 21h main endp ;���& ��&����� main end main ;���& ������� � ���� ��� main

#�������� ������� � MODEL ������ �� ������� 3.11.

-��. 3.11. #�������� ������� � MODEL

.����������� ��������� ������� � MODEL � ������ ����� ����� (����.5). $�� �������� ��������� ����� �������&�� ������ ��� ������� �����. (�����������, �� ��������� ����� ���� ����� ���� ����������� ���� ������ , ����� ����������� ���������� ���� ����� ���������� ���������� ������� �������. $�� ������� � ��� ����� ����.3.

�����&� 3. )��5����� ������� � ���������� ������� ����� ������� �

(����� MASM)

����� ������� �

(����� IDEAL)

6���������

.CODE [���] CODESEG[���] 6���� ��� ��������� ������� ���

.DATA DATASEG 6���� ��� ��������� ������� ���&������� ����� ������. ����� ����������� ��� ���������� ������ ���� near

.CONST CONST 6���� ��� ��������� ������� �������� ������ (�������) �����

.DATA? UDATASEG 6���� ��� ��������� ������� �����&������� ����� ������. ����� ����������� ��� ���������� ������ ���� near

.STACK [������]

STACK [������]

6���� ��� ��������� ������� ����� �����. (������� [������] ������ ������ �����

Page 46: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

46

����� ������� �

(����� MASM)

����� ������� �

(����� IDEAL)

6���������

.FARDATA [���]

FARDATA [���]

6���� ��� ��������� ������� ���&������� ����� ������ ���� far

.FARDATA? [���]

UFARDATA [���]

6���� ��� ��������� ������� �����&������� ����� ������ ���� far

6������ ������� ������� �� ��������� [��&] ��� ��, �� ���� ���������� ��������� ������ 4� ����. # ���� �����, ������� ��������� �� ������ ������ ���� ��� ���� ����� ��������� � ��������� � �������� ����������� ���� ��� �� ��, ����� ������ ������ ������� ������ ��� ���&������� ����� � �����&������� ����� ������, � ����� �������.

(�� ������ ���� ������� � MODEL ��������� ������ ��������� ������� ������������ , � ����� ��� ���5����� ���� ����� �������, � ���, ���� ������� ������&�� ��� ��� ���� ��������������� ����� ����� ������ (��. ����. 5). " �����&� 4 ����������� �������� �������������.

�����&� 4. '������������, ���� ����� ������� � MODEL '��

������������� 0������� ���������

@code ���������� ����� ������� ��� @data ���������� ����� ������� ������ ���� near

@fardata ���������� ����� ������� ������ ���� far @fardata? ���������� ����� �������

�����&������� ����� ������ ���� far @curseg ���������� ����� �������

�����&������� ����� ������ ���� far @stack ���������� ����� ������� �����

.������� ������� � MODEL ��������� ��� ������� ����� ������, ����� ��������� ���� ������ �������, ������� ������ ������ � ���, ���� � ��� ���� ������ � ��������� ������ .

" ����. 5 ��� ����� ������� �������� ��������� ����� ����� ������� � MODEL.

Page 47: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

47

(������� ��������� ������� � MODEL �� ���� ������� ������� �������� ������ ���� ������� ����� ������ (����.6).

�����&� 5. %���� ������ %���� ���

��� ���

������ 6��������� �����

TINY near near *� � ������ �;������� ��� ����� � ������ DGROUP. '���������� ��� ������� ������ ������ .com.

SMALL near near *� �������� ��� ������, ������ �;������� ��� ����� � ������ DGROUP. $�� ����� ���� ��������� ��� �������� � ������ �� ����������

MEDIUM

far near *� �������� ������� ������ , � ���� �� ������ �;��������� ��������� �����. "�� ������ �� �������� ���� ����� — ���� far. ����� �;������� ��� �����; �� ������ �� ��� — ���� near

COMPACT

near far *� ��� �������; ������ �� ������ — ���� far

LARGE far far *� ��������� ��������, � ���� �� ������ �;��������� ��������� �����

�����&� 6. %��������� ����� ������ 0�������

���������� 6���������

use16 #������ ������� ����� ����������� ��� 16-������ (���� �� ���� ��5�� ������� � ������ ��&���� i80386 ��� i80486)

use32 #������ ������� ����� ����������� ��� 32-������ (���� �� ���� ��5�� ������� � ������ ��&���� i80386 ��� i80486)

dos (������ ����� ������� MS-DOS

6������������ ��������� ��� � ���� ������ ���� ��������� ������� �������� �� � ��&����. 6��������� ������ ���� 4��� �������� �� ������ ��� ��������� � � ��� ���� ������ �� ��������� ������ �������� ����.

Page 48: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

48

.�������� ��� �������� �������� �������&�� ������� ��� � �������� ���������� ���� � ���&������ «!���������� $<% � ������». .���� ���� ������ ��� ���� ������ ��� ����������� ������� �, �������� ����� ���� ���� ��5��� ��� ���� ������������ ����� ������� . ���������� �������� �����������, ��� ��������� ������ ������� ����� ������ ��� �����5����� ������ ������ � �� ������� ����� � ��������� ����� ������.

*������� �������� &��������� ������ ��� ��� ������ ������ � ������, ��������������� ��� � ��� ���� � ���������� �������, ����������� �� ������ ��� �� ��. $� �� ���� ���� 5��� 4������ � � ��� ��� ����� ������ ���� �� ���� �����������&�� � ���� � ���� �����.

Page 49: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

49

5. ������& ���$����� �� &+"�� Assembler " �� ���� �� � �������, ��� ������� ��� � ������, ���

������� ������ �������, ��5��� ���5�� ������ ����&�� ��� ��������� ������&����� � ��������� ����� ������.

-�������� ������� �� ����� ��������� � ������ ����� ���5����� ������� �������&�� ���������� � �������� ���� ������ ����&���� ����, ����� ����� ������ ��� �������. "��� ������ ����&���� ���� MASM �� ���� ��� ����������� ������&����� 8086. ����� ����� ����&���� ���� ���� ���� ������ �� ��� �������� �� ����� ���������� ����. ����� ��� �������� ���������� ���� ���������� ������ ���� ������ IDEAL, ����&���� ���� ��� ���� ���� ������ �� ����������� ���� ���������� �����.

*�� ��� ������ ����� ������ ������� ��������� ����� ����&���� ���� Turbo Assembler-�.

masm ; ��� ������ ����� ���� ����������: MASM ��� ; IDEAL

*� � �� «masm» �������, �� ��� ����� ����� ����&���� ���� MASM. ���� � ������ �������� ����� ����������, ����� ����� ������ �� ������� ��� �� ������&��. ���� ���� ����� ����� ������, ����������� ��� �������� ������� ���� �����.

model small ; ��� ����� ������

" ����� ������ �������� ����� ������� �� ������� ������ ������� 64*� ��� �����5���� ��� �������, � ����� � ���� ������� ������ ��� �����5���� ������ � ������&�� ���� � ������. ���� ������� ������� �����, ����� ���� ���� ������ �� ���������� ��� �������� ������.

.stack 100h ; ���������� ������� ����� (���. ����� ����� ; ���5����� SS)

-����� ����� �������� ������ ����������� 100H ����� ( ��������� ������ ��������� 256 ����� ������). (���� �� ��� �� ��� stack, data, code ���� ��� ����� ����, ����� �������� ������ �������&�� ����� ���������.

#�����5�� �������&�� ��������� ����� ������� ������.

.data ; ����� ������� ������

(��� �� �� � data ������� �;� ����� ����������, �� ��� , � ����� ���&������&�� ��������� ���������, ���� ���� �����.

message db '(����� ������� $' ; ���� �� ����������

Page 50: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

50

��� ��� ����������� ($"% �� ������� ��� ���� �� ��������, ������ ����� ����� ��5��� ���� ������� ����� ������. *����� ��� � ����� ����� ������� ��� ASCII, ����� ������ ������� ������, ������� � ��� � ������, ����������5�� ������� ������. #��� ������, ������� ���������� ����� ������ ����� ����� �������� ������ � 0000H � 0011H, �� 18 ����� ������. .���� ��� �������, �� ���������� message ��� ��� � �� � ������. " �5�� ������ ����� ���������� ���������� – 4� ��������� �� ������ ������, ����� ������� ��������� ������, ��� 4� ��������� �� ��� �� ������ ������ �� �����, ����� ������� ��������� ������&��.

���� �������� ���������� per_1, ������ ���� ����������� ��� ���� � ��5�� �� �� � db. #������ ��������� �������� �������� �������� 0b3h ( ��������� ������ ���� 11). " ������� ������ ���� ������ ����������� ��� 0012h.

per_1 db 0b3h ; ���������� ������� 1 ����

0���� 0 ������ ����� ������ �����, ��� ��� ���� ���������� � ������, � h �������, �� ���� ������� ��� �������&�������� ������� ���������.

#�����5�� ���������� � ������ �������������� ���������. " ������� ������ ������ ����� ������&�� ����� �����5���, ������� � ������ ������ 0013h, ��� 4�� ������� ���� ����� �����5�� � ������ 0013h, � ������� �� ���� ��� � ������ 0016h. 0����� ���������� ������ $"% ���� ��5��� ������ ���� � ���� , �.�. ������� ���5����� ������� ����, � ����� ������� � �.�.

per_2 dd 0e341624ah ; ���������� ������� 4 ����� per_3 dw ? ; ����� �� ���� ����� (2 �����) �� per_3

2��� ���������� ������, � �� ���&������� ���, � ��� �������� �������� ������ ����� ���� ?, �� � � ������ ���� ��� ������ ���������� ���� �������� (���� ������ �������&�� ������� ����� �� ���� ����� �� ���������� � ���������� ������� ����� ������� �����, �4��� �������� ��������� ���� ���� ����� � ����). -���� ���� �������� ������ � �������� 0017h � 0018h.

���� ������ ������ ������� ����� � �� 10 ��������� ����������. %���� �������� �����. (��� ������ ����� �� ���� ������ �� �������� ����� .

mas db 10 dup (?) ; 10 ���������� ������� 1 ���� adr dw per_2 ; ������ adr �������� ���5���� per_2

Page 51: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

51

2��� ��� ������� ��������� ������ � ������ ����� ������ ��� ��� ������� ����� ���������, � �������� ���� ���� ��������� ����� ������� ����� ���������, �������� ���&�� ������. 1��� ����� ����� �� � �� ���� ���5��: ������� �����, ������5�� ��������� ���� ���5�� � ������� �����, ������5�� ���5���� ��������� ������ �������. " �������, �������� ��� ���������� adr ����� �������� ���5���� ��������� per_2 ��������� ������ ������� ������, ��� ��� ���������� �������� ��� � ��������� �������. " �������, �������� ����, ���������� adr_all ����� �������� ��������� ���� ���5�� ��������� per_2, � ����� ���5���� �� ���������� ��������� ������� ������. (�� 4�� ������� ���� ���� (0024h � 0025h)����� �������� ���5����, � ������� ���� ���� (0026h � 0027h) ��������� ���� ���5��.

adr_all dd per_2 ; ���������� adr_all ����� �������� ����� ; ����� per_2

(��� ������� ������� ������ ���������� ������� ������� ��� �������. #������ ����� � ������ ������� ������� ��� ������ ���, � ������ ��� � ������ ���;������ ������ ���� �������.

.code ; ����� ������� ��� ira: ; ��� ��&����� (��� �������)

'�� �� �� ��&����� ��� ����� ��� ��� ���&����� �� � «main», �� ������ �������. '�� ��&����� ������� ���� �����. .����������� ��� ��� � ������ �������� ������� ��&����� �������� �������, �� ������ � �������� �������� ������� ��� �� �� ��&�����.

#�����5�� � � ������ �������&�� ����� ���������� � ������ ������������ ��� ��������� ������, ��������5�� ������ ������. ����� �������&�� � ������ ���������� ������� ������ ��� �������. 2��� ������ �������&�� ������ ���, � ��������� ������ DS ����� ����� ��� �� ������ ������, �� �� ���� ��5�� ������� ������ ���� �����.

mov ax, @data ; ax ���5����� ����� ������ ������� ������ mov ds, ax ; ����������� ������ ������

:��� ��� ��������� ������� �� ����� ���������� ��������� ��������� ����� ������ ������, ������5�� �����-��� ������. *����� ������ ������ ����� � � ���������� ������������, ����� ����� ���������� �������. " ����� ������ �� ������������� ��� ������� ��� ��������� ���������-�������. �� ���������� ������ ������, ����� ���5�� �������� ���������

Page 52: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

52

���, ����� ����� ������� offset. " ������5�� ������ ������ ������ ���� ���� �������.

mov di, offset per_3 ; ������ di ����� ��������� per_3

0���� ������ di, ����� � ������ �������&������������ ���5����� �������� ������, �� ����������� ���������� per_3. !���� ����������� ��������� ������ ������� ������.

*����� �� ������ ��&����� Intel ��� ��� � ��������� �� � � ������� 8-�� ���������. (��� �� ������ �� ���� ��������� ��� � �������� ����� �������, ��� � � �������� ����� ������. #�����5�� ������ �� ���� �������� ������� ���� ������� cx �������� 3. 2��� ������ ��� ��� � h ���� �������� ��������, ���5��� ������, ��� ����������, � ��&���� �������, �� ����� ���� ������� ��������� ������� ���������, � ������, �� ���� ���, � � ���� ��� �������&��������� ������� ��������� ��� ������&�� ����&�� ������.

mov cl,3 ; ������ cl ������ ����� 3

-����� cx ����� ������������ � ��� � ��� ���� ����� ������� �� ����� ���������. �� ������&�� &��� ��� ������ ��� ������ loop (!����). 2��� ��&����, ��� �������� �������, �������� ������ ������, � � �������������� (��������� �� �����&�) �������� ������� cx, � �����, ���� �������� cx ����� ����, �������� � ������, ��������� ����� ������.

�� ������&�� �� ����� ������� ����� ��������� ����������� ���&������� ��� ������ – �����. %���� – 4� ��� ���� ��������� ������ ������, ��� �������� ����� �������� ���, ����� ��������� �������� �������� ������� ��� �������� ������ ��� �, ��� ������ � ������ .

m0: ; ����� m0

���� ������� ������� �������� ������ ������� «����� � ����� � �», � �� ������ ��������� ������: ���� 23h ������ ����� ������ al, � ����, ������5���� ������� bl ��������� ������ ah.

xor ax,ax ; ��������� ����&�� ����� � ����� 2 mov al,23h ; ������ ����� 23h ������� ������� (al) ; ������� ax mov ah,bl ; ���� ���� ������ �������� bl ah

���� ������� ���� ����� ������ ������5�� �������������� ����&��. (�� �� ������ ��������� ��������

Page 53: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

53

������� ax � ����� 30h, � ��������� ����&�� ���5����� ������ ax, ����5�� ��� 4�� � ��������. ���� ������� ������ �������� �� ������� ax, � ����� ������ ������ ������ dx �������&���������� ��������. ���� �������� �� ������� dx ����������� � ��������� ax � ��������� ���5����� ������ ax.

add ax,30h ; ������ ���� ������� ax � ����� 30h sub ax,30h ; ������ �� ax ���� 30h mov dx,0030h ; �������� ������ dx ���� 0030h add ax,dx ; ������ ���� ax � ��������� ������� bx

*�� ��� �� ��� ������� ������ , ��� �������� ���� ����&�� ��������� ���5����� ������, ��������� ��� � ��� ������ .

#�����5�� �������&�� �� ���� ������ ����������� ��� ������&�� �� ����� ������� ���� �����. #������ ��� �� ������ , ����� ������ ������ dx, ���5����� ��������, � ����� ��������� ���� ���� ����&�� ��� ����� (��� ��). "��� ������ ��5��� ���� ��� ����� ������� ������ ax � dx ��� ���5���� ���������� ������� �5� ����������. .������ cmp ������� �� ax �������� ������� dx � �������� ���� ������� ��&����� �� ������� � �������� ����&��. ������ ������ � ������ ������� ��� � �������. 9�� � «c» ����� ��� �������-��� ��, ����� ����������� ��� ������&�� �� ����� (������� �����, ��� �������). 2��� �������� ax �����, ��� �� � dx ���� ������ ���. " ���� �� ������ ���� ������ ������� ����� � ��������� ��� ��� ������ �� ����� m1.

mov dx,1253h ; ������ ������ dx ����� 1253h cmp ax,dx ; ��� ����� ������� ������� ax � dx j� m1 ; ������ �� m1, ���� ax<dx

���� ������� ���� ����&��, ����� ��&���� ������, ���� ��� �� �� �������� (���� ax>=dx). (�� �� ������ � ������ ������� ������5����, � ������ – ������� ������ � �������, �.�. ������ ��5��� ������ ����, ��� ��&���� �������� ������ jmp. (����� ��5��� ������ �� ����� ��������� ��� �������. .������ and ������� �������� ����&�� «'» ��� � ��� ���������.

mov dl,80h ; ������ ������� ������� (dl) ������� dx ; ����� 80h and al,dl ; �������� ����&�� ' ��� ��������� al � dl jmp m2 ; ������ ��� ������ �� ����� m2

Page 54: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

54

���� ������� ���� ������, �������� ���. 0���� � �� � ������ ������ ������� ����&�� «'1'» (������ OR).

m1: ; ����� m1 mov dh,80h ; ������ dh ����� 80h or al,dh ; �������� ����&�� '1' ��� ��������� a � dh m2: ; ����� m2

-���� ������ cl ��� �����5�� ��������, ���� ����� ������ �� ������� �����. 2��� ����� �������� ��������� �������� ��� ���������� ���������, ���� ����� ����� ����� (� ��� �������� ������ �������). # ��5�� ������� push ��� ���������� �������� �������&���������� ������� �����.

push cx ; ������ ������� ������� cx ����

*������&�� �� ������5�� � �� ������ �� ���� ��5��� ��� ���� �� �� � ������� ������� ax �� 12 ������ . #��� � ������ cl ������ ����� �������� �� � . 0���� ������ rol, �������� �������� ������� cx, ���� ��� N �� � ������� ������� ax, �� N ����������� ��������� �� ������� cx (���� ch ��� �������� ������ � ����, � cx ���������� �� ch � cl ����� � ��5���� 4��� ���� ���5��). #� � ������� ������� ax ��������� ���� � ���� (����������� �������� ��� ������� rol).

mov cl,12 ; ������ cl ����� 12 ��������� rol ax,cl ; �� � ������� ������� ax �� ������� cl

.������ pop ������ �� ����� �������� ������ ����� � ������� ������ cx. (�� 4�� ��������� ����� ���5����� �� � � ������, � �������� ����� ������, �� �������� �������� cx ������� �����������.

pop cx ; ������ �� ����� ������� � �������� cx

-����, � ��� ������� �������, ������ di ��� ���5�� ����� ������ ������, � ������ �� ���������� per_3. #�����5�� ������ ������ ��� ������ ������, ����� ���� ��������� ������� di, �������� ������� ax. (�� 4�� ������� ����� ������� ax (al) ����� ���5��� � ������ di, � ������� ����� ax (ah) – � ������ di+1. (�� ����������� ���� ������� di (inc di) �������� ������� di � ��������� �� 2, ��� ��� ���� ���� ����� ������ � ������� �������� �� ������� ax. " ������&����� Intel ��5��� ��� � � �������� �������: si � di. (�� ���5���� � ������ ��������, ����������� � �������� �����, �������� ���5���� � ������ �

Page 55: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

55

������, ����������� ��������� ������ ������ . (�� ���5���� � ������ �������� ��� ������ ���� � �������� ����, �������� �������&�� ������� �������� ������ .

mov [di], ax ; ������ ������� ax � ������ di inc di ; ����������� ���� ������� di

���� �� ������5�� ���� ������ ��� ����� ���.

loop m0 ; ������ �� ����� m0, ���� cx �� �� � ���� ; (cx=cx-1) push ax ; ������ ������� ax ���� mov al,24h ; ������ ������� ������� (al) ������� ax ; ����� 24h mov [di],al ; �������� �������� al ������ � ������ di pop ax ; ������ �� �����

���� �� ������� lea �������� ����� �� ������� offset. 0���� ������ dx ���5����� ����� ������ ������, � ������ �� ���������� per_3. (�������� ���� �������&�� ����������� ��� � �� �� 4���� ������ ����� ��� � , ��� ����� ���5��� ������ ������ ������� � ������, ����� ���� ����������� ��������� per_3. (�� �������� ������� int �������� ����� ���� �������� ������� ���� ����� � ��� ����� ��������� ������ ���� ����� ����, ���� ��� ������ ������ � ������� ������� int ( ����� ������ – 21h). (�� �� � ��������� ������ ���� ����� ���� ������� ����� �������� ������� ax (��� ��� �� ���� ������ ����� – ah). " ������ ah ���5����� ���� ����&��, ����� ����� ������� ��������� ������ ���� ����� ����. *����� ����&�� ������� ��� � � �������� ���� ������� , ����� ���������� ��������� ������ ���� ����� ���� � ��5�� ������ �5� ����������. " ����� ������ ��� ����� ����&�� 9h ����� ���� 21h, ����� ������� ������ � � � �������� ���� ��� � ������ ������, ����������5�� �����, � ���� �� 4����. (�� � �� ����� �� 4���� ����� ������ $"% ����� ������� ����� ��� �� $. �� 4� ����� ������ � ������ di ��� ���5�� ���� 24h, ��� ��� �� ��� �� ����� – 24h (����� ������ di ��� .������� ����� ������ ������, ������5�� ���������� per_3).

lea dx,per_3 ; ������ ������ dx ���5���� ��������� per_3 mov ah,9h ; ������ ������� ������� ������� ax ����� 9h int 21h ; �� ����� ���� 21h

#�����5�� �������&�� �� ���� ������ �� ���� � ���� �� 4���� ��� �, �� ��� ��������� ������� al. ����&�� 02h

Page 56: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

56

����� ���� 21h � ��� �� 4���� ��� �, �� ��� ���5�� ������ dl � �� � ����� ����.

mov dl,al ; ������ dl ������� al mov ah,02h ; ������ ah ����� 02h int 21h ; �� ����� ���� 21h

�� ���� �� ������� ���� �����, ��� �� �������� ������ masm, ����� ��������� ����������� ����&�� 4ch, ��� 4�� ������� ���� ������� al ����� ���� ������. ����� �������&�� � ������ ���������� ��� ��������� �� ������ �� ���� �� � ��������� �������.

mov ax,4c00h ; ������ ������ ax ����� 4�00h int 21h ; �� ����� ���� 21h

�� �������� ��������� ��&� ������ ����������� ������� � end.

end ira ; ������� ��&����� ira

����� �����, ������� �� ����� Assembler ����� ������� ��� ������� 1.

1����� 1 masm model small .stack 100h .data message db '(����� ������� $' per_1 db 0b3h per_2 dd 0e341624ah per_3 dw ? mas db 10 dup (?) adr dw per_2 ; adr_all dd per_2 .code ira: mov ax, @data mov ds, ax mov di, offset per_3 mov cl,3 m0: xor ax,ax mov al,23h mov ah,bl

Page 57: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

57

1����� 1 add ax,30h sub ax,30h mov dx,0030h add ax,dx mov dx,1253h cmp ax,dx j� m1 mov dl,80h and al,dl jmp m2 m1: mov dh,80h or al,dh m2: push cx mov cl,12 rol ax,cl pop cx mov [di], ax inc di loop m0 push ax mov al,24h mov [di],al pop ax lea dx,per_3 mov ah,9h int 21h mov dl,al mov ah,02h int 21h mov ax,4c00h int 21h end ira

(������ ������ ������� � ������ ������ ������� ������ ���� ������ ����� Assembler. *��������� ��� ��������� ������� �� ����� ����� ���������� � ���� � ������ («;»). (��� ���� ����� ������� ����� ����������, ����� ��������� �� ������������ ��� �� ������� � ���� ���� ������� �� ��� �����, ��� ���� � ���������.

Page 58: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

58

6. ������& � �(�������"� ��(����. 1��������� ����� ��������� �� ($"%, �����

� �������, � � �� ����&�������� ��������, � �������������� �������� �� ���� ��&����� Intel. (�� �������� ���������� ���� ��������������� ������ ��� ����� TASM ��� �������&�� � ������&�� ������������ ������. "�� �������, ��� ������ ��� ������ ���������� ����, ��� ���� ������ � ������ ����� ������ MASM � ����� ������ small. (�� �������� ���������� ���� ��� ������ ��� ���������� ��������� ��� ��������� ������, ����� ��� ����� ���, � ����� DOS ����� ��� ������� ������, ���5�� ���� ������ TASM.

� � ��� � � � 1 +�� ������������ ������: '������� ��������� ��&����� Intel 8086, � �� �

�������� ����.

,���� ��� �������: '������� ������� ������ ��� ������������ ��������, �

����� ������� ������ ������ ������ ���������� � �������� ���������� ������� ����� ������� ��������� ������&����� Inlet 8086. " ���������� �������� ����������� ����� ������� ����� �����:

− ��������� ������&����� Intel 8086; − ���������� ���5�� �� ��� � ������� ; − ������� ������&����� � �� �� �� ����������; − ��������� � ���������� ������� ��� ; − ��������� ������ � �������� ����&��� �������&��; − ����&�� ����� ����; − ������ ������&��; − ����� ��������� ��������� ������ �� ����� !���������; − ���������� ������, ���5�� ����� Turbo Assembler.

-����� �� ������������ ������: 0�5��� ��������� ����� ���� ������ ������ ����

������ ����. �� ��5��� ��������� ����� ������� ����� ����� � ��� �� ������5�� �������� ��� .

1. .�� ��� ���� � ������� ($"%. 2. #�������� &�������� ��&�����. 3. 2����&� ������&�� $"%. 4. -������ ��&����� Intel 8086. -������ �5� ����������. #��� � ����������.

Page 59: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

59

5. -������ ��&����� Intel 8086. #�������� �������. #��� � ����������.

6. -������ ��&����� Intel 8086. -����� ��� . #��� � ����������.

7. (���&�� �������&�� ������. !����� ����� ���� ������� ������.

8. #���. 6��������� � �� ��� ����&��� ������ ����. 9. (���� ����. 6���������, ������ ����� ����, ����&�� ��&����� �� ����� ���� ����� ����.

10. -����� ������&��. (�� ���� �������. 11. $���� ��������� ������� �� ����� Assembler. 12. (�&��� ��������� ������� �� Assembler. 13. �������&�� �������. 6���������, �� ��� �&��. 14. *��� �� �������. 6���������, �� ��� ����&��. 15. .������ �������. 6���������, ������ ������, ���������� �� Dump � Registers.

16. ���� ���������� ����� Assembler. 17. #������������� �������&�� ����� Assembler. 18. 1������ ����� Assembler. 19. ���� ������ ����� Assembler. (�� ���� �������. 20. )��5����� ������� � ���������� �������. 21. %���� ������, ����������� ����� Assembler.

( ����������� ��5��� ��������� ����� ������� ���� ���� ���5�� � �������� �������5�� ���������� ����.

� � ��� � � � 2 +�� ������������ ������: '������� ����� �������� ���� �� ����� Assembler.

. ������� �� ����� ��� ��, �������&��, ������&�� � ������ ������������ ������.

,���� ��� �������: '������� ������� ������ ��� ������������ ��������,

��� ��� ���� ������� �� ����� Assembler �� ���� �� � ������� 1 �� 5- ������ ���� ��������� �����.

-����� �� ������������ ������: 0�������� ���� ASM_Ed, ����� ��������� ������ Tasm

����� d. .������ ��� ������ ���� � ������� �������&�� � ������&�� ��� ���� �����. ���� ��������� Turbo Debugger �� ��������� ASM_Ed. (� ����� ��� ������� ����&���� ���� �������. " ������ ����� ���� ���� ����� ��� ��� ������

Page 60: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

60

��������� �� � � ����� ������. " ������ ������ ������� ������� &����� ��������� �� ��������.

"�������� ������� ��� � ������, �������� Turbo Debugger ��� ������ ���� ������� ������ � ����� ������. .�;������ ��������� ������� ����� ������ � ������ ��� �������� �������.

"�������� ��&��� �������&��, ������&�� � ������ �������, �������� DOS-��.

1. 0�������� tasm.exe �� ������� ����� 2. 0�������� tlink.exe �� ������� ����� 3. 0�������� td.exe � &����� ��, �����5���� ��� Turbo

Debugger 4. ( ����� �� 4����, ���� � �&���� /zi ��� tasm.exe � /v ���

tlink.exe. 5. .&����� ��������� �� Turbo Debugger.

" ����� ��������� ����� ����� ���� ������� �� ��������� ����� �� � ���������� �� ��������.

� � ��� � � � 3 +�� ������������ ������: .���������� � ��������� ������&����� Intel.

����� ���� ������ � ������ � �� ������&�� �� 4����, � ����� �������� 4����������� ����&�� � �����������, ��������� �������.

,���� ��� �������: 1���� ������&������� ������� ������� �� ���� �� �

����&��� ���� ���� ������&��. $� ��� ���������� �� ����� �������. 2��� ���� ����� �������� ��� ��� �� ��� ������, ��&���� ���������� �� �� (���.6.1).

*�� ������ ���� �����

!������

%���� ���� �����

!1)

(����� )������ ��- � ��

*�� ��� �

:��� �� ������

-��. 6.1. (������� ������ ��&���� ��- � ��

Page 61: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

61

*�� ������� ��� � ����� ������� ��- � �� �������� ������ ��&����� (�������). ���� ��� ��� � ��������� �������� ������ �� ������, ��� ���� ���� ��� ���� �����-��� ����� ��. 6�������, �� ����� ��� ��� ������� ������� ���� ����� ��� ����, ���� ������������� ������� ��� ���. �� 4� ��������� �� ���� �� � �� � �����&� ��� � ��������� �� ��� �� &����, ������ � ��� ������. ���� ��������� ������� ��� �� &���� �� 4� � ������� ��������. 6�������, ��� ������� &���� «3» ������ ������&����� ������� �� «33h» �� ���� �� � �� � �����&��. #��� ������, ��� ������� ���� ��� ��� �� ���� ��������� ������ �� ��� ��� ��, ����� � ��� ������, ���� «30h». (�� � �� ����� �� 4���� ��������� ������ &���� ����� ������� ��� �� ��� ��, ������5� ������ &����, � ����� �������� ����� ������ �� ���, ����������5�� �����, �� ����� ���� �����. .��� �� ������ � �� ������������ ����� ������ �� ������� 6.2. ����� ������ � ������ �� ������ �����. "����� ������ ����� ���� ������ $"% �����, ������5�� ��� ��� � , �� ���� ��5�� &����� �����, � ����� � � ����� �� 4���� ���� �����. ����� ����� ����&�� ������ ���� . (��� ����� ��� ������� ���������� ���� � �� ������&��.

�� ������� � �� �����, ������� ������ ���������� ������ ������, ��������� ������� ��� ������ ����� � ���������� ������� � ��� � ����� � ��������� ������� � ���. �� �������&�� ������� ��� ������ ��� ������ ��� ������� ������ ���� ����� �������. .��� �� ��� �� � ����� �� ������ ���� ������� ������� ���� ���� ptr (���. 3.7), � ��� �� � ��� � ������ ������&�����. -������, ��� �� ����, ��� ���� ������� ���� ��� � �������� ��� (ax), ��� ��� ������ ����� (ah) � ������ ����� (al). #��� ������, ��� ��� ������� ���� ����� �� ������� � �������� �������� ������ (al) �������� ������� �����, � ������ (ah) ���� � ��������. " ��� ������ (ax) ����� �������� ��������� ������� ����.

(�� �������� �������������� � �������� ����&�� ��������� ��� ��� ����� �������� ���������� ����&�� ������&�����. ����� ��� ��� � �5�� ����������, �4��� ��� ������ ��� ����������� �������� ����������. -�������� ������������� ����&�� ��������� � ���� �� 4���� ���� ����� � ��5�� �������, ��� ����� �����.

Page 62: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

62

6����

"����� ����� ����� ������� (ax) �� (per)

#��5���� &���� ��� � ��5�� �� �� (ax) �� 12 ��� ���

"�������� ��� � &���� � ��5�� �������� ����� (0F000h) �� (ax)

(��� � ������5�� &���� �� ��� �� ���&�� ��� �, ����� �� �� ������� (ax) �� ������ ���� ��

2��� �� 4���� � ����� ��

&����

*��&

0����� ����� ���������� (per)

(������� ��� &���� ������� (al) �����

������ ���� ������� (al) � ����� 30h

"� � �� 4���� ����� �� � ����� ���� 21h

(�� �� � �� �� 4���� ��� ��, �� ��� ��������� (al), �����

���� ���� ������� (al) (dl) � ������ ��� ����&�� � �� �� 4���� (ax)

"����� ����� ����� ������� (ax) �� (per)

#�������� (ax) (per)

! 62�

-��. 6.2. !����� � �� ������������ �����

������ ���� ����������� ������� � ������ ��� �� ���� ��� ����&�� ��&���� ��������� ������� ����������.

Page 63: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

63

�� ������ ����, ��� ��� ��, ��������� ����� ���� ���� , �� ���5�� ���� ���� &����� ��������� ��������� ����&��.

(�����: ��������� ���������� ���� ��� ������ ���� ������� ���,

������5� ������5�� ����� ��: a+(b∧c). ������, �� ���� ��� �� ������� ������� ���

���� ��� ����: a1=12h, b1=7h, c1=70h; a2=12h, b2=82h; c2=38h; a3=8h, b3=CEh; c3=35h. (�� ������ ���� ��� ������ ��������� 12h ��� ����

�������.

#��� ������, ��� �������, �� ���� ����� ������ ���

���� ��� �������, ��� ��� �������� ���� ������, ����� ��� � �� �� ��������� ��� ������ ��������� ��� ���, ����� ������� �� ����������.

(�� �������� ��������� ����� ������������ ������ ��� ����&�� DOS, ��� ������� �����&� 6.1.

�����&� 6.1. ����&�� DOS (����� ���� int 21h)

�+��*���� ���� ,������

���� �"���

" � ��� �� � �������� � 4���� ���-���� (���������� �� 4�����)

ah=01h al=ASCII-�� ��� ��

"� � ��� �� ah=02h dl=ASCII-�� ��� �� " � ��� �� � �������� � ��� 4���� ���-���

ah=07h ah=08h

dl=ASCII-�� ��� �� al=ASCII-�� ��� �� (����&�� 08h ��� �� �� �����, �� ����� �� CRTL-BREAK)

7h= 00000111b AND

70h= 01110000b 00h= 00000000b

82h= 10000010b AND

38h= 00111000b 00h= 00000000b

CEh= 11001110b AND

35h= 00110101b 04h= 00000100b

Page 64: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

64

�+��*���� ���� ,������

���� �"���

"� � ����� �� 4����

ah=09h ds:dx=����� ����� � ��� �� «$» �� ��&�

" � ����� � ��� ������

ah=0ah ds:dx=����� ������ ��� ��; ��� �� ���� ������ – ������� ������� ����� ��� � (�������� ���� ������); ��� ���� – ������ ������ ������� ��� � ( ������� ������); ������ � �������5�� ����� – ��� ��� � ������� � ��� ������

" ������� ����� ������ � ����� ds:dx � ������� ������ ������� ��� � ������� dl

(� ���� ������� ������ ��� ������

ah=0bh al=0 – ����� ���� al+0ffh – ������ ���� ��� ��

(����� ������ ���� ����� ���� int 21h. 0������: ��������� � ���� �� 4���� �� ��� ��, ������5����

��������� sum, ���������� ���� ���� ���� 1 ����. -������:

mov dl, sum mov ah, 02h int 21h

-��������: �� 4����� �� ����� ��� �, ASCII-�� ��� ��������� ��������� sum.

0��������: (�� � �� �� 4���� ������� ���� ���������, ��� ������ ������, ��� �������, ��������� ���� ���� ���� ����� � �. ������, �� ���� ���� ����� �� ����� ������5�� ��� �� ���� �������&��������� &���, ��������� ���� ���� ������� ���� ����� &���� �� 4� � �������� �� � ����� ��������� ������ �� ������� ��- � ��. �� 4� � �������&�������� &����, ������� ����� ��������� &���� ��� ����� ��� ���� 30h, � � �������&�������� &����, ������� �����

Page 65: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

65

�������� ��� ��� ���� 37h. " �����&� 6.2 ��� ���� ���� ASCII-�� ��� ��� � , ����������� ��� ����� � 4����� � ��� ������.

���� ��� ���� ������ � �� �� 4���� ������� ��������� sum. " ����� ������ ���������� sum �� �� b3.

(�����: .data sum db 0b3h .code prog: mov ax, @data mov ds, ax mov al, sum and al,0f0h ror al, 4 add al, 37h mov dl, al mov ah, 02h int 21h mov al, sum and al,0fh add al, 30h mov dl, al mov ah,02h int 21h mov ax, 4c00h int 21h end prog

" ��� ��������, ��� ����� ��� ���, �� 4����� �� ���� � � ��� �� «B» � «3».

*� ����� ������� � ������ ���� ��������� � ��������� ��� �������� ���������� ����. " ����� ������� ��� �������� � ������� � ������ ����� ������ , ����� ��� ���� ������ ��� ������� ��� &��������� ������&�� �������. $� �� ��� �� �������� ��������� ��, � ����� ������� ������� ������ ��� ������� ���� ���������.

" ����� ������ ������� � ���� �� 4���� ����������, ����5�� �� � �� &���. 2��� ������� &��� ����� � ������, ���������� ���� ��������� ��� �������. #��� ������, ������ ������� �� ���� ���� ��� ��������. .�� ���� ���� ������ ��� ������ � ������ ��� �������&�� ���� ������ ������ .

Page 66: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

�����&� 6.2. �(�� ASCII-����� ����� ��

�� 3 ��� #�� �� 3 ��� #�� �� 3 ��� #�� �� 3 ��� #�� 000 00h 6��� 032 20h sp 064 40h @ 096 60h ` 001 01h 6���� ��� �� 033 21h ! 065 41h A 097 61h a 002 02h 6���� ������ 034 22h " 066 42h B 098 62h b 003 03h *��& ������ 035 23h # 067 43h C 099 63h c 004 04h *��& �������� 036 24h $ 068 44h D 100 64h d 005 05h *�% 037 25h % 069 45h E 101 65h e 006 06h � 038 26h & 070 46h F 102 66h f 007 07h 0 �� 039 27h ' 071 47h G 103 67h g 008 08h "� ��� �� �� 040 28h ( 072 48h H 104 68h h 009 09h ����.������&�� 041 29h ) 073 49h I 105 69h i 010 0Ah (��� � ����� 042 2Ah * 074 4Ah J 106 6Ah j 011 0Bh "���.������&�� 043 2Bh + 075 4Bh K 107 6Bh k 012 0Ch (��� � ������&� 044 2Ch , 076 4Ch L 108 6Ch l 013 0Dh "� ��� ������� 045 2Dh - 077 4Dh M 109 6Dh m 014 0Eh Shift out 046 2Eh . 078 4Eh N 110 6Eh n 015 0Fh Shift in 047 2Fh / 079 4Fh O 111 6Fh o 016 10h Data line esc 048 30h 0 080 50h P 112 70h p 017 11h )��� ����� 1 049 31h 1 081 51h Q 113 71h q 018 12h )��� ����� 2 050 32h 2 082 52h R 114 72h r 019 13h )��� ����� 3 051 33h 3 083 53h S 115 73h s 020 14h )��� ����� 4 052 34h 4 084 54h T 116 74h t 021 15h 6�� 053 35h 5 085 55h U 117 75h u 022 16h #��������&�� 054 36h 6 086 56h V 118 76h v 023 17h *��& ���� 055 37h 7 087 57h W 119 77h w 024 18h !����� ���� 056 38h 8 088 58h X 120 78h x 025 19h End of medium 057 39h 9 089 59h Y 121 79h y 026 1Ah 0����� 058 3Ah : 090 5Ah Z 122 7Ah z 027 1Bh Escape 059 3Bh ; 091 5Bh [ 123 7Bh { 028 1Ch -�����.����� 060 3Ch < 092 5Ch \ 124 7Ch | 029 1Dh -�����.����� 061 3Dh = 093 5Dh ] 125 7Dh } 030 1Eh -�����.������ 062 3Eh > 094 5Eh ^ 126 7Eh ~ 031 1Fh -�����.�����&� 063 3Fh ? 095 5Fh _ 127 7Fh 0���

Page 67: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

67

-����� �� ������������ ������: 1. "� ���� �� 4���� ������ ������ 4����&�� DOS �������

� �� ������ �� ���� �� � ������� ������� (�����&� 6.3).

�����&� 6.3. "������ -������ "������ -������ "������ -������

1 ax, bl 11 sp, bh 21 bp, dh 2 dx, ah 12 di, bh 22 si, bx 3 cx, bh 13 cx, bp 23 di, al 4 bx,cl 14 ax, dh 24 sp, si 5 di, dh 15 si, al 25 cx, dl 6 bx, al 16 sp, ax 26 ax, bh 7 dx, si 17 bx, si 27 si, cl 8 cx, ax 18 bx, dh 28 di, ch 9 sp, bp 19 cx, al 29 bx, dl

10 bp, al 20 ax, bp 30 sp, dx

2��� ��� � �� �������� ������� �� � ���� �� ��������, � ������������ ��� ������� (��� �� � ��� ������) ������� ������ ������ ������ ���� ��� ��������.

2. 0����� ������� ��� ������� ������ ����������, � � �� ����� ����� ��������� � � � � ��������� (�����&� 6.4).

�����&� 6.4 "��-�

1 ���� 2 �����

"��-�

1 ���� 2 �����

"��-�

1 ���� 2 �����

1 a, b, c, d 11 a, b, c, d 21 a, b, c, d 2 a, c b, d 12 a, c b, d 22 a, c b, d 3 a, d b, c 13 a, d b, c 23 a, d b, c 4 b, c a, d 14 b, c a, d 24 b, c a, d 5 b, d a, c 15 b, d a, c 25 b, d a, c 6 c, d a, b 16 c, d a, b 26 c, d a, b 7 a, b, c, d 17 a, b, c, d 27 a, b, c, d 8 a, c b, d 18 a, c b, d 28 a, c b, d 9 a, d b, c 19 a, d b, c 29 a, d b, c 10 b, c a, d 20 b, c a, d 30 b, c a, d

-��������� ������� �������� 4����������� ����&�� ��� ��������� ����� ������� �� ���� �� � ������� ������� (�����&� 6.5.).

�����&� 6.5. "��-� -������ "��-� -������ "��-� -������

1 (a+b)∧(c-d) 11 (a+b)-(c⊕d) 21 (a∨c)∧(a⊕b⊕d) 2 (a∨c)-(b⊕d) 12 (a⊕b)-(d⊕c) 22 ((a+b)⊕(c+d)) ∨a 3 (a-c)∨(b⊕d) 13 (a∧b∨c)⊕d 23 (a∨b∨c)⊕(c+d) 4 a⊕b∨(c-d) 14 (a+b+c)∨d 24 (a⊕d)+(c⊕(-b)) 5 a+b-(c⊕d) 15 (a-b-c)∨d 25 a⊕b⊕c⊕d

Page 68: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

68

"��-� -������ "��-� -������ "��-� -������ 6 (a∨b)+(c∨d)⊕a 16 (a∨c)+(b∨d) 26 (a+b-d)∨(c+d) 7 (a+b)⊕(c-a-d) 17 (a+c)∨(b⊕d) 27 (a∨c∨d)∧(a+b) 8 a⊕b⊕(c+a+d) 18 (a∨b)+(d∧c) 28 (a⊕d)+(c⊕d)-b 9 (a-b)⊕(c⊕d)-a 19 (a+b+c)⊕d 29 (a-b)⊕(a-c)⊕(a-d)

10 (a-b)⊕(d∨c) 20 (a-c)⊕b-(b∨d) 30 ((a+b)-(b∨d))⊕a

" �����&� ������� ������5�� ���������: ⊕ – ����&�� ������ ���� «� ����� � �» (XOR); ∧ – �������� ����&�� �������� «'» (AND); ∨ – 1������� ����&�� ������� «'1'» (OR).

(�� �������� ������ 2 ��������� ������ �������� �������� ����&�� ���������-������� ������� � ������&�����. ����� ��������� ������ ���� ������� ������� ������ �������� ����� (��������� ���� ���� ��� ������ ������ ����� ������ �������� �������������� ����&��).

3. �� �� ���� ������������ ������� ��������� ���� ��� ����, ������� ��5�� ��������� ������� ����� ��������� .

����� �� ������: 0�5��� ��������� ����� ���� ����� �� �� � ��� �����

�������. �� ��5��� ��������� ������� ��� �� ������� �� ����� ����������, ���� �;������ ������ ����� �������, ������� �������� ������ ��� ������� ����� �� $"%, � ����� �� ���� ������ �����, �;���� ������������ ��������� ��.

� � ��� � � � 4 +�� ������������ ������: '������� � ������� ���� ������ ���� ��������� �����

Assembler, �� ���� �� �������� �������� � ��������� �� �������, � ����� ������&�� ����������� ���� , ������5�� ��������� � ����������.

,���� ��� �������: "�� � �������� ������� ��������� ����� � ��������

����&��� – ������� ���� ����� �� ��� ��� ��������� �������� ������, ���� ����� �������������� ��� ����������, � ��� �� �� �������, ����� ��� ��� 4�� ��&����� �� ��������, ������ �� �� ���� ����� ��&�����. (��� �� ������� ����� ��&����� ���� ����� � ��5����� �� �� �������, � �� �������� ���������� � ������, ������5�� �� ������ �� � ���������.

������ � ��� ����� � ������ ������� ��������� ������ ���������� ����� �;��� ��������� ����&������ ����������� �������. *��� �, 4�� ��������� ��� ������ ��� ����� ��������, �� ������� � �������� ���� ������ �������

Page 69: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

69

���. " � ������� � ���� ������� ��������, �� ������ �������, ��� ����� ������ �������� ����� , �� ���� ��� ����� 64*, ���� ������, ��� ��������� ������ � �;��� ��� ���� 64*, ���� �� ������ ��� ������ ����&���.

+��� �������� ���� !��������� ������� ��� ���������� ��&���� � �� ��� – ������� (near) � ������� (far).

(�&����� ������ ���� ����� ��������� �� �� �������, �� � ��� ��5�� �������. ������ ��� ��&����� �������, �� � ��� ��� ���5����� �� ��� ��� �� �������.

(�� �� � ��&����� ����� ���������� ����� � ���� ��� ��5�� �������:

− ��� �� � ������� ��&����� – �� , ������5�� ���5���� ���� �� � ��������� ����5� �� �������;

− ��� �� � ������� ��&����� – �� , ������5�� ����� �������, ���� ��������� ���� � ����, � �� , ������5�� ���5���� ���� � ���� 4�� �������.

" �5�� ������ ����� �����, ������5�� ���������, ��� ����� �� ������� ������ �������. �� ����� � �������� ����� !��������� ��&����� ������ ������� ���&������� �����. .������� ��&����� ����� ������5�� ���������:

���_��&����� PROC �������� ���_��&����� ���_��&����� ENDP

#������ ������� �������, �� ������� � PROC ���� ����� �� ��� ���� � �����, ��� ��� ��������� �����.

(�������, ����� ����� ���� ����� �� � PROC, ��������� ��� ��&�����: ������� (NEAR) ��� ������� (FAR). 2��� �������� ������ ���, � � �������� ��&����� ��������� �������.

" �5�� ������, �����5��� ��������� ���� ������� ��� �� ���, � ��� 4�� ������� ������, �� ���� � ���� ��������� ��������� �� �����, � ����� ��������� ���� ��� ���5���� � ���. (4��� ��������� ������ �����5��� ��� ��&� ������� ���, ���� ����� �� ������� �������, ��� ���� ������ ������� ���, ����� ���� ��� �������. " ������ �������� ��������� ������ �����5��� ������� �� � �������.

(�� ������ ���� ���5���� ����� �������� ���� �� ����� Assembler ��� ��������� ���� ���� �����5�� ��� ������ ������� ��� � �;� ����� ����� �� �� ��&�����, ��� ��&� ������� ��� � �;� ����� ��&� �� �� ��&�����, � ���� ���������� ��� ���� �� ������� (���. 6.3).

Page 70: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

70

masm model small .data .�;� ����� ���������� .code

prog:

��� ������� mov ax, 4c00h int 21h end prog

Name_proc PROC ��� ���������

Name_proc PROCP

masm model small .data .�;� ����� ���������� .code

prog: ��� ������� mov ax, 4c00h int 21h

end prog

Name_proc PROC ��� ���������

Name_proc PROCP

-��.6.3. -����5���� ��� ��������� ���� �������

%��� � ��������� � ������������. (����� ��� ����������� ��������� ��&����� ��� ����������

�������. (�������� ���� – �������� �������� ����� �������: �� ��� ������� ������ ��� ��������� �����-��� �������, � ��&����� � ���� ���������� �� ������ �� �� 4��� ������ � ��������� � �� �����. ���� ���� ����� ��� �� �� ��������: ������ ��� ��������� ����� ������� ��� ���� �� ���� (���� ��, � ���� �� � ���� ������ ). -����� 4� ������� ���, ������ �� ��������� ����� ����. " 4�� ������ �� ��� ������� ������ ��� ��������� ���� � ��� ��� ���������, ��������� ������� � ����������� �, � ��5�� ���� �����, ��5��� ����.

"���� ������������ � ������� �� ������������. �� ����� � ����������� ������� ����� ��&����� �������

���&������� ������, 4� �� ��������� CALL � � ��� ���� ����� RET.

"�� ������ �� � CALL ������ ��. "�������������� �� NEAR CALL ����������� ��� �������� ���� ����� ��&�����, �����5���� �� �� �������. .� ����� ��� � � �������� ������� IP � �������� ����� �������� �������� ����� (IP) ����� ������ � ������ � ����. %����������� �� FAR CALL ����������� ��� �������� ���� ����� ��&�����, �����5���� ���� ������� ��� ���� �������� �����. .� ������ � �� �������� ������� CS � ���5���� IP ��� ��������� �������� ������� � �������� ����� ��� ������ IP, ��� � ������ CS. ���� ��� ���� ������ �� � ���������, �������� ������ ��� �� �� �������.

call ���_��������

"�� � ���� RET � ������ �� ������ ���������, ������� �� ������ ����� ������� �� ������ �����. "�������������� � ��� �� ������ �� ����� �� �� � ���5��� � ������ IP, � ������������ � ��� �� ������ �� ����� � � �� �, ���5�� �� � �� ������ ������

Page 71: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

71

������ IP, � �� �� ����� ������ – ������ CS. *����� RET ���� ����� ������, ����� ������� ���� ��� ��������, ����� ����� ������&����� � ��������� ��������� ����� SP ���� �� ������� ������ � ���� (������ �����). .������ � ���� �� �������� (RET) ��� ������ �� ��������� ����� ������� �, ����� ��5�� ���& ���������.

(�����:

Name_proc PROC ��� ��������� RET Name_Proc ENDP

)����������� ���������. ���� ��� ��&���� � ������ ����� ���� DOS � BIOS.

(���� ���� – 4� ������ ��&�����, ���������� ������������� ����&���� ������� (����� ���� DOS) ��� ������������� ���������� ������ ��������� (����� ���� BIOS). (4��� � 4��� ��&������ ��� ���5����� ��� ��� ��, ��� � � ����� ��&������. .������� �� ���� ���� �� �: ���� ������ CALL ProcName ����������� ������ ���� INT Number, �� Number – ���� ����� ����, �������� INT 10h, INT 21h � �.�. $�� ������ ��� ��� ����� ���� � ����� Number (0< Number <255), � ���� ���� ���� ������ �������� ������� ��������� ������� ����� ����, ��������� ����� ���� ������� Number-� 4������� �����&� ���� ����� ����. �����&� ���� ����� ���� ������� ���� ��� ����� �� 256 4������ , ����������� � ������ 0000:0000 � ����5�� ����� 1024 ����, ��� 4�� ������ 4������ �����&� ���� �������� ������ ����� � ������� ���� ��� ��������� ����� ��&����� ������� ����� ����. 0����� � � ��������, ��������� �������� ���� ����� �� ������ ����������� ��������� ��� �� ������ INT.

" � ��� � ���, �� ���� ����&���� ������� ���� �� ����������� ��&���� � ��� ��� �� � ����� ��������� ���� ����� ����, �� (��&�����) �;��������� �����, ��� ����� � ����� ���� � ���� � ��� �� �����. (�������� ��� ����� ���� ��� ����&���� ����� ����. :��� ��������� ����&�� ����� ���� ����� � �� � ������ AH �������� ���� �������� ����&��:

MOV AH,����_����&�� INT ����_����� ����

�� �������� �� ���� ����� ����� ��&����� ���� ����� ����� ����������� ������&�� (��������, ��� ����&�� � �� ��� �� �� 4���� – �� ��� ��). ����� ������&�� ���������� ����� ������� ������&�����.

6��� ��� ���� ������ ������ ���� ����&�� 02h ����� ���� 21h ��� � �� ��� �� �� 4����.

MOV AH,02h ;AH – ���� ����&��

Page 72: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

72

MOV DL,’a’ ;DL – � ����� ��� � INT 21h ;���&������&�� ����� ����

.������� INCLUDE "������� ������� � INCLUDE, !�������� ��� �����, �����5����

�������� �����, ����� �� ������� ���� 4�� ������� �. " �5�� ������ ���5���� � ������� � INCLUDE ( �������) ����� ������5�� ��

INCLUDE ���_�����

������ � INCLUDE ��� ����� ��� ���� ���� ��� � ����� ������ �������. " ��� ��� ������� ���� ����, ������ ��� ���� ����� ������ ����� � ��� ���� ����&���� �������.

������ � ������, ��� ������ �������� ����������� ��� � �� �� ������� ������; ���� �� ����� ��� 4�� ������� ����� ������� ��� , � ������ ��� ����-� ����, � ����� ��������� � �������� � ��5�� ����� ������� �.

/�����������. %��������� � ����� !��������� �� ���� ����� ��� ������

������� ���� ���������� (������������), ����5�� �� �5�� ���, � ����� ������� ������ ��� 4� ��� ��� ������� ����� �� ����. " ��&���� ��������� ���� �������� � ���������� ����5��� ����� ������� ���� ������� (����������) ����� ���������� ���������� �� ���� �� � ���������������, ���������� �� ���������� ��������������.

%��������� ���� ���������� ������ ������� ����� ���, ����� 4� �������. %������������� ������ ����� ���� �������� ��� � ��� �� ������ ���� ����������. %������������� ����, ��� ��������� ��� ��������� ������ �������, ��� � ����������� �� ��� ����� ������� � INCLUDE. " �������������� ��� ���� �������� ���������, ����� ����� ���� ���� ���������� �� ��� ���� ��� �������� ������.

" ������� �� ����� !��������� ���������� ������� &��� �� �� ����&��, �� � ��&�����, � ���� ������� ��� �������� � ����&������ ��������� ����� �� � ��������������� ���� ������. -������� ����������� ������5��:

1) ��&����� �������� ��� ������ ������� ��� ���, ��� ��� ��� �������������� ����������� ����� ���, ����� �� ���� ��5�� ��������� ������� ������� ����;

2) ����� ��&����� �������� � ��������� � ����, ��� ���� �������������� ���� �� ����� � �������� ����������;

#������ ������, �� ��������� ���������� – 4� �������� ������ ��������� ����, � ��������� ��&����� ��������� �����-� ����������� �������� ���� ��&���� �������� �������.

Page 73: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

73

/������������ %������������� ������� ���� ��� ��� ������� ����������,

�������5���� ������� � MACRO � ������� ��5���� ������� � ENDM. ����� �������������� ������5��:

��� MACRO [[���������-��������,...]] ���������� ENDM

'����� �������������� ��������� ���, �������� ������� � MACRO. .� ���� ���� ���������� � ���� ������ ����� ������ ����� ��� �� � ��������������. ��������� ��������� ������� ���� ��� ��������� � ������� � ������ �������������� �����, ����� ����������� ��� ��������� ��������, ������ ����� �������������� ��� � �� �. %��� ���� �������� ���� ���� ��������� �������� , � �� �� ����� ���5����� �� ��� ����� � ����������� ��������.

" ���� �������������� �������� ����� ���������� ����� !���������, �� ����� � ����� ����������� �. ������ ���� ���� ����������, � ������ ��������� �������� ���� ���� ������ �� ���� ���� ��� 4��� �����������.

%������������� ��� ���� �������������. (�� 4�� ��� ���������� ��������� � �������� �� ����� ����� ��� ��������������, ��� ��� ����� ������5�� �������������� � ���������� ����5��� �������5�� �������������� � ��� �� ������.

%������������� ���� ���� �� �� ���� ����� ������ ��������� � ����� ������ �����. !�������� ��� 4�� ������� ���������� �������������� ���� �� �, ����5�� 4��� ����������� ��������� ��������� �� ����������� ���������, ���� ����� ��� �� �.

.�5�� �� ���� �� �:

��� [[�����������-��������,...]]

'�� ���� ���� ������ ����� ��������� ������ ����� ��������������. ����������� ��������� ���� ���� ���, ���� ��� ���� ��������. ������ ���� ���� ����������� �������� , � �� �� ����� ���5����� �� ��� �����. $������� ������ �������� ����� ����������� ��������, ��������, ��� TAB-��� ����.

*������� ����5��� ��� �� ��������� �������� �� ��� �� ����������� ��������, ��� ��������� �������� �� ��� ����������� �������� � �.�. 2��� ����������� �������� ���� �� � �����, ��� ��������� �������� ��������������, ������ ����������� ��������� ����������. 2��� �� ����������� �������� ������, ��� ���������, ��������� ���������, ��� ����� �� ������ �����������, ����5����� ������� ������� (��������).

Page 74: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

74

" ���������� �� ����� !��������� ������� ������� ������ ��� ����� �������� ������ � �� ���������. $�� ����� ����� ���� �������� �������� �� �� ����� < >, � ���� 4������� ������ – ����������� ��������, ��������:

allocb <1,2,3,4>

(�� ��������� �������������� ���� ������� ���������� ������� ���� �������&�� ��� ���� ���� ������. (������ ����� �������������� ���� ������ ����� �������, ������� �����&��, ��� ������� ���� ��� ���� ��������� �������, �� �� �� ����� �������&��. �� ���������� ��� ����� ������� ����� �����&�� ��������� ������������ ������� � LOCAL, �� ���5�� ������ ��� �������� ����� ������������ ����� ��������������. �����:

LOCAL ��������_���,...

�������� ��� ���� ����� ������ ����� ����� �������������� � � ���������, �� ��� ����� ���� �� � � �������� ����� ����������. " ������� � LOCAL, ���� �� �������� ���, ���� ���� ����� ��� �� �� ���, � ���� �� �������, �� ����� ����������� ��������. �� ���������� ����������� ����������� ������� � LOCAL ���� !�������� ��� ���� ��� ����� ��� ����� ���� �� � ������� ������� ��� ������5� ���:

??����

6��� ������� ���� ��� 16-����� ���� �������� � 0000 � FFFF. �� ����� ��5���� � ��� ���������� ���� ���������� �� ������������ ��������� � �� ������� ����� 4� ����.

������ � LOCAL ���� ������ ����� ���� ��������������, ������, ��� �� ����� �������� ��� ��� ����� ����������� ��������������, � ���� ���� ��� ��������� ��� ���� MACRO.

�� �������� �������������� ������ ������� � PURGE. �����:

PURGE ���_��������������,...

������ � PURGE ��������� �� ����5�� �������������� � ���������� �������. (������5�� �� �� �� 4��� �������������� ����� ��� ���� � �����. 2��� ��� �������������� ������� ���� �������� �������&�� ��� ������� �, ������ �� ����� ��� ��������� ����� �������� �� ���� �� � ��������� ���� ����� �� �. ������ � PURGE ���� ����������� ��� �������� �������� �������������� �� ���������� ������� � INCLUDE ��������� ��������������. 9�������� �������������� ������� ���� ��� ������ ����� �������� ����, �����, �5�� ������, ���� �������� ����� ���� ��������������. *�����&�� ������� INCLUDE � PURGE �� ���� ������ �� ��� ���� ������ ��� ����� �������, �� ������� ������ ����� �����.

Page 75: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

75

"��� �� ����5� �������������� � ��������� ������� � ENDM ������� ����� ������� � EXITM, ����5�� ������5�� �����:

EXITM

"��� �� �������������� � ������� �� ENDM � EXITM ����������� ������5���� �����&�� ����5� �������������� � � ���� ���� �� � ����5� �������������� ����������� ������ �������������� ��� ������ �������. 6��� ��� ���� ������ �������� ��������������:

add MACRO param ADD AX, param ENDM

" 4�� �������������� ��5��� ������ ��� ����� �������, ���������� ��������� ��������� param, � ��������� ������� AX. 9�� ��� � ��������� ���� IFB ������� ��� ��� �� ��������������, ���� ��� �� �

���� ������� ��� ������ �������, ��������5�� ��������� � ����������, ����� ������� �������� ���� �� ����.

1����� �� �� ������� masm model small .data string_x db "" ����� x. x=$" string_y db "" ����� y. y=$" string_z1 db "-�������� ����&�� ������� x+y=$" string_z2 db "-�������� ����&�� ������� x-y=$" x db (?) y db (?) z db (?) info_string db 2 dup (?) string db 3 dup (?) .code include file.pr prog: mov ax, @data mov ds, ax call summa call vivod mov ax, 4c00h int 21h end prog

*�� ��� �� �������, �� ����� �� ��������� ���������� «summa» � «vivod». 1���� �� �������� ���� ������ ��� ����������, �;� ������ ������� ������, ��� ��� �� ���������, ����������� ����� �������, ����� ������� ���������. 1���� ���������� �����

Page 76: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

76

���� ������ ��� �;� ������ ���������� � ������� � ���� ��� � �����������. 2��� ��� �� ��� ������� ���������� ���������� �;� ����� ��� ����� ���������, ��5��� ��5�� �� �� �������, ����� �� �������. ���� �;� ������ ���������� ����� ��������� ��������� ��������� ����������.

1����� ��������� ����� «file.pr» ; %��������� ����� ��������� ���� �� ��&����� � ����������� +") ; "� � ������� ����� �� 4���� ������� ���&�� ������ ; � ����� � �������� � ��� ������ (���������� &����) ; &���� ���������� ������� al ; ����� ��� ���������� mac macro x, y, string_v local m1 m1: mov ah, 02h mov dh, y mov dl, x int 10h mov dx, offset string_v mov ah,09h int 21h mov info_string[0], 2 mov dx, offset info_string mov ah, 0ah int 21h mov al, string[0] sub al, 30h jc m1 cmp al, 0ah jnc m1 endm pr1 proc mov al, x add al, y ; #�����5�� ������ ����������� �������� ������� al. aaa ; (��� ��� �������� al ���������� ����-�� ����� ; ��� ��� al - 4� ��� ����, al ���� ���������� 4� � ����� ; � ������� �������� ����� ; ��������� �� ����� ��� �������, ����� ����� ���� ��� ; �������� ������� ��� ; ����������� al, ���� ��������, ���� ��������� ����� 9 jnc m3 add al, 10h m3: ret endp

Page 77: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

77

pr2 proc ; (������ ���� &���� �� � � � �� 4���� add al, 30h mov dl, al mov ah, 02h int 21h ret endp ; " � ����� x � y. #����� ���� ����� #�������� ���������� z. summa proc mov ah, 00h mov al, 03h int 10h mac 10, 10, string_x mov x, al mac 10, 12, string_y mov y, al call pr1 mov z, al ret endp

vivod proc mov al, z ; "�������� ��� � &���� and al, 0f0h ror al, 4 mov ah, 02h ; (��&���� ���� mov dh, 15 mov dl, 10 int 10h call pr2 ; "� � ��� � &���� mov al, z ; "�������� ��� &���� and al, 0fh call pr2 ; "� � ��� &���� ret endp -����� �� ������������ ������: "����� ��������� �� �������5�� ��������� �����. 1. "� � ������� ������ ��������� ����� ��� � ��5��

����������, �� ������ � �������� ����� �������� �������� ������ .

2. #������� ����������, ����� ��5�� ������� ����&��, ���� ���� ����� ���� ������ ���� �������� ������� ( � � ��� ������). #���� ���� � ��� ������ ����� ��� ����������, �� ������ ����������� ����� ������� &��� ����������, � �������� �������� ������� ���������� �� ���������� �� ��� ������� ����� ��� ����� ����.

3. 1������ ����� �� ���� ��������� ���������, � ��������� ������ ����� �� �� ������� ����� ������� ������&�����.

Page 78: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

78

4. "�� ��������� � ���������� ������ �������� ����, ���������� ������� ������� � INCLUDE.

����� �� ������: 0�5��� ��������� ����� ���� ����� �� �� � �������

������� � ������� �����, ������5� ��&����� � ����������. �� ��5��� ��������� ���� �;������ ������ ����� �������, ��������� � ��������, � ����� ������� �������� ������ ��� ������� ����� �� $"%. .����������� ��� ��� ��5��� � ������ � ��� �� ���� ������ ����� � ������� ������ ��� ������������ ���������.

� � ��� � � � 5 +�� ������������ ������: '������� ����&�� BIOS ����� ���� 13h.

,���� ��� �������: -���� ������������ ����� � �� �� 4���� ����������

������ �� ���&���� ���� ������. !����� � �� ��� ������5��: 1. � � ��� ��, �� 4���� ���&�� ������; 2. � �������� ���������� ���&�� �� �����&�; 3. ���� ����������� ���&�� ����� 80, � � �������� ���������� ���&�� �� �����&� � � ��� ���������� ���&�� �����&�.

:��� ��������� � ���� �����, ��� ��� � ���� ����� ���&�� ������, ����� ����� ���� ������ ���� ������ �� ������� ���. �� �������&�� ������ ��������, ��� ��������� ������ �� ����������, ��� ����� ����� ����� ����&�� ����� ���� 10h (����&�� BIOS), �� ��� �� ����� ������� ���� �����&� 6.6.

�����&� 6.6. ����&�� BIOS (����� ���� int 10h) �+��*���� ����

,������ ���� �"���

'�������� ���������

ah=00h al=���� ��������� (����� �������� ��������

(��&���� �

��� ������ ah=02h dh=���� �����

dl=���� ����&� *���� ������� ���&��

:����� ����5�� ���&�� ������

ah=03h bh=���� ���������&� dh=���� ����� dl=���� ����&�

Page 79: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

79

�+��*���� ���� ,������

���� �"���

"��� ���� �� ������&� �������

ah=05h al=���� ���������&� .���� ����� �������� ������&�

:����� ��� �� ����5�� ���&�� 4�����

ah=08h

bh=���� ���������&� al=�� ��� �� ah=�������� ��� ��

"� � ��� �� � ��������� ���������� ����5�� ���&�� ������

ah=09h bh=���� ���������&� bl=�������� ��� �� al=�� ��� �� cx=������� � ������

"� ��� �� 4���� ����5�� ���&�� ������ ��� � � ��������� ����������

"� � ��� �� ����5�� ���&�� ������ � ����5��� ����������

ah=0ah bh=���� ���������&� al=�� ��� �� cx=������� � ������

"� � ��� �� �� 4���� ����5�� ���&�� ������

"� � ��� �� �� ���� ��� ���������&� � ������5���� ������ ������5�� ���&��

ah=0eh al=�� ��� �� "� � ��� �� �� 4���� ����5�� ���&�� ������ � ���5��� ����� �� ������5�� ���&��

:����� ����5� ���������

ah=0fh ��� al=����5�� �������� bh=���� ���� �� ������&� �������

!������� ��� �� ����������� ���� ����� ������&��. (������ ��������� ���� ����� ��������� ������5�� �����: ������� ������ ���� ��������� �� �� & ��; � ������� ������ ���� ��������� & �� ��� ��. (�� 4�� ������� ���� �������� ��������� ��� ���� ��� (������� ��� ������ �������), ��� ��� ���� ��� �� (������� ��� ������� �������).

(�� �������� ���������� ���� ��� ������ 4����� ��� ����� ����� � ��� � ����&�� 00h. (�� �� � ����� ����&��

Page 80: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

80

�������� ��������� ���������, ���� ��� ������� ������ 4�����. (�� ������� ������� ���� ������ �������� 03h. (�� � ���� ����� ��������� (���� ���� ������ � � ��������� ����� ����5��) �������� ������ 4�����.

(�� ������ ���� ���������& ��5��� ��� ������� ��� �� ���������� �� ���������&� �� ������� ���� �����, � ����� ��� 4�� ���������&� ������ � ����5��. ���� ����� �� ��� ���&��� ��� � ����� �� ������ ��� �� ��. (�� ����� ����5�� ���������&� ��������� ��� ���������& ����������.

"� � ����� �� 4���� ���� ����� ��5��� ������ ���� ���. �� 4� ��������� ����� ��� ����� ������ ������ ��� ���� ��� �� �����. ���� ��� ���� ������ � �� ����� �� 4����.

masm model small .data str db “$� ����� $” row db (?) col db (?) .code prog: ; .������ 4����� ����5�� ���������&� mov ah, 00h mov al, 03h int 10h mov ax, @data mov ds, ax ; )���� �� ������ ������� �� ����� ������ mov di, offset string mov row, 10 mov col, 10 m1: ; (��&���� ���� ������ mov ah, 02h mov dh, row mov dl, col int 10h

; #���� ���� ������ al �� ��� �� �� ����� � �� ���� �� ���& �����. 2��� ���������� ��� � $, � ������� – ���& ����� � ��� �� �������.

mov al, [di] cmp al, “$”

Page 81: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

81

jz m2

; "� � �� 4���� �� ��� � ��� ����� & ��� (����������� ��������� bl) �� ��� �� (����������� cx), �� ��� ���5����� ������ al. "������ ���� �� ���������&�.

mov ah, 09h mov bh, 00h mov bl, 59h mov al, [di] mov cx, 01h int 10h

; ������ � ������5��� ��� �� (� �������� di), ��������� ���������� ���&�� ������. (������� ������ ��� ������ �� ����� &����. ,��� ����� �����, ���� ���������� ���� «$».

inc di inc col jmp m1 m2: mov ax, 4c00h int 21h end prog

-����� �� ������������ ������: -��������� ������� �� ����� Assembler ������5�� � � ��

4���� �� ���� �� � ������� ��������. ��������"�, +�����"� � ��'��� ��������, ����� ����(���� ����� ��, �� � -�� �� �$������� ���� ���� !��, �� '�" ("�! ������" �� !+����� �� � �������� �"�� ����& ���$����". ��� ���������" (������ ����� � ��� (���) �� ���� ���$������ +���.��& �� !+����� �� �� !�� � ���&��*��/ ������� �+������&. "�� ������� ����� ���� ������� � �������� ����. .��������� ����� �������� ���, ��� �������, ��� ���������, ��� ����������.

(�� �������� ��������� ����� ��� ������ ��� ����������� �����, ��������� �������5�� ���������� ������.

1��������� ����� ��������� �� ���� �� � ������� �������, ���� ��� ��������� ������� � ������ �����.

"������ 1. 6������� ������� ��� � �� ����� ������ � ���������

���������� � ���� ��� � ������� ���&�� �� 4�����. str – ����� ��� � �� row – ���� ����� col – ���� ����&� attr – ���� �������

Page 82: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

82

"������ 2. 6������� ������� ��� ����� ���� � 4����� ����� ������, ������� �

���&��, ������� ���� ������. str – �����, ���� ���� �������� ��������� ������ row – ���� ����� col – ���� ����&� len – ������� ����� ����� ��� �

"������ 3. 6������� �������, ����� ������ �������� ��� � 4������

����� (����� �����, ��5��� ��5�� �� 4�����), ��� ���� �������� ������ � ����� �������� ���� ������.

row – ���� ����� col – ���� ����&� len – ����� ����� attr – �������� �����

"������ 4. 6������� �������, ����� � ��� �� 4���� ������� �����

����� ��� � � ������� ���������� (����� ������� ����� �������� �� ����� 5 4������ ).

str – ����� ��� � ��� � �� attr – ����� ������� ��� � row – ���� ����� col – ���� ����&�

"������ 5. 6������� ������� ������ ������� ��� ��� «r» ����5��

���������&� �� ��������, �������� ���� ������. (�� �������� ���� ������� ��������� ����� ��� � �������� ������� ��� �� ���� ������ ��&���� �������� �������.

attr – �������� ��� ��

"������ 6. 6������� ������� ��� ����� ���� � 4����� ��������� ����&�,

������� � ������� ���&�� ������. -�������� � ���� ������ ����� 4�����.

row – ���� ����� col – ���� ����&� len – ������� ����� ����� ��� �

"������ 7. 6������� ������� ������ ������� ���� ������ ��� ��

�����, ������� � ������ �� 4����. (�� ������ ��� � ��������� ������� ���� � 4������ �����. .����� ��� ������� � ����� � ������� ��� ��.

str – ����� ��� � �� attr – � �� �������� ��� ��

Page 83: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

83

"������ 8. 6������� ������� ������ ��� ��� � «a» ��� 4�������

������, �� ��� � «b» � ��������� ����������. (�� �������� ���� ������� ��������� ����� ��� � ������� ��� �� ���� ������ ��&���� �������� �������.

attr – �������� ��� ��

"������ 9. 6������� ������� � �� �� 4���� 4-� ����� � ������, ��������

�������� ��� � � ��������� ����������. symbol – ASCII-�� ��� �� attr – �������� ��� �� side – ������� ��� � , ���� ���5�� ���� � ������

"������ 10. 6������� �������, ������� ��5�� ������� ��� «o»

4������ ����� ����� ��������� ���&���� ������, ��� ��� ��, �� ���� ����� ������� ����������.

row – ���� ����� col_1 – ���� ��� ����&� col_2 – ���� �� ����&�

"������ 11. 6������� ������� � �� �����, ������ � ������� ���&�� ��

4�����, � N ��� � 4������ ����� (���� � �� N ��� � �������� ������ �� � �� ����� � ���������� ����5� ����&�).

row – ���� ����� col – ���� ����&� N – ������� ��� � ��� 4������ �����

"������ 12. 6������� ������� ��� �� ������� ������� ���&�� ������,

���� ���������&� ������ � ����5��, � ����� ������� ������������ ������� �� �������� ���������&�.

row – ���� ����� col – ���� ����&� Nvideo – ���� ������� ���������&�

"������ 13. 6������� ������� ������ 4����� � � �� &����� 4�����

������� ����� � ��������� ����������. #���� � �������� ��� � ����� ���� ������ ��&���� �������� �������.

str – ����� ��� � �� attr – �������� ��� � �����

"������ 14. 6������� ������� ���� ���� 5 ��� � 4������ ����� ��

������� ���&�� ����5�� ���������&� �������� ���������&�. row – ���� �����

Page 84: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

84

col – ���� ����&� Nvideo – ���� ������� ���������&�

"������ 15. 6������� ������� &��������� ����� ������� ��� � (4�����

���5�� �����), ��� 4��, ������� ��� �� N �� ����� ��� &����, ����� �� ���� ��� �������� ��� �� N-1 �� �������5�� ��� &����.

str – ����� ��� � �� attr – ����� ������� ��� �

"������ 16. 6������� �������, ����� ����� ��� ��� �� � 4����� �

�������, ������� � ������� ���&�� ������, � ������ � � ����� �: ����� �� ��� � � ����� ������� ��� � . "� ���� �� 4���� ��� �� ����� .

row – ���� ����� col – ���� ����&� N – ������� ����� ����� ��� �

"������ 17. 6������� ������� � �� ������� �� ��� � , � ���������

����������, ��� �� ��� � ���� �������� ������� ���&�� ������.

row – ���� ����� col – ���� ����&� attr – �������� ��� ��

"������ 18. 6������� �������, ������5�� ��� �� �� 4�����, ���� �� ��

� ������ � ����� �� �� ����� ����� � ��� � . .����� ��� ����� ���� � ��� ����, ������������ ������� ����&� ����5�� ���������&�.

symbol_mass – ����� ��� � col – ���� ����&�

"������ 19. 6������� ������� ���� ��� � �� ������� �����,

������� ���&�� 4�����. .����� ��� ���������� &��� � ���� ��� ������� ���� ��� ���. -����� ��� ������� ��������� �������� ��� � �� ��� � .

row – ���� ����� col – ���� ����&� str – ����� ��� � ��

"������ 20. 6������� �������, ��������5�� ������� �� �� 4�����,

����������� ����� ��������� ���&���� ������, ��� ��� ��, �� ���� ����� ������� ����������.

row – ���� �����

Page 85: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

85

col_1 – ���� ��� ����&� col_2 – ���� �� ����&�

"������ 21. 6������� ������� � �� ����� �� 4����, ��� 4�� ����

�� ��� ����� (������) ����� ���� � �����, ������� � ��� � ������� ���&�� ������, � ��� �� �� ��� (�������) – � ���.

row1 – ���� ����� col1 – ���� ����&� row2 – ���� ����� col2 – ���� ����&� str – ����� ��� � ��

"������ 22. 6������� ������� ��������� ������� ��� ��, ���������

� �������� ���&�� ������. row – ���� ����� col – ���� ����&� symbol – ��� � ��� �����

"������ 23. 6������� ������� � �� ������� ����� � �������, �����

���������� ������� ������, ������� � �������� ���&��. str – ����� ��� � �� row – ���� ����� col – ���� ����&�

"������ 24. 6������� ������� � �� ������� ���&�� ������ ��� � ��

������� �����, ����� ������ ��� ������� ����� � ��� � . str – ����� ��� � �� row – ���� ����� col – ���� ����&� symbol_mass – ����� ��� �

"������ 25. 6������� ������� ���� ���� ��� � �� ����5�� ���������&�

��������, ������� � �������� ������� ���&�� ������ � � ������. row1 – ���� ����� col1 – ���� ����&� row2 – ���� ����� col2 – ���� ����&� Nvideo – ���� ������� ���������&�

"������ 26. 6������� �������, � ��5�� (� ������������) �������

���&�� ������ ���� ���������, � ����� ��� ����� – ���� ����5�� ���������&�.

row – ���� �����

Page 86: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

86

col – ���� ����&�

"������ 27. 6������� �������, ��������5�� ������� ��� «s» �������

����� 4�����. row – ���� �����

"������ 28. 6������� �������, ����� � ��� ������� ����� 4����� ���� �

���� ����� � ��������� ����������. str – ����� ��� � �� row – ���� ����� col – ���� ����&� attr – �������� ��� � ��

"������ 29. 6������� �������, ����5�� ���� ���������� �� ��� �

������� �����. str – ����� ��� � ��

"������ 30. 6������� �������, ������5�� �� ���� �� 4�����, ������5��

��� �, ����������� ������� ���&�� ������. row – ���� ����� col – ���� ����&�

����� �� ������: �� ��5��� ��������� ����� ��������� ��� ��� ���������

�� �� ����� ���������, ������ ����� ��� �������� ������� �����. .����������� ��� ��� ������ � ��5��� ��������� ����� � ������ ��������&�� ������������ ������� �����, � ����� ������ �;������� ������� ����� �������.

� � ��� � � � 6 +�� ������������ ������: (������ ������ � ������ �� ����� ����� �� ��� ����

������&�� �����, ������� ���� ������.

,���� ��� �������:

������" ��(��" �� �������� (����*�*�"� ������") #���� !��������� ���� ��� ����� ��������� ���� ��� ��

������ � 1 � 65535 ����. .����&�� � ������� ������� ��� ���������, ��� �����, ������ ���� ���� � ��������, � ����� ��������� ����� ���������� ��� �� ��. *����� ���� �� ����&�� ������� ���� ��&����� � ��� ��������: ��� ������������� ��� ������� ���� ����5�� �� ����, ����� – �� �� (�� �������� ����������� �������� ��� � B (byte) ��� W (word)).

2��� ��� ����� ����� DF ����� ��������� ������ ���� �

Page 87: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

87

������� ����� ��� 0 ( ������� ������ CLD), �������� �������� ������� � ���������� � ����� �����, ���� 1 ( ������� STD) – �����������. '�������� ������� ����������� ��� � ����� ����� �� �����&�, ���� ������ ������� � �������, ��� �� 2 – ���� � �� ���.

*����� ���� � ������� ��5� �� ����������� � ���������� ���������� (���������� � ������), ����� ������� ��� �������� � ���������� � ������ �������� ������.

"� �� ��������� ����� MOVS (MOVSB, MOVSW) *����� MOVS ���������� �4������� ����� DS:SI ����� ES:DI

� ������� ��� �������� ��������� ������ �� ������5�� 4������ �����. *�����, ��������5�� 4�� ����&��, ���� ��� ���� ����

4������ �� ��� ������ ������ (&�����) �����. -����� 4������� ����������� ���������� ������. " �5�� ������ ���� ����� ��, ����� ���� ������� ������� ��� �, ���� ������� ��������� ����� ��������� 4������ �� ��� ������ ������ ����� � ��5�� ������ MOVS, ��� ��������� ��� ��� ��� � ��� �������� ���� &������� ������.

1. )���� ��� �������� ���� DF �� ������� � �, ���� ����� ����� ����� ������� ����� 4������� &����� – ����� ����� ��������� ��� ��� ���� ����� .

2. 0������� ��������� �� ������ &����� ������ ���� ������ DS:SI � ES:DI.

3. 0������� ������ CX ������� 4������ , ������5�� �������.

4. "����� ������ MOVS � �������� REP (������� REP ����������� ���� ��� ����� ��������� ����, � ��� �������� ����� ����������� �������� REPE, REPZ, REPNE � REPNZ).

!������� �������� " ������� ����� ��&����� ������� � � ������ ��� ������ ,

����� ���� ����� ���������� � ������:

1-�� �������: REPE (� �����, ��� �� �) REPZ (� �����, ��� ���) REP (� �����)

2-� �������: REPNE (� �����, ��� �� �� �) REPNZ (� �����, ��� �� ���)

(������� � ������ ��� ���� ����� ���� ��� �������� ��������� �� �� �����, ��������,

REPE CMPB

(������ ��������� ������ CX ��� ������� &��� . 6� ����� 4���� &���� ��������� ������5�� ����� ��:

1) �� ���� CX. 2��� � �� �� 0 – ��� �� &���� � ������ � ������5�� ������;

2) ��� �������� ����� ������5�� ����� ����;

Page 88: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

88

3) �������� �������� ���� � ����&��; 4) ���������� CX �� �����&�, ���� ��� 4�� �� ����������; 5) �� ���� ���� ZF, ���� ��������� ���� �� ����&�� SCAS ���

CMPS. 2��� ��� �� � ������ &���� �� ��������� – ��� �� &���� � ������ � ������5�� ������. "��� �� &����, ���� �������� � ������ REPE � ZF=0 (�������� ��� ����� �� � ���) ��� ����������� ������� REPNE � ZF=1 (�������� ��� ����� �� � ���);

6) ��������� �������� ��������� ������ �� ���� �� � ��������� ���� ����� ����� � ������ �� ����� &����.

"� �� �� ������ ���� CMPS (CMPSB, CMPSW) *����� CMPS ��� �� ��� �������� 4������� ��� ����� (DS:SI) �

��������� 4������� ��� ����� (ES:DI) � ������� ��� �������� ������ �� ������5�� 4������� ���� �� ���� �� � ���� ����� ����� DF. #�� ����� �������� ��� � � ������ ��� ����� CMP. -�������� – ������ ����� ����.

" ������5�� ������� � ��5�� ������ CMPS ������ str1 � str2 ����� �������� ��� �� ������� ��� � ����. " ������� ������ ������ Assume, ����� ���������� ��� ���� ��������� ������ ES � DS � ���� ������� ������. " ������ ������ �� ����� ��� ���� ������ ��������� �������� � ���� ������� ������ ������� � � �� ��������� ������ . .������ ��������� �������, �� ��������� ���� ������ ��� �������� �� ��������� data � ������ ES � ������ DS.

masm model small .data s1 db "‘#���� � ���� $" s2 db "6� � ���� ��� ��: $" str1 db "0123456789" ; (�� �� ����� ��� ��� ����� str2 db "0123456789" ; "���� ����� ��� ��� ����� per db 00h ; 2��� ����� �� �� ��, � per<>0 (��� ������� ; per=0) .code Assume ds:@data, es:@data ; (�� ���� DS � ES � ������� ������ 2��� ������ ��� ���� �� ����� ������� � ������ ��� ����� ���� ������� �� �����, ��� ��� ��� �� ���� ����� ��������� � ������ DS:SI, � ���� � ������ ES:DI prog: mov ah, 00h mov al, 03h int 10h

Page 89: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

89

mov ax, @data mov ds, ax mov es, ax ; �������� ES �� DS cld ; ���� ���� DF – ��� ����� ����� ����� ; ��������� ����� lea si, str1 ; ������� si ���5���� str1 lea di, str2 ; ������� di ���5���� str2 mov cx, 10 ; ������� ��� � ����� ����� (����� ; ����) met1: repe cmps str1, str2 ; ��� ����� ��� �� ���& ��� ��� 4������� ; �� �� jcxz equal ; ������ �� �����, ���� cx=0 mov per, 01h ; ��������� per, ���� ���� ��� �� ��� ���� ; ��������� ��� � mov ah, 09h lea dx, s2 int 21h 2��� ����� �������� �� �� ��, ������� ��� �� ����&�� ��� ����� cmps. " �������� si � di ���������� �������� ���5���� ��������� ������ ���� str1 � str2 �� ���� ���. -������ si � di ����� ��� �� ������5�� ���� ��� � ��� ��� �����. (4���, �� �� �������� � ���� ������� ��� � ���� 4������ ��������� ������ �� 4��� ������ �����&�. dec si ; ���������� si �� �����&� dec di ; ���������� di �� �����&� mov dl, [di] ; ������� dl ��� ��� �� � ������ di mov ah, 02h ; ���� ����&�� � �� ��� �� �� 4���� int 21h ; � � ��� �� �� 4���� mov dl, 20h ; ������� dl ��� ��� �� «�����» int 21h ; � � ��� �� �� 4���� (ah ��������� � �� ; ��������� � � ����� �������) mov dl, [si] ; ������� dl ��� ��� �� � ������ si int 21h ; � � ��� �� �� 4���� mov dl, 0ah ; ������� dl ��� �� ���� �� ����� int 21h ; ������ �� � �� ����� mov dl, 0dh ; ������� dl ��� �� ������� ����� ����� int 21h ; ������ ����� ����� inc si ; � �������� si �� �����&� ( � ��� � ����5��� ; �������)

Page 90: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

90

inc di ; � �������� di �� �����&� jmp met1 ; � ��� �� ��&����� ��� ����� ���� � ����5�� ; ���&�� di � si equal: mov al, per cmp per, 00h jne exit ; ���� ����� �� �� ��, � ���������� per ����� ; ������ � ���� � �������� ������ �� ���& ; ������� mov ah, 09h lea dx, s1 int 21h exit: mov ax, 4c00h int 21h end prog

"� �� �� ���� ��� ����� SCAS (SCASB, SCASW) *����� SCAS ���� ��� ��� ����� ������� ������� (AL ���

AX) � ����� ������, ��������� ����� ��� ����������� ���� ES:DI, ���� �� ������ DI ������ �� ����� �� ������� 4������ ������ (���� ��� �� ) �� ���� �� � ���� DF. *����� SCAS ����������� ���� ��� ����� ����� (ES:DI) 4������� ������ ������� AL ��� AX.

*�����, ��������5�� 4�� ����&��, ���� ��� ���� ����� �������� ������ ������. 1������ 4�� ������ ������ ��������� ����� ��� ����� ��������� (&�����) 4������ ������ ���� ����� ������� 8, 16 ��� 32 ����. '���� �������� ���� ���� ���� �������� ���5�� ������ al/ax/eax. "��� ������� ������� �� 4��� ���� ���� ���� ���� �� � ������� 4������ &�����, ���� ��5��� ������ ����.

" ������5�� ������� � ��5�� ������ SCAS ����������� ������� ������� ������ ��� �� symbol �������� ����� str.

masm model small .data simbol db "g" s1 db "'��� ��� �� ����� ���","$" s2 db "" ����� ������ ��� � ����� ����","$" s3 db "" ����� ������ ��� � �������, ��� �� � ����","$" str db "dsgaseggqwdasfswegrwgqf" per db 00h .code

Page 91: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

91

Assume ds:@data, es:@data prog: mov ah, 00h mov al, 03h int 10h mov ax, @data mov ds, ax mov es, ax cld lea di, str ; di ������ ����� ����� ����� str mov al, symbol ; al ���5����� �� ���� ��� �� mov cx, 23 ; �������� ������� ��� � ����� met1: repne scas str ; ���� ����� ���������� ��� �� ����� ; ������� �������� ��� �, �� ��� ; ��������� al jcxz equal ; ��� �� ��&����� ����� ���� ������� ; ���& ����� add per, 01h ; � �������� �������� � ������� jmp met1 equal: cmp per, 00h ; ��� ����� ������� � ��������� � ������� � ; ����� jne yes_simbol ; ������, ���� ������ ��� �� ��� ��� �, ; �������� ������� al mov ah, 09h lea dx, s1 int 21h jmp exit yes_simbol: mov al, 5 cmp al, per ; ��� ����� ������� � ��������� ��� � � ; ����� 5 jnc min_5 ; ������, ���� ������� ��������� ��� � ; ����� ���� mov ah, 09h lea dx, s2 ; � � ��5����, ���� ������� � ������� int 21h ; � �������� ��� �� ������, ��� �� � ���� jmp exit min_5:

Page 92: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

92

mov ah, 09h lea dx, s3 ; � �, ���� ������� � ������� int 21h ; ����� ���� exit: mov ax, 4c00h int 21h end prog

"� �� � ������ ����� LODS (LODSB, LODSW) *����� LODS ������ ��� ������ AL ��� AX �������� ������

������, ����� ���� �������� ��������� DS:SI. ���� �� ��������. $�� ����&�� �� ���� �� ���� 4������ &����� � �������� �

������-���������� al, ax ��� eax. $�� ����&�� ���� ������ ��� ����� � ����� (������ �����) � ���, ����, ����� ������ 4������, �� ���� � (��������, ��� ���������). "������ ������ �� ������ 4������� ����������� ���������� ������.

#�����5�� ������ ���� ��� � ��� �� 4���� ����� str � ��5�� ������ LODS. " ������� ������� ����� ��������� SI �� ����� str,� ������� CX �������� ������� ��� � � ���� �����. #������� ������� CX ����� ���, ����� &��� ��������� ������� ��� � �� ��� �����.

masm model small .data x db 10 ; ��������� �����& ��� � �� �� 4���� str db "(�� �� ��������� ���� ���� !" .code Assume ds:@data, es:@data prog: mov ah, 00h mov al, 03h int 10h mov ax, @data mov ds, ax mov es, ax cld lea si, str ; ��������� �� �������� ����� mov cx, 31 ; ������� � ����� ��� �

Page 93: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

93

met1: (�� �������� ������ LODS AL ���5����� �� ��� ��, �� ����� ����� ��� ��������� SI. (��� 4� ��������� SI � ����� ����� �� �����&� � ��������� ������5�� ������. lods str ; ������� ������ AL ��� �� �� ����� �� ; ����� ����� ��� ������-��������� SI mov ah, 02h mov dh, 10 mov dl, x int 10h ; ���&���� ���� ������ mov dl, al mov ah, 02h int 21h ; � ��� �� ����5�� ���&�� ������ inc x ; ��������� ���������� �������� ������ loop met1 ; ���� � ����� �� �� ��� ��, � �������� � � mov ax, 4c00h int 21h end prog

"� �� ��� ����� ����� STOS (STOSB, STOSW) *����� STOS �������� �����, ������5���� � ������ ES:DI,

4������� �� ������� AL ��� AX. 6� ���� ������ �� �����. $�� ����&�� �� ���� ���� ���� ����� ��, ������ ������ LADS,

� ���� �������� �������� �� �������-����������� 4������� &�����. $�� ������ ���� ������ ��� ����� � ����&��� ����� (������ ����) SCANS � ������� LODS � ���, ����, ����� ������ 4������, �� ���� � ������ � �������� �� � ���� � � ��������.

-����� �� ������������ ������: -��������� �������, ������5�� ����� �� �� ���� �� �

������� �������. "�� ������� ����� ���� ������� �� �� � ����&��� ������� ������&�� ������, �.�. �� ��� ��&����� ����� �������� ���� �� � �������� � ��������������, ����� ���������� ��������� ���������� �����.

"������0 1 "������� �� �����, ������ � ��� ������, ���������� �����,

����������� ����� ��� ���� |. 6���� ����� ��������� �����. -�������� ������� �����, ������� ������ ��������� ������� ���������. "� ���� ��������� ��������� ������� & ��� &����� 4�����.

Page 94: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

94

"������0 2 .��������� ��� ������ ����������, ������ �� �� �� �,

����� ���������� ������� ���� ��� (������� � �� ������ ���� ������ ��&���� �������� �������).

"������0 3 " ���� � ��5�� ��� ������ ����� ��������� ��� � (�� ����

70 ��� � ). "� ���� 22 ����� 4����� �� ��� �� �� ����� ������ �� ���� ��5�� ��������� ���� ���.

"������0 4 " ���� � ��5�� ��� ������ ����� ��������� ��� � (�� ����

250 ��� � ). "��� ��� ������ ���� ��� �� «|». "� ���� ��������� &����� 4�����.

"������0 5 " ���� ����� � ��� ������ ��&���� �������� �������. ��

���� �� � ������ ������ �������, ����� ��� � ���������� ������. -�������� � ���� �� 4���� (���� ���� ������ �� � ������� � ������� ������� �����). #�5���� � ��� �� � ���� ���������� �� ���� �� ����.

"������0 6 " ���� �����, ����5�� �� ����� � �����& (�� ����� ���� ��� � ).

#�����, �� ����� ������� ��� ����� � ���� ������� ���������, ������� ������5�� ����� ��: ������� ������� ��� �� � �� ����� �� ������ ����. (�� ����� ���� ����� �� ����� �������, �� ��� � � ��� ����� ������� �� ���� 16 ��� ������&��, � ����� �� ���� 8 ��� (������ ���� ������ �����). 2��� ������� ��� ������ ����� �� �������, � � �������� ����&������ 16:16:8 (������ ���� ������ �����). -�������� � ���� &����� 4�����, ����� & ���.

"������0 7 " ���� � ��� ������ ����� �������&��������� &���. "������� ��

����� ���� � ��������� �������&��������� �����. 2��� &��� �� � ����� ��� ����� ���� ���� �����, � ������ ��� ����� ���������. 2��� ������� &��� ������, � ������� �������� &���� ������� �������� ������� �����. "� ���� &����� 4����� ���������� �� ��������� ����� (���� ���� ���� ������� ��� ��������� ������� ���������).

"������0 8 " ���� � ��� ������ ����� ���������� &���. "������� �� �����

� ��������� �����. 2��� ������� &��� ������, � ������� �������� &���� ������� ������� ������� �����. 6���� ����� �������� ����� �� ��������� � ��������� ���������� �����. "� ���� ��������� &���� 4�����.

"������0 9

Page 95: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

95

" ���� ���������� �� ��������� �� ������ $"% (�� ���� 10 �� , �������� ������� ��� ����� �� ��� ����� 250). (������ ������� ��� � �������� �� �. "� ���� ��������� &���� 4�����.

"������0 10 " ���� ����� ��� � , ������� ���5�� ��� ���������� ��

��������� �� . '� ������ ������ ������ � � ���� �� 4���� ���� �� �� �, ����� ���������� ��� � � ��� ���.

"������0 11 .����� ��� � ����� ��� � . '� ������ ������� �� �,

������5�� ��� ��� � "o". -�������� � ���� �� 4����.

"������0 12 " ���� �����, ����5�� �� ��������� ��� ������ $"%.

(�������� ������� ��� «a» � ������� ��� «b» ������ �����. .��������� ����� ��� � ����� ��������� ��� ��� ����, ���� ������� ��� � ���. .� �� � ���� &����� 4����� ������� & ���.

"������0 13 " ���� �������� ����������. *���� ��� ������ ����� ������

�� � ����� ��. .� �� � ���� ����� & ��� &����� 4�����.

"������0 14 "������� �� ������ ����� �������&��������� &��� 20

��������� �������&��������� �����. 2��� ����� ������ ������� ����� ������ 20, � ����� ����� �����. 2��� ������� ����� ����� 20, � ������� ������ &����. "� ���� 14 ����� ���� �� �����, ����� ������� �� � � � ����� ����� ������� �����&.

"������0 15 " ���� ����� ��������� ��������� ��� � ����� $"%. "� ����

12 ����� 4����� �� ������ ��� � (������� & ���), � 20 ����� �� ������� (������� & ���). ����� ������� ������� ���&������� ��� � , �������5���� �����.

"������0 16 " ���� ������ $"% ����� ��������� ��� � . "� ���� 10

����� 4����� �� ��� ��, � ����� �� ASCII � ������ ������ �����, � 18 ���� – � ����� �� � ������ �� ������ ����� � ����� 39.

"������0 17 "������� �� ������ ����� &��� � � � ��������� ����������

����� � �� � �������� ���������. 2��� &��� ����� �� � ����� ��� ����� ���� ������ ������� � ����� – ����� �������������� � �����. 2��� &��� ����� – ������ �������. 6���� ����� ��� �� � �� � ������� �� �� ������ ����. -�������� ������� ��� ����� �������&�������� ������� ��������� � � ���� ������� & ��� &����� 4�����.

Page 96: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

96

"������0 18 " ���� ���������� (�� ���� 20 �� ). " ���������� �����

����� �� �� �. "� ���� 12 ����� 4����� ����� & ��� 4�� �� � � ����������� �� ����� �� ����� ����������.

6������� : tytyt yyy fgfg tytyt jkj yyy fff yyy tytyt -> 1,4 yyy -> 2,6

"������0 19 " ���� � ��� ������ ����������, ����5�� �� ���� ��� �� 200

��� � . "� ���� &���� 4����� ���� �� ��� �, � ����� � ���� ������� ����� ASCII ��� ���� �����& ����� �������.

"������0 20 #��� ��� ������� �� � ��� ������ 10 � ��������� ����������

����� � ��������� ���������� ����� � �� ����� �� ������ �����.

"������0 21 " ���� ����� ��� � (����������), ����5�� �� ���� ��� �� 250

��� � . -�������� �� � ���� ���������� ������ ��� ���� ����. "� ���� ��������� ����� 15 ����� 4�����.

"������0 22 " ���� ����� ��� � � ������ �� � (t1,t2,t3,t4) ������.

'�������� �� ����� �� �, � �����5�� � �� ��� t1,t2,t3,t4. "� ���� ��������� &����� 4�����.

"������0 23 " ������ ���������� ������� ������� �� � � ����������� �

���������� �������. -�������� ������� ������ ����� 4�����.

"������0 24 0������� �� � ����� ���������� ������ ������.

(��� ���� ������ 4�����. "� ���� ��������� ���&�� ������.

"������0 25 '� ����� ���������� ������� �� � � ������� n1,n2,n3,n4,n5.

6���� ��� � ���� �� �������� ������� ��� ��������, � ����� ��� ���� �� ������ ���� ����� ��� �������� �������. "� ���� ��������� �� 4���� ������.

"������0 26 '� ����� ���������� ������� �� � ����������� �����.

(�������� ������� ��� � �������� �� �. (������� ���������� � ��������� ������� ��� � � ���� �� 4����.

"������0 27 .��������� ��� ������ ����������, ����� �� �� �� � �

��������� �������. .��������� ������� ����� �� . -�������� � �������� ���������� � ���� �� 4����.

Page 97: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

97

"������0 28 " ���� ����� ��� � (����������) �� ���� 250 ��� � . 6����

�� �, ����5�� ��������� ���� ������� ����������. "� ���� ��������� �� 4����. )�����, �� ������� ������� ��������� �� ���� ���� ����� �� � ������������ � ������� � �����.

"������0 29 " ���� � ����� ���������� � �� , ����5�� �� ���������

��� � . " ���������� ����� �� � (���� ����), ����5�� �� ��� �� ��� � , �� � ������ �� . "� ���� ��������� �� 4����.

"������0 30 0����� �� ���������� ������� ��� ��������, � ���

���������� ���� � ��� ������ ��&���� �������� �������. (�� 4�� ����� ���������� ���� ���� ��������. '� � �� ���������� ������� ����� �� �� � (���� ����). "� ���� �� 4����, ���� � ������, � � ���������� � ����&�� �������� ����� �� �� � ����.

����� �� ������: �� ��5��� ��������� ����� ��������� ��� ��� ���������

�� �� ����� ���������, ������ ����� ��� �������� ������� �����. .����������� ��� ��� ������ � ��5��� ��������� ����� � ������ ��������&�� ������������ ������� �����, � ����� ����� �;������� ������� ����� �������.

� � ��� � � � 7 +�� ������������ ������: . ������� ������������� �� ����� ������ � ������ ������ ����, �

����� �������� ������ � �� �� ����� � ���� � ������� ($"% ������� � ����� Assembler ������ 4����&�� MS-DOS.

,���� ��� �������: �� ������ � ������&��, �����5���� �� ������ ($"%,

����������� ���&������� ����� ���� �� ����&�� MS-DOS. " 4�� ����� ���� ����� ����, ��������������� ��� �������� �� ��� ����&�� ����&���� �������, �� ����� ��� �������� ����&�� � ��������� �������, ������� � ��������. ��� �� ����&�� DOS ������� �������� ����� � ��� ����������� ��� ������� ����� ����� ������� ������ DOS..�� ��� ����������� � ������ ������� ������&�� ������, � ������&�� ����������� ������ ���������� ���������� ����� ����������� ����� ��� � �������� ������ ��������� � ��&�����.

6��� ������ ����&�� DOS, ������5�� �� ��� ����&�� ��� ��������� �������, �������� � �������. (�� ������� ����������� ������5�� �������:

Page 98: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

98

• ����� ASCIIZ – ����� �� ����� ASCII-���, ����� �� �������� ���� �� ���������;

• ��������� ����� – ���������� ����, ����� ����&����� ������� ���� �� ��� ���� ����� ��� ���� ����� ����� ������ � ������������� (���� ��� ���5����� � ����� � 4��� ����� – ���� � � ��������).

������ ����&�� ��� ����� � ���� � ������� �� ����� ������ ������ MS-DOS � ���������� � ��� �� ����������� ��� ���������. �� ���������� ��������� �������� ����� ����&�� ����������� ��� ������� ������� CF:

• ������ ������ �� ������� ����&�� ��� CF ������ ����� 0; • ������ ����� ��� CF ������ �� ����� 1. ( ���� ��� ���� MS-DOS ���� ����&�� ������ �������

��������, ���5��5�� �������� ��� ��� ���� ����&�� � �������5�� ������ �� �� ���������. )� ������� ����� ������ � ������: ������ ����� ���� ����� �� ���� CF ����� ������� !8 �� �����, � ����� ��� ��������� ������� �� ����� ����. "������ �������� �� ���� ��� ����� �����&� 6.7. .���� ������� ����� ���, �� �������� ������� !8 ������ ������ �� ������� ������ ����&�� �� ����������.

�����&� 6.7 . 0������� ����������� �� ����� *�

����� -������ �� ���

00h 6�� ����� 01h 6� ����� ���� ����&�� 02h ���� �� ������ 03h (��� �� ������ 04h .����� ������ �� ���� (��� � �����

��������� ) 05h ���� �����5�� 06h 6���������� ��������� 07h -������� ��� ���� ����� ������� 08h 6�������� ������ 09h 6���������� ����� ���� ������ 0Ah .����� �������� (����� ����� 32 *����) 0Bh 6���������� ����� 0#h 6���������� �� ������ 0Dh 6���������� ������ 02h 6��� ����� ������� 0Fh 6���������� ���� � 10h (����� ������� ����5�� ����� 11h )������ �� � �� ���� 12h 9���� ��� ���� 13h ��� ��5�5�� � ������

Page 99: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

99

*� �����

-������ �� ���

14h 6��� ����� ������� 15h ��� � �� � 16h 6��� ������ ������ 17h (�� �� ���� CRC ��������� ����� ������ 18h 6� ����� ����� ��������� ������ 19h .����� ����� (���&���� ����) 1Ah 6��� ������ ��� ������� (�� DOS-����) 1Bh #���� �� ������ 1#h " �������� ��� ����� 1Dh .����� ������ 1Eh .����� ������ 1Fh .�5�� ��� 20h 6�������� ���������� 21h 6�������� ��������� 22h 6���������� ����� ����� ( 2S:DI ����� ���������

��������� �� ����� ���� ��� ��� ����� ASCIIZ) 23h FCB ��������� 24h -���������� ����� ��������� 25h 6��� ���� �� �� � ������&� ' 26h 6� ���� �� ������ ����&�� � ����� 27h 6�������� ����� �� �����

28h-31h 0������ �� ��� 32h 6�������� ����� ���� � ����� 33h )�������� �������� �� ������� 34h ����� ���� ����� ���� 35h 6� ������ ���� � ��� 36h #��� ������ 37h #��� � ������� ����� �� ��5��� ��� 38h '������� ����� ����� NetBIOS 39h !��������� ����� ���� �������� 3Ah 6� ����� ����� �� ���� 3"h 6��������� ����� ���� 3#h 6�� �������� ��������� ������� 3Dh .������ �� ������ �������� 32h 6�� ����� ��� ����� ������ 3Fh ���� ������ ������ 48h #��� � ��� ������ 41h ���� � ���� �� ����� 42h 6� ����� ��� ���� ������� � 43h #��� � ��� �� ������ 44h '������� ����� ���� �� ���� 45h '������� ����� ������ ����� NetBIOS

Page 100: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

100

*� �����

-������ �� ���

46h "�������� ����� 47h #��� � ����� �� ������ 48h (������ ��� �������������� �������� ��� ����� 49h-4Fh

0������ �� ���

50h ���� ��� ��5��� ��� 51h 0������ �� �� 52h *���� �� ���� ���� ����� 53h .���� � ����� ���� Int 24h (����������� �����) 54h #����� �� �������������� 55h ��� ��������� ����� 56h 6���������� ����� 57h 6���������� �������� 58h .����� ���� � ������ 59h ����&�� �� ������� ����� ���� 5Ah ��������� ������� ������� �� ����� ���

���� ��� ����� �� ��� ����&�� ����� ���� Int 21h, ����������� ��� ����� � ���� � �������.

����"����� Int 21h, ,�����& OEh: ������! ����0�/ �$�*����/ ����

����&�� �� ���� ������ �������� ����. (���� �� � ����� ���� ��������� �������� ������� ������5��

��������: • !6 – �������� 0Eh; • AL – �� ������ ����� (0 – !:, 1 – ": � �. �.).

(��� �� ������� ����&�� ����&�� � ��5��� ������� AL ���������� ������ ����� ������� ���� ������ ���� �� (����������� ��������� LASTDRIVE ����� CONFIG.SYS).

����"����� Int 21h, ,�����& 19h: ������ ��! ����� ����0�$� ���������

����&�� ��������� ���� ���� ��, ����� ������ ����� ��������� ����5��, � ���� ����������� � ��������.

(���� �� � ����� ���� ��������� �������� ������ !6 �������� 19h.

(��� �� ������� ����&�� ����&�� � ��5��� ������� AL �� ������ ����� (0 – !:, 1 – ": � �. �.).

����"����� Int 21h, ,�����& 1Ah: �+�����! ����� �( ���� �(���� � ������

����&�� ������ �� ��� ����� ������, ��������� ����&��� ��/ � �� � ����� �������.

Page 101: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

101

(���� �� � ����� ���� ��������� �������� ������� ������5�� ��������:

• !6 – �������� 1Ah; • DS:DX – ��������� �� � �� ����� ������ ����� DTA.

(�� ������� ������� �� ������ DTA ��� ������� ����� ���� � ������ PSP:0080h.

����"����� Int 21h, ,�����& 2Fh: �� �*��! ����� �( ���� �(���� � ������

����&�� ��������� ����5�� ����� ������, ��������� ����&��� ��/ � �� � ����� �������.

(���� �� � ����� ���� ��������� �������� ������ !6 �������� 2Fh. (��� �� ������� ����&�� ����&�� � ��5��� 2S:"8 ��������� �� ����� ������ ����� DTA.

����"����� Int 21h, ,�����& 36h: ������ ��! �(1�� ���(����$� ����� �� �����

����&�� ��������� �;�� � ��� ����� �� ������� ������� �����. (���� �� � ����� ���� ��������� �������� ������� ������5�� ��������:

• !6 – �������� 36h; • AL – �� ������ ����� (0 – !:, 1 – ": � �. �.).

" ������ ����� ������� !8 ����� � ��5�� �� OFFFFh (����������� �� ������ �����).

" ������ ������ �� ������� ����&�� ����&�� � ��5���: • !8 – ���� ����� ��������; • "8 – ���� � ����� ������� ; • #8 – ���� ���� ������; • DX – ���� ���� ������� �� �����.

.�;�� � ��� ��������� � ����������� ���� ������� ������� ������ !8, "8 � #8, � ����� �;�� ����� ������ – ���� ������� !8, #8 � DX.

����"����� Int 21h, ,�����& 39h: ��+���! ������� �$ ����&�� ������ ����5�� ���� � ����� � �� �������. (���� �� � ����� ���� ��������� �������� ������� ������5��

��������: • !6 – �������� 39h; • DS:DX – ��������� �� ����� ���&�����&�� ������ ��� ����� ASCIIZ (����� ��5��� ��� �� ������ �� ������� ����, ���� �������; �� ����&�� �� �������� �����, ���� ����������� ����� ������� � � ������ ���� ��).

"������ ��� �����: 03h, 05h.

����"����� Int 21h, ,�����& 3Ah: ��� ��! ������� �$ ����&�� ������� ��������� �������.

Page 102: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

102

*���� ����� ���� ������, ����� ������� ��5���� � �����. (4��� ����� ��������� ������ ���� � �������, ����� �� ����5���� ��� ����� � ������.

(���� �� � ����� ���� ��������� �������� ������� ������5�� ��������:

• !6 – �������� 3Ah; • DS:DX – ��������� �� ����� ���&�����&�� ������� ������ ��� ����� ASCIIZ.

"������ ��� �����: 03h, 05h, 06h, 10h.

����"����� Int 21h, ,�����& 3Bh: ����/�� � ���$�/ ���� �$ ����&�� ������ ����5�� ���� � ����� � �� �������. (���� �� � ����� ���� ��������� �������� ������� ������5��

��������: • !6 – �������� 3Bh; • DS:DX – ��������� �� ����� ���&�����&�� ������ ������ ��� ����� ASCIIZ.

"������ �� �����: 03h.

����"����� Int 21h, ,�����& 3Ch: ��+���! ,�/ ����&�� ������ ���� ��� ������. 2��� ���� ��� ��5��� ���, � �

������ ��������� � 0. (���� �� � ����� ���� ��������� �������� ������� ������5��

��������: • !6 – �������� 3Ch; • #8 – �������� ���� ��� ����� (����. 6.8); • DS: DX – ��������� �� ��� ����� ��� ����� ASCIIZ.

" ������ ������ �� ������� ����&�� ����&�� � ��5��� ������� !8 ��������� �����.

"������ ��� �����: 03h,04h,05h.

�����&� 6.8. ����� �� � ������� ����� 6��� �������

.�������

0 ���� ��� ������ 1 #������ 2 #�������� 3 %���� ��� (������ ���� ���� ����� ��� ���� ���

����� ���� ������� ; ��� ������� ����� ��� ��������� ������� �������� ������� ���� ���� �� � 0)

4 *���� (������ ���� ���� ����� ��� ���� ��� ����� ���� ������� ; ��� ������� ����� ��� ��������� ������� �������� ������� ���� ���� �� � 0)

5 (������ ���� �&��

Page 103: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

103

6-15 0������ �� ���, ����� ���� �� �� 0

����"����� Int 21h, ,�����& 3Dh: ����"�! ��0�����.0�/ ,�/ ����&�� ���� ��� ���� ��� ������, ������ ��� �������

������&��. )�������� ��� 4�� ������ �� ����� ����� �����. (���� �� � ����� ���� ��������� �������� ������� ������5��

��������: • !6 – �������� 3Dh; • AL - ������ ������ (����. 6.9); • DS:DX – ��������� �� ��� ����� ��� ����� ASCIIZ.

" ������ ������ �� ������� ����&�� ����&�� � ��5��� ������� !8 ��������� �����.

"������ ��� �����: 01h, 02h, 03h, 04h, 05h, 0Ch.

�����&� 6.9. ����� ����� ����� ������ 6��� �������

.�������

0-2 -���� ������: 000 – ���� ��� ������; 001 – ���� ��� ������; 010 – ��� ������ � ������

3 0������ �� ��, ����� ���� �� �� 0 4-6 -���� ���������� ���� :

000 – ����� � ���������; 001 – ����� �������� �����5�� ���� ����� � �����; 010 – ����� �������� �����5��� ������ ����; 011 – ����� �������� �����5�� ������ �� �����; 100 – ����� �������� �������� ����� ����� � �����

7 ��� ������ ����: 0 – ������� ��&��� ��������� ���������; 1 – �� ���������.

����"����� Int 21h, ,�����& 3Eh: +���"�! ,�/ ����&�� ������ ��� �� ���� �������� ��� ����� , �� ����

������&�� ������, � ����� � ������ ��������� ����� (���� 4� ��������� ���� ���� ���� �� ����� �����).

(���� �� � ����� ���� ��������� �������� ������� ������5�� ��������:

• !6 – �������� 3Eh; • "8 – ��������� �����. "������ �� �����: 06h.

����"����� Int 21h, ,�����& 3Fh: *����� ��,������� �+ ,�/ � ����&�� ����� ��� ������ �� ����� ��������� �����. #���� ����

���������� � ����5�� ���&�� ��������� �����.

Page 104: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

104

(���� �� � ����� ���� ��������� �������� ������� ������5�� ��������:

• !6 – �������� 3Fh; • "8 – ��������� �����; • #8 – ���� ���� , ������5�� ����� ����; • DS: DX – ��������� �� �����, ����� ����� ���� �������� ��������� ������&��.

" ������ ������ �� ������� ����&�� ����&�� � ��5��� ������� !8 ���� ������ ��������� ���� (� ���� ���� ������ ��������, ������� ������� #8 ��� �� � ����&��, ���� ��&���� ����� ���� ������� ���& �����).

"������ ��� �����: 05h, 06h.

����"����� Int 21h, ,�����& 40h: +����! ��,������� � ,�/ ����&�� ������ ��� ������ �� ������� ������ ����. 0�����

���������� � ����5�� ���&�� ��������� �����. )'» (���� �� � ����� ���� ��������� �������� ������� ������5��

��������: • !6 – �������� 40h; i • "8'– ��������� �����; : • #8.– ���� ���� , ������5�� ������; • • DS: DX – ��������� �� �����, ������&�� �� ��� ������ ����� ����.

" ������ ������ �� ������� ����&�� ����&�� � ��5��� ������� !8 ���� ������ ���������� ���� (� ���� ���� ������ ��������, ������� ������� #8 ��� �� � ����&��, ���� �� ����� ��������� � ���� �����, � ���� ������ �����������).

"������ ��� �����: 05h, 06h.

����"����� Int 21h, ,�����& 41 h: ��� ��! ,�/ )������ ��������� ����. ����&�� �� �������� ���� �� ����&�� � �� ������� �����,

����5�� ������� «���� ��� ������» (4�� ������� ���� �������� ��� ��5� ����&�� 43h, ���� ���� ��� ��� �������).

(���� �� � ����� ���� ��������� �������� ������� ������5�� ��������:

• !6 – �������� 41 h; • DS:DX – ��������� �� ��� ����� ��� ����� ASCIIZ.

"������ ��� �����: 02h, 03h, 05h.

����"����� Int 21h, ,�����& 42h: �+�����! �� �'���� ���+��� & ,�/ �

����&�� ���5��� ��������� �� ������� ���� ���� . (���� �� � ����� ���� ��������� �������� ������� ������5��

��������: • !6 – �������� 42 h;

Page 105: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

105

• AL – �� ���� ������ ������� ��������� (0 – ����� ������ � ������ �����, 1 – � ����5� ������� ���������, 2 – � ��&� �����);

• "8 – ��������� �����; • #8 – ������� ����� ���5����; • DX – ������� ����� ���5����.

" ������ ������ �� ������� ����&�� ����&�� � ��5��� �������� DX � !8 � � ������� ��������� ��������� ������ �����:

• DX – ������� ����� �������� ������� ��������� • !8 – ������� ����� ��������.

"������ ��� �����: 01h, 06h.

����"����� Int 21h, ,�����& 43h, ���,�����& 00h: �� �*��! ����(��" ,�/ �

(�����&�� ��������� �������� ������� �����. (���� �� � ����� ���� ��������� �������� ������� ������5��

��������: • !8 – �������� 4300h; • DS: DX – ��������� �� ��� ����� ��� ����� ASCIIZ.

" ������ ������ �� ������� ����&�� ����&�� � ��5��� ������� #8 �� ������� ����� (��. ����. 6.8).

"������ ��� �����: 01h,02h,03h,05h.

����"����� Int 21h, ,�����& 43h, ���,�����& 01 h: �+�����! ����(��" ,�/ �

(�����&�� �������� �������� ������� �����. ����&�� �� ���� �������� �������� ����� ��� ��� ������. (���� �� � ����� ���� ��������� �������� ������� ������5��

��������: • !8 – �������� 4301h; • #8 – � �� �������� ������� ����� (��. ����. 6.8); • DS: DX – ��������� �� ��� ����� ��� ����� ASCIIZ.

"������ ��� �����: 01h,02h, 03h, 05h.

����"����� Int 21h, ,�����& 47h: ������ ��! ��& ����0�$� ���� �$� �� ���+����� �����/����

"����� ��� ����5� (�����) ������ �� �������� ������� �����. (���� �� � ����� ���� ��������� �������� ������� ������5�� ��������:

• !6 – �������� 47h; • DL – �� ������ ����� (0 – ����, ����������� � ��������

(����5��), 1 – ���� «!:», 2 – ���� «":» � �. �.); • DS:SI – ��������� �� ����� ������� 64 �����, ��������� ��� ������ ����� ������.

Page 106: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

106

" ������ ������ �������� ����&�� ����� ����� ������� ���� � ���� ������ � ����5� ��� ����� ASCIIZ. .������� ���� �� ������� ���� ������������ ����� � ��������� ������� ��4� «\».

"������ �� �����: 0Fh.

����"����� Int 21h, ,�����& 4Eh: ��/�� ����"/ ,�/ +������$� ����

����&�� �5�� �������� ������ ��� �� ����, �� ���� ��5�� ������� ���&�����&��.

(������ ����� ������ ����� � ����� DTA ��� ��� ��5� ����&�� 2Fh.

(���� �� � ����� ���� ��������� �������� ������� ������5�� ��������:

• !6 – �������� 4Eh; • #8 – ����� ������� ����� (��. ����. 6.8); • DS: DX – ��������� �� ���&�����&�� ����� ��� ����� ASCIIZ

(���&�����&�� ���� ������� ���� ���� � ������).

" ������ ������ �� ������� ����&�� � ��5��� ������ DTA ��� ������ ��� ��� ������� �����. ����� ���� ������ ��� ���� ����. 6.10.

�����&� 6.10. ����� ���� ������ ����� ��� ����&�� ����� #��5���� -�����

4������� .�������

00h BYTE 9�� � ������ ����� 01h 11 ���� 3 ���� ��� ����� 0#h BYTE !������� ����� 0Dh WORD #������ 4������ ����� ������ 0Fh WORD 6��� �������� ������ ��������� ������

11h 4 ����� 0������ �� �� 15h BYTE !������� ������� ����� 16h WORD "���� ������� �����:

���� 0-4 – � ����������� �����5����; ���� 5-10 –������; ���� 11-15 –����

18h WORD ��� ������� �����: ���� 0-4 – ����; ���� 5-8 – ����&; ���� 9-15 – ���� �� (��������� 1980 .)

1Ah DWORD -����� ����� ������ 1Eh 13 ���� '�� � ���������� ����� ��� ����� ASCI1Z

����"����� Int 21h, ,�����& 4Fh: ��/�� � ���.0�/ ,�/

Page 107: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

107

����&�� �5�� ������5�� �����, �� ���� ��5�� ���&�����&��, ������� ��� �������5�� �� � ����&�� 4Eh.

(���� �� � ����� ���� ��������� �������� ������ !6 �������� 4Fh. " ������ DTA ����� ��������� ��� ������ � �������5� �� � ����&�� 4Eh ��� 4Fh.

" ������ ������ �� ������� ����&�� � ��5��� ������ DTA ��� ������ ������ ������� ����� (��. ����. 6.10).

"������ �� �����: 12h.

����"����� Int 21h, ,�����& 56h: ������������! � � ����������! ,�/ .

����&�� �������� ����5�� ��� ����� �� ������� � ���� ������� ��� 4�� ������5���� ����� �� �� ������ ���� ( �������� �� ������ �����). "���� ����� �������� ���� (� �� ������5����) ����� .

(���� �� � ����� ���� ��������� �������� ������� ������5�� ��������:

• !6 – �������� 56h; • DS: DX – ��������� �� ���&�����&�� ��5��� ��5� ����� ��� ����� ASCIIZ (���&�����&�� ���� ������� ���� ����, � �� ����� ������� ������ ���� �� ����&��);

• ES: "8 – � � ��� ����� ��� ����� ASCIIZ (���� ������� ���� ����, � �� ����� ������� ������).

"������ ��� �����: 02h, 03h, 05h, 11h.

����"����� Int 21h, ,�����& 57h, ���,�����& 00h: �� �*��! ����& � ���� ��+����& ,�/ �

#���� ��� ���� � ���� ������� ����� � �������� ����������. (���� �� � ����� ���� ��������� �������� ������� ������5��

��������: • !8 – �������� 5700h; • "8 – ��������� �����.

" ������ ������ �� ������� ����&�� ����&�� � ��5��� �������� ������5�� ��������:

• #8 – ���� ������� �����: • ���� 0-4 – � ����������� �����5����; • ���� 5-10 – ������; • ���� 11-15 – ����

• DX – ���� ������� �����: • ���� 0-4 – ����; • ���� 5-8 – ����&; • ���� 9-15 – ���� �� (��������� 1980 .).

"������ ��� �����: 01h, 06h.

Page 108: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

108

����"����� Int 21h, ,�����& 57h, ���,�����& 01h: �+�����! ����& � ���� ��+����& ,�/ �

'������� ���� � ���� ������� ����� � �������� ����������. (���� �� � ����� ���� ��������� �������� ������� ������5��

��������: • !8 – �������� 5701h; • "8 – ��������� �����; • #8 – ���� ������� �����:

• ���� 0-4 – � ����������� �����5����; • ���� 5-10 – ������; • ���� 11-15 – ����.

• DX – ���� ������� �����: • ���� 0-4 – ����; • ���� 5-8 – ����&; • ���� 9-15 – ���� �� (��������� 1980 .).

"������ ��� �����: 01h, 06h.

����"����� Int 21h, ,�����& 5Ah: ����"�! ��0�����.0�/ ,�/ .���� ��� ���� ��� ������, ������ ��� ������� ������&��.

)�������� ��� 4�� ������ �� ����� ����� �����. (���� �� � ����� ���� ��������� �������� ������� ������5��

��������: • !6 – �������� 5Ah; • #8 – �������� ����� (��. ����. 6.2); • DS: DX – ��������� �� ���� ��� ����� ASCIIZ ( ��&� ����� ���� ��������� �� ����� 13 ����, ���������� ������ ��� �������� ������� ��� �����).

" ������ ������ �� ������� ����&�� ����&�� � ��5��� ������� !8 ��������� �����, ����� ��� ������ � ������ ������ � ���������; DS:DX ��� 4�� ����� ����� ��� �� ����, ��������� ������� ����� ������ �����.

"������ ��� �����: 03h, 04h, 05h.

����"����� Int 21h, ,�����& 5Bh: ��+���! ���"/ ,�/ #����� ���� ��� ������. .� ����&�� 3Ch ��������� ���, ��

�� �������� �����, ���� ���� � ����� ������ ��� ��5��� ���. (���� �� � ����� ���� ��������� �������� ������� ������5��

��������: • !6 – �������� 5Bh; • #8 – �������� ���� ��� ����� (��. ����. 6.2); • DS: DX – ��������� �� ��� ����� ��� ����� ASCIIZ.

" ������ ������ �� ������� ����&�� ����&�� � ��5��� ������� !8 ��������� �����.

"������ ��� �����: 03h, 04h, 05h, 50h.

Page 109: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

109

���� ��� ���� ������ �������, ����� ������ ������� Testing �� ����� d:\, � ��� ����� base. " ������ base �������� ���� test2.txt, ����� ��������� 10 ��� �� ��� � �� ����� test1.txt.

%���� ������ � ������� ������� masm model small .stack 100h .data buffer db 10 dup (?) ; ����� ��� �������� �������� ����� �� ����� catalog1 db 'd:\Testing',0 ; ��� ������ � �������� ����� ���� ; ����� catalog2 db 'base',0 ; ��� ������ catalog3 db 'd:\temp', 0 name1 db 'test1.txt',0 ; ��� ����� ��� �������� ���� ����� name2 db 'test2.txt',0 descriptor dw 2 dup (?) ; ����� �� � �� � ��������� 4������ .code prog: ; $ ����� &����� mov ah, 00h mov al, 03h int 10h mov ax,@data mov ds,ax (�� ������� �������� ��� ������� ����� ���� ������5�� ���� ��� ���� �����, � ����� ����� ����� ����� �� ��. ; ������� ���������� Testing �� ���� d:\ mov dx,offset catalog1 mov ah,39h int 21h ��� ��� ��� �������� base �� ������� � � �������� �� ��� ���� �����, � ����� �� ��� ������ ����� �� �� ��������� ������ ������� d:\Testing ������ � ��� . ���� ��� ��� ����� ����� ������� base. ; #�� 1 ; %���� � ���������� d:\Testing lea dx, catalog1 mov ah,3bh int 21h ��� ��� ������ � ��� ����� ����� d:\Testing, ��� ����� ����� ������� base. ; #�� 1 ; ������� ����������� base � ������� d:\Testing mov dx,offset catalog2 mov ah,39h

Page 110: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

110

int 21h �� ����� � �����, ������5�� ��������� ������, ������ � ��� ������ ������ �� ����� �����, �� �������� ��������� �����. " ����� ������ ���� ���5���� � ����� �����, �����5����� �������� d:\temp, ����� ����� ��� ��� �� � ��5�� ������5� ������� ���. ; #�� 2 ; %���� � ���������� d:\temp lea dx, catalog3 mov ah,3bh int 21h ; #�� 2 ; $������ ���� d:\temp\test1.txt �� ��� lea dx, name1 ; ������ �� ����� ��������� �� ����� ������, ; ������5�� ��� ����� mov al, 92h ; ��� ������ ������ � ����� (����. 6.9) ; ���� ����� ��� ������ � ������ ; ����� �������� �����5�� ����� � ����� ; ������ ���� ������ mov ah, 3dh int 21h mov descriptor[0], ax ; ��������� ���������� ����� (�����������, �� ��������� ������ � �� ���� ������ d:\Testing\base, ��� �� ��������� ����� ��� � ������ � ��� ������ ���� � ����� . ��� ��� ������ ��� � ���� ��� ( ������� ������ ��� ����� ������, ������5�� ����� ���� � ��������� ������) ��������� ������ ������ � ��� ������� ����� d:\Testing, � ����� ������� ������� base, ����� ��������� ���. ; #�� 3 ; (����� ������� d:\Testing lea dx, catalog1 mov ah,3bh int 21h ; #�� 3 ; %���� � ���������� d:/Testing/base lea dx, catalog2 mov ah,3bh int 21h ; #�� 3 ; ������� ���� test2.txt � ���������� d:/Testing/base mov dx,offset name2 mov cx,00h ; �������� ���� ��� ����� (����. 6.8) mov ah,3ch int 21h mov descriptor[2], ax ;��������� ���������� ������ ����� ����� ���� ����� ��� ������. .������ descriptor[2] ����� ��� �� ������ ���� ����� � descriptor. ����� ������ 4� � ������� ����� ���5����, ���� ����������� ���������� descriptor � ���� ��������

Page 111: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

111

� �������� ������. :��� 2 ����� �� ���� �� � ���, �� ��������� ����� �������� � � ����� ������&�� � ��� ��������� ���������� ��� ����� test1.txt (descriptor[0]) ���� ������ �� � � ����� ������ �� ������, � ������5�� ������&�� ��� ������ ��� ���� � ������ ����� (���� �� ��� ��������).

; 1��� �� ���� test1.txt ����� ���� �������� mov bx, descriptor[0] mov cx, 10 lea dx, buffer ; ��������� �������� �� ����� ������&�� ; ������ �� ������, ����� ��� � ������ ; ���� ����������� ���5����� ��������� ; buffer mov ah, 3fh int 21h ; �������� �� ������� �� buffer � ��� test2.txt mov bx, descriptor[2] mov cx, 10 mov ah, 40h lea dx, buffer int 21h ; -������ ��� test1.txt mov ah, 3eh mov bx, descriptor[0] int 21h ; -������ ��� test2.txt mov ah, 3eh mov bx, descriptor[2] int 21h ; $��� ��� ��������� mov ax,4c00h int 21h end prog

" ��� ������ ��� ������� ��� �������� ��������� ��, ��� �������� ���� 4������ � ������� ���.

«9�� /1» ����� �� � �� ������. -��������� �������� «9��� /1» � ������ ������� �������� base. �� ������� �������� base ��� ������ ��� ����� ���� ��� �������� � �����. �� 4� ��������� �������� �������� ������ ������ catalog2 �� ‘d:\Testing\base’. (��� 4� �� ��������� ������ �� ��� ��������� �� ��� �� ����� ���� � ����� . 2��� ��������� ������ ������� ������� ��� ������, � ������� ������, ��������, � ������ ���� ������� ���.

«9�� /2» ����� ����� �� � �� ������. -��������� �������� «9��� /2» � ������ �������� ���������� ��� ����� test1.txt. 0���� �����

Page 112: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

112

����� ������ �������� ���� ������ � ������ name1 �� ‘d:\temp\test1.txt’.

«9�� /3» ����� �� ���� ������. -��������� �������� «9��� /3» � ������ ������� ����� test2.txt ������ d:\Testing\base. ��� ��� ��������� name2 ��������� ���� ��� �����, ��������� ����� ��� ������ � ��� ������ ���� � ����� d:\Testing\base, �� ���������, ����� ������, � � 4����. ����� �����&�� ���� ���� ����� ���� ������ ����5��� ����� ����� ‘test2.txt’ �� � ���� ��� ‘d:\Testing\base\test2.txt’. 2��� ������� ���� ����� ���� � ���� ����� �����, � ���������� � ������ ������� ������. 2��� ������� �������� ���� � ���� ����� �����, � ����� ��������� � ������ ��� ������.

-����� �� ������������ ������: -��������� �������, ������5�� ����� �� �� ���� �� �

������� �������. "�� ������� ����� ���� ������� �� �� � ����&��� ������� ������&�� ������, �.�. �� ��� ��&����� ����� �������� ���� �� � �������� � ��������������, ����� ���������� ��������� ���������� �����.

"������0 1 " ���� � ����� ����� �� 8 �������� �� (����� ����� �� 2

����� ������&��). (������ ������� �� , ����5�� �� ����� ��������� ���, �������� � ������5��� ��� ���:

- ��� �� � � ���� – 4� ��� �� � � ���� ��� �� �; - ���� � � ���� – 4� ������ � ��� ����� ���� �� �� �; - ������ � � ���� – 4� ����� � ����� ���� ������ �� �; - � �.�. 0������� �������� ���� �� ������ ����� ( ������ DOS)

������� � ������� ������� �� � � ������� ������� ������.

"������0 2 (������� �� ����� ����� ��������� � ��������� ����������

����� (�� ���� 25). .��� ��� ����� ���� �� �����, � ����� � ���� ������� ����� �����& ����� � �� � ������ ����.

"������0 3 ���� ������� � ������ � ����, �����5���� �� ������:

������ ����, �;�� ������, ���� ���������� �� �����, ������� �����&� � ���. -��������� ������� ����� ������������� � ��� � � ������ ���� � ������ �� �������� ����, ��� ��� ����� ���������� ����� ������ ����� � ���.

"������0 4 ���� ������� ����������, ����5�� �� �� , ������� �����

�� ��� ����� 25. 0������� ���������� �������� ���� � � ���� �� 4���� �� �, ������5�� ����� 6 ��� � .

"������0 5

Page 113: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

113

���� ������� ����� �� 200 ��� � . -��������� ������� �������� �� ����� ����� (�������� ��� ��, ������ ��� ��, ��� �� ��� ��).

"������0 6 -��������� �������, �� ���5�� ���� ����� ������/�������

���� � ����� �����, ���� ���������� ��������, � ����� �������� ������� ����� �����, ��������� �;�� ��� � ����, �� ��� ����� 255.

"������0 7 ���� ����� �� 144 � ��������� ���������� �����, �����������

�� �����&� 12×12. 6���� � � ���� ���� «resul.txt» ���������� �� ���, � ����� ���� ����� � ����&�, �� � ��������.

"������0 8 ���� ������� �� �, ����������� ������� �����, ��� � ���

�������. #��� ��� �������, ����� ������ ����� �� �, ���������� �� �, ������� ���� ������, � ����� ���� ������� �� ����� �� �, �������5���� ����� ������� ������� ���. -�������� �������� ������� ����������� ����� �����.

"������0 9 ���� ������� ���������� ����� (�� ���� 12 ���� ) � ��������� ������� �����, ��� � ��� �������. '�������� �� ����� ����� �� ���� �����, ���5�� ����� ������, ���� �� ����� ����� 4�������, ������5� �� 4�� �����. (��� ���������� �� ���� �� ���� ��� ��� ������� ����� � �����, ������5���� �����.

"������0 10 � ����� �� ����� ������� � N �����, ������� ������ � ����

������� ��������� (�� ���� 16 ���) � ����������� ����� ������� �� � �� �����. 0������� �������� ����� �� ���� ���� �� ����� �� ��� �����, ��� ����� ����� � �� ���� ��5�� ����� �� �� ����� ����� 50. " �������� ���� �������� �����, ������� ������ �������&�������� ������� ���������.

"������0 11 #�� ���� ���� ��� �������� � �� ����� �� ���� . 0�������

� �� ����� �� ���� ���� �� ��� �� �� ��� ����� � ���� �� ���&�� �����, ����� �� � ������ � �� ���� ��5��� ��� ���� �� ��.

"������0 12

Page 114: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

114

#���� ��� �������� ����� /1 ���� /2, �� ����������� ����� ������� ���� ������ � ��� ������. '���� ����� (- ), �������� (- ), ������5�� ����� � ����� ���� ������ ���� ����� � ��� ������.

"������0 13 #��� ��� �������, ����� �� ���� ������� ������5�� ����� ��:

1. ������ � �� ���������� ����� �� �����, ����� ���� �� ����� �� ��� ����� 255 (����� ���� �����������);

2. ������ ��� ������� �����; 3. ���� ��������� ����� ����� 255, � �������� ������� ���� ���������� ���� � ������ «pereg.txt», ����� ���� «normal.txt»;

4. ���� �� ������ ��� ��� «ESC» - �������� �������� ������� � ������ /1;

5. ���� ������� ��� ��� «ESC» � ���� �� 4���� �������� �� �� ���� � ������������, � ���� ���� ���� �����.

"������0 14 6� ����� ������� n ���� ������5�� ������ ��� ���������

�� . '���� ���� �� ����� ����� ������5�� �� «fileX.txt», �� X – 4� ���� ����� �� ����� (X∈(0…n)). 0������� ���� «otvet.txt» ����� ���� , ������5�� �� FF � ������� � �� ��� ��� ���� �����.

"������0 15 '� ���� ���� ����� ���� (����� ���� ����� ���� ������)

��������� ���� � ���������� ������� � ��� (��� � ). -�������� (��� ����� � ������� ��� ) �������� ���� «otvet.txt».

"������0 16 #��� ��� �������, ��������5�� �������� ����� A ���� B.

'���� ���� �������� ���� ������. #��� ��� ��������� �������: - ��� ������ �� ����� A �� ����� ������� � �� � ����� � �����������5�� �������, � ����� ���� ������ ���� �� �;

- ��� ������ �� ������� ����� �� ����� � ������ � �� � � ��������� �������������� � ��������� ���� �� �;

- ��� ������� ����� A � � ��� ����� �� ����� ������� ����� ���������� �� ���������� ���� � ��� ���������� ���� ������ ����������.

"������0 17 #��� ��� �������, ������5�� �� ��� �� ����� �� �����

«new.txt», � �������5�� ����� �� ���&�� ����� «data.txt» ��� ��������� ����� �����.

"������0 18 ���� «data.txt» ������� ����� ���&��, �� ����� ���� ��� ����

��� �� ����� ����� «new.txt», ���� ������ ��� ������ ��� ��. #��� ��� ������� ������� �� ��� � ����� ���&��, ��������� ����� «data.txt».

Page 115: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

115

"������0 19 #��� ��� �������, �������5�� ���� «result.txt» ����� ���� �

�� ������, ���� ��� ��� ���� , ������ ����� ��� ����� ������, �������� ���� ������, �� ���� ��� �� � � ��������. #���� ���� ���� ���� ����� ������ �����������.

"������0 20 #��� ��� �������, �������5�� �������� �����, ������

���� ������. "�� ��� � «�» � �� ���&�� ���������� ������ �����, ���5����� ���� «a.txt», � �� ��� � «b» - ���� «b.txt». "�� �������� ��� �� ��������.

"������0 21 ���� «1.txt» ������� � �� ���� �� �������&��� ��������� �����.

���� «2.txt» ������� ����� �� � �� ���� �� �������&��������� �����. #��� ��� �������, ����� ������ ��� ���� «3.txt» ������� ���� ������ �� ���� ��5�� ����� �� ��� � �� ���� .

"������0 22 ���� ���� ����� (��� ����� ������ � ��� ������ ����

�������� �������) ������� ���� �� . #��� ��� �������, ����� ������ ��� ���� 1.txt ���� �� �, ����5�� �� �� ��� ��, ���� 2.txt – �� �, ����5�� �� � �� ��� � , ���� 3.txt – �� �, ����5�� �� ���� ��� � � �.�. 2��� ����-��� �� ���� �� ��� (�� � �� 1 ��� ��, ��� �� 2 ��� � � �.�.), � ���� � ������, ��������5�� ������� ��� � ����� �� � 4�� �����, �� ��������. 2��� �� ����� ���� ���� � ����� ������. � � ����� ���� ������.

"������0 23 #��� ��� ������� ���� �� �� ��� � �� ���� �� ACSII

(866 – MS-DOS) ���� �� ANSI 1251 (Microsoft Windows) � ����� � ������ ���� �����. )����� ������� �� ����� �����, ����� ��� ��������� ���� ����, ���� ������ ���� �������� �������.

"������0 24 6� ����� �������� 10 ���� � ����� � ������&���. '����

���� �� ����� � ������ ��&���� �������� �������. 0������� ����, ��� ��� ������ ���� ����� ��&���� �������� �������, ����� ���� , ������5�� �� �, ����� ���������� 7 ������ ��� .

"������0 25 #��� ��� �������, ����� ������� ������� ��� � �����,

������� ���� ������ (��� ����� � ��������� ����). 2��� ������� ��� � �� � ����, � ���� ���������, ����� ����5�� ��������� �������� �����������, ��� ���� �� ���� ��� ����� �����, � ���� ����������� �������� ��������� � �������� � ����� new.txt.

Page 116: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

116

"������0 26 6� ����� ����5�� �������� ������� 10 ����� �� ���� : 0.txt,

1.txt � �.�. #��� ��� �������, ������5�� �� �������� ���� ������&�� ����� ������� string1 � string2. " ������ ������ �� ����� string2 ��������� �� ������&��, ������5�� �� ����� string1. #���� string1 � string2 ����� ����������.

"������0 27 .��������� �������� ������� ����, ��������� ������� (�����

���� �� ����� ������� � �� ������� �� ����� 5), ����� �������� �� ����� d:\ �������� �������� ���� ������ ���� �������� �������. 0������� ��������� ����, ��� ��� ����� �������� ���� ������.

"������0 28 ����� 1.txt � 2.txt ������� � 10 �� ������. 0������� ���� 3.txt

�� �� � �� ���� 1.txt � 2.txt, � ������ ��������� � ������� � ��� , �� �� ���� � ������������� �� � ������� ������.

"������0 29 '������� ����&�� ��������� ������� ��������� �����

����� ��� ������ n-�� ��� � �� ����� old.txt ���� new.txt, �� n-�������� ���� ������ ��������� ������� ��������� (� 0 � 255) ���� �������� �������. " �����������5�� ����� ����� ����� ��� �� ����� ���� ��������� ��� �� «�����».

"������0 30 " ����� a.txt ����� ���� �� . 0������� ���� result.txt �������

������� ��� ���� �� � ���� b.txt. *������ ������� ������� ��������� ������� ���������. -�������� ���������� ������� �� 4�����.

����� �� ������: �� ��5��� ��������� ����� ��������� ��� ��� ���������

�� �� ����� ���������, ������ ����� ��� �������� ������� �����. .����������� ��� ��� ������ � ��5��� ��������� ����� � ������ ��������&�� ������������ ������� �����, � ����� ����� �;������� ������� ����� �������.

Page 117: instructor.sdu.edu.kzinstructor.sdu.edu.kz/~ivanov/ASSEMBL_15/METOD(AS… ·  · 2015-08-2856 ˆ 21h 4˛ ˝ , ˛ ˛ ˝5 dl ˆ. mov dl,al ; dl ˝ al mov ah,02h ; ah 02h int 21h ;

117

��)��)2�

1. = � ". Assembler. – #(�: «(����», 2000. - 624 �. 2. "���� = � . Assembler. #��&������� �����. #��� ��� ��� ��� . – #(�: «(����», 2000 – 496 �.

3. "���� = � . Assembler. #��&������� �����. #��� ��� ��� ��� . – #(�: «(����», 2000 – 496�.

4. %����� ���. !��������� ������ � IBM PC. . – #(�: «(����», 1999 – 816�.

5. "������������� ������ � �������: )������ ��� �� /". .2���� � ��. - %.: "���.��., 1993. - 292�.

6. !��������� 1.(., (��� !.*. (������� ���� �� ����� !��������� *-580 / (� ���. !.!. ������.-%.: %��. 4���. ��-�, 1986.-96 �.