     17 

        

          ,    C++, 
      .    
       , ..  
,     . 
      Borland C++       
 ,      .  
 ,        
   ,   C++. 
  : 

          ,    
 ; 
               ; 
          . 

         ,     
   . Borland C++    
    ,   C++. 

             . 
          asm   . 
         ,    Turbo Assembler (TASM). 

          ,     
 . Turbo Assembler  Borland . 

        

          ,  
          C++  
 .        
    ,    
 .        
      .      
-.      , 
    ,    . 
    

    438 30 

    

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

               
,    ,   Borland C++.  
        
.    -     
  ,   .     
MYPROG.CPP   - myprog   MYPROG.ASM,  
     .    
 TASM   MYPROG.CPP   ,   
  MYPROG.ASM.     : 

    pragma inline 

      . ( 
#pragma     .) 
          -  
          C++. 
      ,  - 
      .   
 -    -Ename,  name   , 
 Microsoft Macro Assembler (MASM). 
            -S   
  ,    TASM       
 .ASM. ,    ,   
      
  .       
 , ,  ,    
 .   MYPROG.CPP  bcc -S myprog, 
   MYPROG.ASM.      
,    TASM.EXE,     (  
   C:\BC45\BIN),    bcc myprog .asm. 

     

            .  
        
  DOS. (     
  asm.      .) 


    ,   void 

       -S ,     , 
  void.        S. 
  17.1    DOS   bcc -S voidf.  
   VOIDF.ASM   . 
            
  (    ,   
,     ),   17.2 
   VOIDF.ASM,   . 

    

       ,  ,   Borland C++ 
3.1.   4.5   ""  (,    
  jmp,  ,     17),  
    ,     
  ,      . 

     17.1.  VOIDF.CPP (     -S) 

    1.   #include <stdio.h> 
    2: 
    3    void f(), 
    4 
    5:   main() 
    6'   { 
    7      f(); 
    8:     return 0;
    9-   } 


     17.      439 31 

    10: 
    11:	void f() 
    12:	{ 
    13:	   int x = 123; 
    14:	   printf("x == %d\n",  x); 
    15:	} 
    
    
     

    e      VOIDKASM.     
       17.1  
 -S.    VOIDFM.ASM (   )  
 17.2.        . 

     17.2. VOIDFM.ASM (     VOIDF.CPP) 

    1:	_ segment byte public 'CODE'	;    
    2:	;
    3:	; main() 
    4:	; 
    5:	assume cs:_TEXT	;  
    6:	_main proc near	;  main() 
    7:	push bp	;   
    8:	mov bp, sp	; bp  sp 
    9:	; 
    10:	;{ 
    11:	;f(); 
    12: 	;
    13:	call near ptr @f$qv	;   f() 
    14: 	;
    15:	;return 0; 
    16: 	;
    17:	xor ax, ax	;   -    0 
    18:	jmp short 1058	;  ! 
    19:	91958: 
    20: 	;
    21:	;} 
    22: 	;
    23:	pop bp	 bp 
    24:	ret	    
    25:	_main endp	  main() 
    26:	; 
    27:	; void f(void) 
    28:	; 
    29:	assume cs:_TEXT	  
    30:	@f$qv proc near	  f() 
    31:	push bp	  bp 
    32:	mov bp.sp	 bp  sp 
    33:	sub sp,2	    
    34: 	;
    35:	;{ 
    36.	;int x = 123; 
    37: 	;
    38:	mov word ptr [bp-2],123	;  123   
    39: 	;
    40:	;printf("x == %d\n", x); 
    41:	; 
    42:	push word ptr [bp-2]	   
    43:	mov ax, offset DGROUP:s@	   s, 
    44:	push ax	;    
    45:	call near ptr _printf	;  printf() 
    46:	pop ex	;    
    47:	pop ex	;    
    48: 	;
    49:	;} 
    50: 	;
    51:	mov sp.bp	;    
    52:	pop bp	;   bp 
    53:	ret	;     
    54:	ef$qv endp 
    55:	?debug  9 .	;   
    56:	?debug  FA00000000	;  Turbo Debugger 

    
   440      IV.   

    57:	_TEXT ends 
    58:	_DATA segment word public 'DATA'	;   
    59:	s@ label byte			;   printf() 
    60:	db 'x == %d'			;  printf() 
    61:	db 10				;   
    62:	db 0				;,   
    63:	DATA ends	  
    64:	TEXT segment byte public 'CODE'	;   
    65:	_TEXT ends			;  
    66:	public _main			;  jnain 
    67:	public @f$qv			;  f() 
    68:	extrn _printf: near			;  printf() 
    69:	_s@ equ s@			;                
    70:	end				; 

         ,  
        . 
 main()       ,   
 _main      . (    
   .)  ,   ,  main, 
    (_main).   7   b 
  ,      sp.  b 
 ,   ,     
   . 
      13    f(),     
