home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30A / TIMER.ASM < prev    next >
Assembly Source File  |  1994-12-18  |  3KB  |  135 lines

  1. ;**************************** TIMER.ASM *********************************
  2. PAGE  70,132
  3. comment 
  4.                              TIMER
  5.                              -----
  6.  
  7.      Purpose:
  8.      --------
  9.  
  10.      TIMER is a sample program to show how the timer funcitons can
  11.      be used.  The unmodified program will time the execution of
  12.      programs, but it can be modified to time code segments.
  13.  
  14.      Using TIMER
  15.      ----------
  16.  
  17.      To time a program, type "TIMER <program name>"<Enter>
  18.      TIMER will execute the program and display the elapsed
  19.      time when the program exits.
  20.  
  21.      Compiling
  22.      ---------
  23.  
  24.      The commands needed to build TIMER.EXE using MASM are:
  25.         masm TIMER;
  26.         link TIMER,TIMER,,alib.lib;
  27. 
  28.  
  29. ;----------------------------------------------------------------------------
  30. .xlist
  31.     include  mac.inc
  32.     include  common.inc
  33.     extrn    library_setup:far
  34.     extrn    library_terminate:far    
  35.     extrn    spawn_dos:far    
  36.     extrn    calibrate_timer:far
  37.     extrn    start_timer:far
  38.     extrn    read_timer:far
  39.     extrn    convert_timer:far
  40.     extrn    display_timer:far
  41. .list
  42.     
  43. ;------------------------------------------------------------------------------
  44. code        segment para public 'CODE'
  45.         assume    cs:code, ds:code
  46. ;-----------------------------------------------------------------------------
  47.  
  48. stacksize    equ    1024
  49.     db    stacksize dup (0)
  50. stack_    label    word
  51. ;
  52. pspseg        dw    0        ;program segment prefix
  53. ;-----------------------------------------------------------------------------
  54. start:    cli
  55.     mov    cs:pspseg,es    ;save PSP segment
  56.     mov    ax,cs        ;get CODE segment
  57.     mov    ss,ax
  58.     mov    ds,ax
  59.     mov    es,ax
  60.     mov    sp,offset stack_
  61.     sti
  62.     
  63. ; next, release memory beyond the end of the program
  64. ; The  definition for ZSEG marks the
  65. ; end of the program's code, data and stack area.
  66. ; When linking be sure ZSEG is at the end of the program.
  67.  
  68.     mov    ax,zseg
  69.  
  70.     mov    bx,cs:pspseg        ;
  71.     mov    es,bx
  72.     sub    bx,ax
  73.     neg    bx            ; size of program in paragraphs
  74.     mov    ah,4Ah            ; resize memory block
  75.     int    21h
  76.  
  77.     mov    ax,cs
  78.     mov    es,ax
  79. ;
  80. ; check if enough memory free to run program
  81. ;
  82.     mov    ax,pspseg        ;pass psp segment to setup
  83.     mov    bx,0            ;number of floating point variables
  84.     call    library_setup
  85. ;
  86. ; We want to call SPAWN_DOS which is not compatable with the memory
  87. ; manager, so we will remove it from memory.  We needed to call
  88. ; library setup origionally, to setup the library data area.
  89. ;
  90.     mov    ax,1
  91.     call    library_terminate
  92.  
  93.     call    calibrate_timer
  94.     call    start_timer
  95. ;
  96. ; note: for code timing it will be necessary to comment out the "jcxz"
  97. ;       instruction above, then place code below.
  98. ;
  99. ; **** place code to be timed here ****    
  100.  
  101.     mov    ax,cs:pspseg
  102.     mov    ds,ax
  103.     mov    es,ax
  104.     mov    si,81h
  105.     call    spawn_dos        ;execute program to be timed
  106.  
  107. ; **** end of code to be timed ****
  108.  
  109.     call    read_timer
  110.     call    convert_timer
  111.     call    display_timer        
  112.  
  113. exit2:    mov    ax,4C00h
  114.     int    21h
  115. ;---------------------------
  116.             
  117. code        ends
  118.     
  119. ;-------------------------------------------------------------------------
  120. ;
  121. ; This segment definition is needed so linker will put the LIBSEG here
  122. ; before the ZSEG.  We want ZSEG to be last so memory allocation will
  123. ; work correctly.
  124. ;
  125. LIBSEG           segment byte public 'LIB'
  126. LIBSEG    ENDS
  127. ;-------------------------------------------------------------------------
  128. ; zseg must be at the end of the program for memory allocation from
  129. ; DOS.
  130. ;
  131. zseg    segment    para public 'ZZ'
  132. zseg    ends
  133.         end    start
  134.