home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / sampler1 / fxn.asm < prev    next >
Assembly Source File  |  1985-08-28  |  7KB  |  171 lines

  1.          name      FXN4BH
  2.          page      55,132
  3.          title     'FXN4BH --- demo PC-DOS EXEC function'
  4. ;
  5. ; FXN4BH --- demonstrate use of the
  6. ; PC-DOS 2.0 EXEC function call 4BH
  7. ;
  8. ; Copyright (c) 1983 by Ray Duncan
  9. ;
  10. cr       equ       0dh       ;ASCII carriage return
  11. lf       equ       0ah       ;ASCII line feed
  12.                              ;
  13. cseg     segment   para public 'CODE'
  14.                              ;
  15.          assume    cs:cseg,ds:data,ss:stack
  16.                              ;
  17. demo     proc      far
  18.                              ;at entry DS & ES = PSP
  19.          push      ds        ;Save address for final
  20.          xor       ax,ax     ;FAR RET to PC-DOS on stack
  21.          push      ax
  22.                              ;save copy of SS:SP for use
  23.                              ;after return from overlay
  24.          mov       cs:STK_SEG,ss
  25.          mov       cs:STK_PTR,sp
  26.                              ;
  27.                              ;Reserve 1000H bytes for
  28.                              ;this loader and release
  29.                              ;the rest of memory for
  30.                              ;use by the overlayed program.
  31.          mov       bx,100h   ;ES=segment of PSP of loader
  32.          mov       ah,4ah    ;BX=paragraphs to reserve
  33.          int       21h
  34.                              ;make the messages in data
  35.                              ;segment addressable
  36.          mov       ax,seg DATA
  37.          mov       ds,ax
  38.          mov       es,ax
  39.                              ;jump if memory
  40.                              ;de-allocation failed
  41.          jc        ALLOC_ERR
  42.                              ;print memory successfully
  43.                              ;released
  44.          mov       dx,offset MSG2
  45.          mov       ah,9
  46.          int       21h
  47.                              ;
  48.                              ;now load and execute
  49.                              ;the overlaid program.
  50.          mov       dx,offset PGM_NAME
  51.          mov       bx,offset PAR_BLK
  52.          mov       al,0
  53.          mov       ah,4bh
  54.          int       21h
  55.                              ;restore stack pointers
  56.                              ;to state before EXEC call
  57.          mov       ss,cs:STK_SEG
  58.          mov       sp,cs:STK_PTR
  59.                              ;Make data segment
  60.                              ;addressable again
  61.          mov       ax,seg DATA
  62.          mov       ds,ax
  63.                              ;print message that loader
  64.                              ;successfully regained control
  65.          mov       dx,offset MSG3
  66.          mov       ah,9
  67.          int       21h
  68.                              ;now exit to PC-DOS
  69.          ret
  70.  
  71. alloc_err:                   ;come here if memory
  72.                              ;cannot be released
  73.          mov       dx,offset MSG1
  74.          mov       ah,9
  75.          int       21h       ;print error message and
  76.          ret                 ;exit to PC-DOS
  77.                              ;
  78. demo     endp
  79.                              ;
  80.                              ;these two variables must
  81.                              ;reside in Code Segment so
  82.                              ;that they are addressable
  83.                              ;after return from overlay.
  84. stk_seg  dw        0         ;original SS contents
  85. stk_ptr  dw        0         ;original SP contents
  86.                              ;
  87. cseg     ends
  88.  
  89.                              ;declare a stack area
  90.                              ;for use by this loader
  91. stack    segment   para stack 'STACK'
  92.                              ;allow 64 bytes in this case
  93.          db        64 dup (?)
  94. stack    ends
  95.  
  96.                              ;declare data segment to
  97.                              ;contain variables and tables
  98. data     segment   para public 'DATA'
  99. ;
  100. msg1     db        cr,lf
  101.          db        'Unable to release memory.'
  102.          db        cr,lf,'$'
  103. msg2     db        cr,lf
  104.          db        'Memory above loader released.'
  105.          db        cr,lf,'Now loading CHKDSK.COM.'
  106.          db        cr,lf,'$'
  107. msg3     db        cr,lf
  108.          db        'Loader regained control from CHKDSK,'
  109.          db        cr,lf
  110.          db        'now making final exit to PC-DOS.'
  111.          db        cr,lf,'$'
  112. ;
  113.                              ;drive, path, and name of program
  114.                              ;to be loaded and executed.
  115. pgm_name db        '\CHKDSK.COM',0
  116. ;
  117. par_blk  dw        ENVIR     ;segment address of
  118.                              ;environment descriptor
  119.                              ;
  120.                              ;full address of command line
  121.                              ;to be passed at offset 80H
  122.          dw        offset CMD_LINE     ;in overlaid
  123.          dw        seg CMD_LINE        ;program's PSP
  124.                              ;
  125.                              ;full address of default
  126.                              ;File Control Block to be
  127.                              ;passed at offset 5CH in
  128.          dw        offset FCB1         ;overlaid
  129.          dw        seg FCB1            ;program's PSP
  130.                              ;
  131.                              ;full address of default
  132.                              ;File Control Block to be
  133.                              ;passed at offset 6CH in
  134.          dw        offset FCB2         ;overlaid
  135.          dw        seg FCB2            ;program's PSP
  136. ;
  137.                              ;actual command line tail
  138.                              ;to be passed to overlay
  139. cmd_line db        4,' *.*',cr,0
  140. ;
  141.                              ;first default FCB to
  142. fcb1     db        0         ;be passed to overlay
  143.          db        11 dup ('?')
  144.          db        25 dup (0)
  145.  
  146.                              ;second default FCB to
  147. fcb2     db        0         ;be passed to overlay
  148.          db        11 dup (' ')
  149.          db        25 dup (0)
  150. ;
  151. data     ends
  152.  
  153.                              ;declare separate data
  154.                              ;segment to contain
  155.                              ;environment descriptor
  156. envir    segment   para 'ENVIR'
  157.                              ;
  158.                              ;Search path used by PC-DOS
  159.                              ;to look for commands or
  160.                              ;batch files not found in
  161.          db        'PATH=',0 ;the current directory
  162.                              ;
  163.                              ;Search path used by PC-DOS
  164.                              ;to locate COMMAND.COM
  165.          db        'COMSPEC=A:\COMMAND.COM',0
  166.          db        0         ;extra 0 byte designates
  167.                              ;end of environment
  168. envir    ends
  169.  
  170.          end       demo
  171.