@f$qv.        .  
,    C++     9-12.  
      . 
      17-19      main().  
  (),       , 
  ,     ( 15). 
 jmp   17, ,       
   .  ,     
     .   
     ,     
(       ). 
    ,  main()    23, 24, 
   b (   7)  
     main()    ,  
        
    .. 
         f() ( 30-54).    
    b,      
  ( 31).         
   (    )  b 
    sp ( 32).    
      main().    
 . 
      33   ""  ,   
         
 ,   f() ( 36).  mov   38 
   123     . 
    b      
.      printf()   4247.  
           s, 
    .   ,  
  VOIDF.CPP ( 14  17.1  40  17.2).  
          .  
  ,  s,    . 
        ,     
printf()   45.         
 _printf.     printf()   pop   
46  47  ,      ,  
      . 

     

             
     ,     
        .  
    Pascal (, ,  
 Microsoft Windows)      .
          
,         . 
   Pascal   ,   
     . 


     17.         441 

     f()    51-53,    
  ,     , 
   33.         
.   52    ,  
  ret       f(). 
       ,     
 ( 55, 56),      ( 
59-62)  ,     printfO, 
   ( 66, 67)    
  printfO ( 68). 
             ! 
 ,  ""      
.     ,      
,           
. 

    ,  	

      ,      : 
    ,    al;    
    dx:ax,  dx  ,     
;        
80x87;     ;    . 
         .    
,      ,   
 -S       . 
     ,   
    .    
      ,    
 -    ,  "  . 

        

        -   .  
      ( 17.3).    
  bcc -S classf       
 CLASSF.ASM. 

     17.3.  CLASSF. (   -S) 

    1:   include <iostream.h> 
    2: 
    3: class TClass { 
    4: public: 
    5:    int x; 
    6:    void SetX(int n); 
    7:    int GetX(); 
    8: }; 
    9: 
    10: main() 
    11: { 
    12:   TClass q;
    13: 
    14:  q.SetX(123); 
    15:  cout  "q.GetXO == "  q.GetX()   '\n'; 
    16:     return 0; 
    17:   }
    18: 
    19: void TClass::SetX(int n) 
    20: { 
    21:  x = n; 
    22: } 
    23: 
    24: int TClass::GetX() 
    25: { 
    26:    return x; 
    27: } 

      TClass   38     (int x)   
-      .    - 
SetX()     3.1   : 

    push bp		;  
    mov bp, sp	;   bp 
    push si		; si,   
    mov si,word ptr  [bp+4]      ;   'this' "  si 

    
    442      IV.   

    mov	ax,word ptr [bp+6]	;     
    mov	word ptr [si],ax	;     
    pop	si	; si 
    pop	bp	; bp 
    ret	;    

      4 5      ,  
  bp   ,     
   sp     ,    
 int n ( 19   173)     si  
   bp  si    this  
   -     this 
  ,       
-,      q,    main()  
 12     si  this   
    [+6],     n  
        word ptr [si], 
     q (  si)   , 
        si  bp 
        ,   -  
  this  ,       
         this 
      

       BASM 

    ,       
,           
         
  (BASM)     
     
             
      TASM    
            
 BASM           , 
    ++.
        ,    BASM  
    TASM.

      .
          80386  80486 .
             TASM 
            .

           ,   
  TASM    ,     
   C++          
       TASM.
,         
   C++,          
. ,     80386      
 ,   TASM.



           80186  80286,  
   BCC   -1.        
   80286,   -2.


        asm

     asm        
   .    asm 
     ,      
           asm :

    asm  [] [;]

       asm      (), 
 mov  shl.   ,       
           .  
     .      , 
     . ,   TASM   
 :

    mov ax, cx  ;  ax    cx
    
    
     17.    	443 

      BASM   : 

    asm mov ,  ;	/*     */ 

       asm      
