home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30A / TEMPLATE.ASM < prev    next >
Assembly Source File  |  1994-11-15  |  4KB  |  141 lines

  1. ;**************************** TEMPLATE.ASM **********************************
  2. PAGE  66,132
  3. comment 
  4.                              TEMPLATE.ASM
  5.                              ------------
  6.  
  7.      Purpose:
  8.      --------
  9.  
  10.      TEMPLATE.ASM is a skeleton assembly language program which
  11.      can be used as the basis to start a new program.
  12.  
  13.      Using TEMPLATE.ASM
  14.      ------------------
  15.  
  16.      The setup in TEMPLATE should work for most programs without using
  17.      alot of memory.  If no floating point variables are used then
  18.      some memory can be saved by modifying the call to library_open
  19.      to specify zero floating variables.  Next, add code to the
  20.      area of TEMPLATE.ASM which indicates the main body of the program
  21.      goes here.
  22.      
  23.      TEMPLATE.ASM was tested with MASM and OPTASM, but any assembler
  24.      should work.  
  25.  
  26.      Compiling
  27.      ---------
  28.  
  29.      The following commands can be used to compile TEMPLATE and
  30.      create TEMPLATE.EXE:
  31.         masm TEMPLATE;
  32.         link TEMPLATE,TEMPLATE,,alib.lib;
  33.  
  34. 
  35.  
  36.      
  37.  
  38. ; Sample template for creating programs using ALIB.LIB
  39. ;
  40.     include    mac.inc
  41.     include    common.inc
  42. ;-----------------------------------------------------------------------------
  43.     extrn    library_setup:far
  44.     extrn    library_terminate:far    
  45. ;------------------------------------------------------------------------------
  46. code        segment para public 'CODE'
  47.         assume    cs:code, ds:code
  48. ;-----------------------------------------------------------------------------
  49. ;
  50. pspseg        dw    0            ;Program Segment Prefix
  51.         dw    200 dup (0)        ;stack
  52. stack_        dw    0
  53. ;-----------------------------------------------------------------------------
  54. start:
  55.     cli
  56.     mov    cs:pspseg,es    ;save PSP segment
  57.     mov    ax,cs        ;get CODE segment
  58.     mov    ss,ax
  59.     mov    ds,ax
  60.     mov    es,ax
  61.     mov    sp,offset stack_
  62.     sti
  63.     
  64. ; next, release memory beyond the end of the program
  65. ; The  definition for ZSEG marks the
  66. ; end of the program's code, data and stack area.
  67. ; When linking be sure ZSEG is at the end of the program.
  68.  
  69.     mov    ax,zseg
  70.  
  71.     mov    bx,cs:pspseg        ;
  72.     mov    es,bx
  73.     sub    bx,ax
  74.     neg    bx            ; size of program in paragraphs
  75.     mov    ah,4Ah            ; resize memory block
  76.     int    21h
  77.  
  78.     mov    ax,cs
  79.     mov    es,ax
  80. ;
  81. ; check if enough memory free to run program
  82. ;
  83.     mov    ax,pspseg        ;pass psp segment to setup
  84.     mov    bx,8            ;number of floating point variables
  85.     call    library_setup
  86.     cmp    ax,128            ;check if 128k of memory is available
  87.     jae    got_enough_mem        ;jmp if 128k of memory avail
  88. ;
  89. ; If you want to have a small program, replace the following error_handler
  90. ; call with your own error display.  The error_handler is a real memory
  91. ; hog.
  92. ;
  93. ;    mov    al,7
  94. ;    mov    ah,fatal_return
  95. ;    call    lib_error_handler
  96. ;    jmp    exit2
  97.     
  98. got_enough_mem:
  99.     
  100. ; prevent an unintended program crash; trap Ctrl+Break, Ctrl+C and
  101. ; Ctrl+Alt+Del key combinations
  102.  
  103. ;    call    BREAK_KEY_INTERCEPT    ;optional
  104.  
  105.  
  106. ;  add main body of program here ............
  107.  
  108.  
  109.     
  110.  
  111. ; normal program exit
  112. ;
  113. exit1:    
  114. ;
  115. ; de-activate the Ctrl+Break trap
  116. ;    call    BREAK_KEY_RESTORE    ;needed only if BREAK_KEY_INTERCEPT called
  117.  
  118. exit2:    mov    ax,0
  119.     call    library_terminate
  120.     mov    ax,4C00h
  121.     int    21h
  122. ;------------------------
  123. code        ends
  124. ;-------------------------------------------------------------------------
  125. ;
  126. ; This segment definition is needed so linker will put the LIBSEG here
  127. ; before the ZSEG.  We want ZSEG to be last so memory allocation will
  128. ; work correctly.
  129. ;
  130. LIBSEG           segment byte public 'LIB'
  131. LIBSEG    ENDS
  132. ;-------------------------------------------------------------------------
  133. ; zseg must be at the end of the program for memory allocation from
  134. ; DOS.
  135. ;
  136. zseg    segment    para public 'ZZ'
  137.  
  138. zseg    ends
  139.  
  140.         end    start
  141.