C++.     ,    . 
     : 

    asm mov ,  	/*     */ 

        C++: 

    asm mov ,  	//     

      asm     .  
 asm    ,  ,   , 
  asm    ,    if, while    : 

    asm { 
    pushbp	//     
    mov bp,  sp                  //    sp 
    ........ //    asm    
    pop bp	//   

            
   ,        
.         
    : 
    
    asm { 
    push ax; push bx; push ex; push dx 
    .... //       
    pop dx; pop ; pop bx; pop ax; 
    } 

      asm,      , 
    .      
,     - , ,   
      ,    .  
   asm   . 
      asm,    , 
 BASM       .   
 ,    BASM   
 C++, ,     ,    
        -S. 

      

            C++  
 .        
 ,    Turbo Profiler  ,  
      .   
       . 

     

     .    The Mythical Man-Month ( 
-)    ,     
           
 .       . 

         MySquare(),    : 

    int MySquare(int n) { 
    return n * n; 
    } 

            -S.   
    (   ): 

	push	bp	;    
   	mov	bp, sp	;    
	mov	bx, word ptr [bp+4]	; int n  bx 
	mov	ax, bx	; bx   
	Imul	bx	;   bx 
	jmp	short @2@58	;    
@2@58: 
	pop	bp	   
	ret		    


    444      IV.   

         . -,   (  
   +4)         .    
     ? -,  jmp 
     ,   , , 
,        . 
        , ,  
 ,  ,   ,   
,    .    ,    
MySquare()    ,   , 
,       . 
      ,   MySquare()     
  ,      
   .   , 
 ,       
 asm,     17.4. 

     17.4.  INLINE.CPP (  MySquare()   
 asm) 

    1:   #include <stdio.h> 
    2: 
    3:   int MySquare(int n); 
    4: 
    5:   main() 
    6:   { 
    7:     int i; 
    8:     int array[10]; 
    9: 
   10:     for (i = 0;  i < 10;  i++) 
   11:       array[i] = MySquare(i); 
   12:     for (i = 0;   i < 10;  i++) 
   13:        printf("array[%d] == %d\n",  i,  array[i]); 
   14:     return 0; 
   15:   } 
   16: 
   17:   //   "Function should return value" 
   18:  #pragma warn -rvl 
   19: 
   20:   int MySquare(int n) 
   21:   { 
   22:   /* 
   23:     return n * n; 
   24:   */ 
   25:    asm { 
   26:       mov ax, word ptr n 
   27:       imul bx 
   28:     } 
   29:   } 
   30: 
   31:   //     
   32:   #pragma warn +rvl 

      22-24       
.         
 . -       
    , , ,    
 80x86.          
 asm        C++. 
      25-29      . 
       .     
  (       
[+4]).         ,  ASM 
  . 
      28     ,    ( 
  )    dx ( )   ( ). 
,        
,   jmp  . 
     ,    ,    
MySquare()   return.   ,  
  ,         
#pragma warn,     18.  

    #pragma warn -rvl 

 ,   

    #pragma warn +rvl 


     17.         445 

     .     ,    

    #pragma warn  .rvl 

        .   
        ,  
-wrvl.    ( )   
 Borland. 
      ,  MySquare(),    
 .          -S  
   .   MySquare   : 

    push bp 
    mov	bp, sp 
    mov	bx, word ptr [bp+4] 
    mov	ax, word ptr [bp+4] 
    imul bx 
    pop	bp 
    ret 

          .   
   ,    jmp . 
  ,    bp.   
  ret. 
         ,     
 .         , 
     . 

       

       ,  , jmp  jnl,   
  ,    .   
 TASM    .  ASM  
 asm        C++,  
,    goto.    
  asm   ,   goto. 
           C++,    
-   asm. , ,     
        ,    
     .    
 ,   ,  : 

    asm { 
        jmp L1
       db 13, 10, ' 1992 by Tom Swan', 0 
    } 
    L1: 
    asm { 
      //...   
   } 

     jmp L1   db ( ),  
  (13),   (10)       
(        ).  
 L1     asm,     
   C++     asm,    . 
          ,  jnz, jl  
.       ""  , 
    . ,    

    asm jne TARGET, 

    BASM    (,   )  
   ,       TARGET   
  -128  +127 .       
, ASM        
  .      
   : 

    asm je TEMP 
   asm jmp TARGET TEMP: 

         ,   
 .  jmp  je      
,     jne,   ""  . 
    ASM     .    

    asm jmp LABEL 


    446      IV.   

 LABEL       -128  +127 , BASM 
   2-  .    
     ,  BASM   
 3-  jmp. 
       ,     NEAR PTR 
 FAR PTR. ,          
 : 

    asm jmp FAR PTR LABEL 


       

      asm      ,   
 .       
. ,     WORD PTR  
BYTE PTR   16-  8-   .   
   count  

    asm mov ax, count 

 : 

    asm mov ax, WORD PTR count 

        count      
 : 

    asm mov al, BYTE PTR count 

        DWORD PTR    
LES       32- , .. 
  "double word" ( ). 
         asm  si  di  
   .    asm  
 si  di,       . 

        

      asm       . 
     ,    
,    (   ). 
    ,    TPoint      
 .   typedef (  C++,    ANSI )   
   : 

    typedef struct point { 
    int x; 
    int ; } TPoint; 

             cursor 
 TPoint: 

    TPoint cursor; 

        C++  cursor.x  cursor.y    
 cursor.   asm    
. ,         
 cursor  : 

    asm mov ax,  WORD PTR cursor.y //      

             
    OFFSET: 

    asm mov bx, OFFSET cursor.y  //      

        . ,    
  ds:di   cursor        
 : 

    asm {
      mov di, OFFSET cursor	//   cursor  di 
      mov ax, [di].y                           //       
    }

     ds       .  
   di.        
cursor  TPoint. ,   ,     
      .     , 
         : 

asm {
    mov di, OFFSET cursor    //   cursor  di 
    mov ax, [di].(TPoint)y        // ,        
}    

     17.    	447 


        

      BASM      - 
  ,  ,     ,  
 .       
    (Turbo Assembler ), 
 Borland . 
    ASM   .     
,    .     
   :       
 .  TASM      ,  
     -  
 . 
      TASM      C++ ,  
    (  .OBJ)  ,   
   .       
  C++,  ,    ,     
  . 
        BASM,     
   .      , 
   ,      ,   
         .. 
       ,   
    . 

      H2ASH 

             
      .   
     , ,  ,  
  C++,      ""  
         . 
     H2ASH.EXE,    TASM,    
    : "       
     ?" H2ASH  , 
      C++    TASM, 
     .ASH (  ).   
         
,  ,    . 
     H2ASH       C++. 
  #include      
   MASM-  TASM.  , H2ASH  
  ,     
.      ,  , 
       TASM.   
H2ASH  ,           
C++   .  32- ,    H2ASH32. 

   

      TSM-UTIL.TXT ,   \DOC,    
    H2ASH.

       H2ASH,     
  . ,    DB.H 
( 11.15)   11.   ,   ,  
  h2ash db.h     DB.ASH   
 TASM.   DB.H    STDIO . 
 H2ASH       ,   DB.H. 
(   H2ASH         
  ,   .) 
       ,  H2ASH   
   . ,  DB.H  
 : 

   #define FALSE 0 
   #define TRUE 1 
   #define NAHELEN 30 
   #define ADDRLEN 30 
   #define CSZLEN 30 
   #define PHONELEN 13
    
    
    448      IV.   

     H2ASH      TASM: 

    FALSE	EQU  
    TRUE	EQU 1 
    NAMELEN	EOU 30 
    AODRLEN	EOU 30 
    CSZLEN	EQU 30 
    PHONELEN	EQU 13 

     H2ASH " "    : 

    typedef struct record { 
      union { 
        long numrecs; 
        long custnum; 
      } info; 
      char name[NAMELEN]; 
      char addr[ADDRLEN]; 
      char csz[CSZLEN]; 
      char phone[PHONELEN]; 
      double balance; 
   } Record; 

            H2ASH,   
   TASM: 

    tag$1UNION 
    numrecs	DD             ? 
    custnum	DD           ? 
    tag$1ENDS 

    record	STRUC 
    info tag$1 <>
    name DB 30 DUP ( ? ) 
    addr DB   30 DUP ( ? )
    csz DB     30 DUP ( ? )
    phoneDB  13 DUP ( ? )
    balance     DD   ?
    record	    ENDS 

         , ,  numrecs  
phone,  H2ASH    ,  tag$l.   
 ,       C++,    
  : 

    GLOBAL  CreateDB	:NEAR 
    GLOBAL  OpenDB	:NEAR 
    GLOBAL  ReadRecord	:NEAR 
    GLOBAL  WriteRecord	:NEAR 


       TASM 

      ,     . 
         Turbo Assembler. 
     TASM,       " ". 
      17.5   Timer()       
,     0000:046     
BIOS.     .    ,  
   Timer(). 

     17.5.  TESTTIME.CPP (  Tlmer())	

    1:   #include <conio.h> 
    2:   #include "timer.h" 
    3:
    4:  main() 
    5:  { 
    6:	while (!kbhit()) { 
    7:	  gotoxy( 1, wherey()); 
    8:	  cprintf("%ld" ,  Timer()); 
    9.  	} 
   10:  	getch(); //    
   11:	return 0; 
   12: }

         ,     
  Timer(),     .   2 
    ( 17.6). 


     17.    	449     
    15   C++4.5 


     17.6.  TIMER. (    Timer()) 

    1:   // timer.h --    timer. 
    2: 
    3:   extern ""  { 
    4: 
    5:     long Timer(); 
    6: 
    7:    } 

          C++    
 extern "" { }.      
 ,   C++     
 ,      
- . ,    TimerO   
 @Timer$gv.     , , ,  
       . 
( ANSI     ,      
   C++.) 

   

          (, 
      ,     
  C++),           
-S       . 
    ,    
   . 

       ,     
    Timer().   17.7   
 Timer()      TASM. 

     17.7. TIMER.ASM (  Timer()    ) 

    1:	IDEAL 
    2:	MODEL small 
    3: 
    4:	CODESEG 
    5:	PUBLIC _Timer 
    6: 
    7:	PROC _Timer 
    8:	xor ax, ax ;    0000 
    9:	mov es, ax ;  es  0000 
    10:	mov di, 0046cH ;  di  046 
    11:	mov ax, [WORD PTR es:di] ;    timer 
    12:	mov dx, [WORD PTR es:di+2] ;   	timer 
    13:	ret ;     
    14:	ENDP 
    15: 
    16:	END 

      2        .  
              
 (.  19).    (   
 CODESEG   4)        
PUBLIC.         
    . 
           , 
,   PROC  ENDP ( 7-14).     
      ,  
  ,     b  ds   
 .        
    ax:dx ( 11, 12).     
   b    sp,     
 ,   ,    . 
             
 .   TASM.EXE    ., 
   ,    ,   
TESTTIME.CPP, TIMER.  TIMER.ASM,     DOS  bcc 
testtime timer.asm.   C++  TESTTIME.CPP  
TESTTIME.OBJ,  TASM  TIMER.ASM  TIMER.OBJ , 
       TESTTIMER.EXE. 
        . 


    450      IV.   

          TASM /ml  
        . , 
  tasm /ml timer   TIMER.ASM  TIMER.OBJ, 
 TESTTIME.CPP   - testtime   , 
 bcc testtime.obj timer.obj. 
           ,    
     ,   .    DATASEG 
        : 

		 IDEAL 
		MODEL small 
		DATASEG     ;   
		PUBLIC _MyVar 
   _MyVar 		DW	0    ;    
		CODESEG
    ;         
    END 

       C++   MyVar (   
)    extern: 

     extern int MyVar; 

         MyVar  ,    
   C++.      ""  
 extern,     ,    
C++  . 
        C++      
  XTRN. ,    
 

    int Global; 

d       Global   
 WORD _Global  :

    IDEAL 
    MODEL small 
    DATASEG 
    EXTRN _Global:WORD     ;      
    ;        
    CODESEG 
    ;      
    END 

      17.8   Timer()    
MASM.       tasm /ml timer.rasm,  
     ,   ,    bcc 
testtime timer.obj. 

      17.8.  TIMER.MSM (  Timer()   MASM) 

    1:   .MODEL small 
    3.   .CODE 
    4:    PUBLIC	_Timer 
    5: 
    6:    _Timer	PROC 
    7:   xor ax, ax 
    8:   mov es, ax 
    9:   mov di, 0046CH 
    10: mov ax, WORD PTR es[di] 
    11: mov dx, WORD PTR es[di+2] 
    12. ret 
    13: _Timer	ENDP 
    14: 
    15:  END


      

       ,  -   
 ,        , 
    .      
,       ,    
   .       
     ,   
iret (interrupt return    


     17         451 

).          C++, 
         
  . 
             
 int. ,      DOS   
  DOS: 

    asm int 0x21 //    DOS 

           32-  
,   .     
   80x86        
   ,      
   .      
-       . 

       DOS 

        ASM   asm    
 DOS.  ,    17.9,  
   "Welcome to BASM!$"  :   
    DOS,  . 

     17.9.  BASMWELC.CPP ( DOS   ) 

    1:	#include <stdio.h> 
    2: 
    3:	// ,   $ (ASCII$)   (ASCIIZ) 
    4:	char messaged = "Welcome to BASM!$"; 
    5: 
    6:	main() 
    7:	{ 
    8:	  puts(message); //   ASCIZ 
    9:	  asm { 
    10:	     mov ah, 9 //   DOS   9 
    11:	     mov dx, OFFSET message //   ASCIIS 
    12:	    int 0x21 //  DOS   0x21 
    13:	  } 
    14:	  return 0; 
    15:	} 

      DOS   ,   9, 
   .      asm 
  10   DOS    ah,  dx 
    ,     
DOS    int 0x21   12. 

     

          DOS       
  ,         DOS.

          DOS   9  
     ($),    
  DOS    /.    ,  
,     8   ,   $. 
  ,   asm   ,    
 . 

      BIOS 

         -    
.           
   BIOS (Basic Input-Output System    
-).         
 . 

     

     BIOS      
,        
.   ,    . 
     BIOS      
  .      BIOS,   
    . 


    452      IV.   

      17.10    BIOS,    
   .       
      ,     
  . (    
  .) 

     17.10.  BI6C.CPP (  ) 

    1:	main() 
    2:	{ 
    3:	asm	{ 
    4:	mov	ch,	0	//					 
    5:	mov	cl,	7	//			  
    6:	mov	ah,	1	//					BIOS	1 
    7:  	int	0x10		//		BIOS					 
    8.	} 
    9:	return 0; 
    10:	} 

      asm   3-8      
:   BIOS     
.    4, 5   ch  ci , 
      ,  
 . (     ,   
      .)   
       . 
      6   ah    
 BIOS,     .    
    7    BIOS  
  int 0x10  ,     
   DOS.       
 .  ,      ,  
   ,     . 

        

        DOS  BIOS      
  .     Borland C++ 
   interrupt,    void  
 .      C++     
   : 

    void interrupt AnyName(unsigned bp,  unsigned di,  unsigned si, unsioned ds,  
       unsigned es. unsigned dx, ^signed ex,  unsigned bx, unsigned ax, unsigned 
      ip,  unsigned cs, unsigned flags) 
   {
      // ....      C++ 
   }

    e      ,   
.        , 
      .     
     ,      
.   ,        
,         .
     ,   ,     
   . ,      ,   
     b  . 
           interrapt-.  
      : 

push           ;   
push bx
push cx
push dx
push es
push ds
push si
push di
push bp
mov bp, DGROUP    ;    b     
mov ds, bp                 ;    DS    
mov bp, sp                 ;        


     17.    	453 

           b   
        
  ds.      interrupt-  
    . ,   
     ,       
ds      . 
    ,   ,  , 
      : 

    pop	bp                          ;     
    pop	di 
    pop	si 
    pop	ds 
    pop	es 
    pop	dx 
    pop	x 
    pop	bx 
    pop	ax 
    iret	;      

       ,    , 
   iret,     
 , ,    ,   
  int.       , 
         . 
      17.11       
 ,      asm.  
        DOS.  
     PC 0x1c,    
  ,        
BIOS, ,   ,    . 
    17.2   ,   0x1c 
   ""   ,   
 ,   ,     
.  MULTIP       
   ,     .  
<Enter>         . 

   

        ,  0xb800   5  0xb000.


     17.11.  MULTIP.CPP (   ) 

    1:   #include <stdio.h> 
    2:   #include <dos.h> 
    3:   #include <string.h> 
    4: 
    5:  #define DISPSEG 0xb800 // 0b000    
    6:	
    7: //       0x1 
    8: void interrupt (far *oldVector){...}; 
    9: 
  10: //   
  11: void Initlnterrupt(void); 
  12: void DoWhateverYouWant(void); 
  13: void Deinitlnterrupt(void); 
  14: void interrupt ShowTime(...); 
  15: 
  16: main() 
  17: { 
  18:  setcbrk(0); //     <Ctrl+C> 
  19:  Initlnterrup();
  20:  DoWhateverYouWant(); 
  21:  Deinitlnterrupt(); 
  22:  return 0; 
  23: } 
  24: 
  25: //        
  26: void Initlnterrupt(void) 
  27: { 
  28:  oldVector = getvect(0x1c); // Save current vector 
  29:  setvect(0x1c, ShowTime); // Set vector to ShowTime() 
  30: } 
    

    454	 IV.   

    31: 
    32:	// ShowTime()      
    33:	void DoWhateverYouWant(void) 
    34:	{ 
    35:	int i, done = 0; 
    36:	char s[128]; 
    37: 
    38:	while (!done) { 
    39:	puts("\n\nEnter a string (Enter to quit):"); 
    40:	gets(s); 
    41:	done = (strlen(s) == 0); 
    42:	if (!done) { 
    43:	   for (i = 0; i < 40; i++ ) 
    44:	     puts(s); 
    45:	} 
    46:	} 
    47:	} 
    48: 
    49:	//       
    50:	void Deinitlnterrupt(void) 
    51:	{ 
    52:	  setvect(0x1c, oldVector); 
    53:	} 
    54: 
    55:	//   01.    . 
    56:	void interrupt ShowTime(...) 
    57:	{ 
    58:	asm { 
    59:	xor ax, ax                      // ax <- 0000 
    60:	mov ds, ax                   // ds <- 0000                 
    61:	mov ax, [0x046d]        //    / 256 
    62:	mov bx, DISPSEG     // bx =   
    63:	mov ds, bx                  // ds =   
    64:	mov word ptr [0009], 0x0f07c //  '|'
    65:	mov bh, 0x70                                //  =  
    66:	push ax                                         //    
    67:	xchg ah, al                                    // ah =   mod 256 
    68:	aam                                              //  ASCII- 
    69:	or ax, 0x3030                              //   ascii 
    70:	mov bl, ah                                    //    bl 
    71:	mov [0x0096], bx                        //     
    72:	mov bl, al                                     //     
    73:	mov [0x0098], bx                        //     
    74:	pop ax                                         //    
    75:	mov ex, 0x0f06                          //   /4.26 
    76:	mul ch                                         //  <-   15 
    77:	shr ax, cl                                     //  <-  / 64 
    78:	m                                            //  ASCII- 
    79:	or , 0x3030                             //   ascii 
    80:	mov bl, ah                                  //    bl
    81:	mov [0009c], bx                      //     
    82:	mov bl, al                                   //    bl 
    83:	mov [0009c], bx                      //     
    84:	} 
    35:	}

            
   PC        
 .      , 
 : 

    void  interrupt (far *oldVector)(...); 

         oldVector    
  interrupt-,   void    , 
   C++   ,      . 
       oldVector 
  getvect(),      28.  
  setvect ( 29)       
.     setvect() ( 52)    
   . 
      33-47  ,      
   for.       ,    - 
,           
,  ,        
 .         
.  
    

     17.    	455 

       DoWhateverYouWantO,  
     . 
         ShowTime() ( 56-85)  
   asm    , 
 - (BCD)   ASCII    
   .     
  . 
       ,   ,  ShowTime(), 
        ,  
   IBM PC      
.         
 . 
       . ,   ,  
   . ,    ,  
  ,    ,  
   ,   ,    
  . 

     

            
,     ,     
         
     .    -S 
        .   
    ,  ,    
    . 

           
         
  .       
 (,   Turbo Profiler)     
   .       
 (   )     . 

      Borland (BASM)    
asm      C++.      
    .     
  . 

     BASM     TASM,  , , 
   80386  80486,     
  ASM.   , BASM   
 ,  . 

      BASM     C++.    
  ,  BASM      . 

            
,       ASM   
       C++.    
     TASM,   
  .        
   . 

      H2ASH     
,  #define,       
.     ,   . 

           
 .      ,  
      ()    . 

        .   
        
int. ,     DOS   int 
0x21.      BIOS    
,       ;  BIOS  
  ,      
   .      
      C++,    
      
 . 
    

    456 49	 IV.   
