home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH19 / RUNDOS.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-07-17  |  3.1 KB  |  129 lines

  1. ; RUNDOS.ASM -    Demonstrates how to invoke a copy of the COMMAND.COM
  2. ;               DOS command line interpreter from your programs.
  3.  
  4.         include    stdlib.a
  5.         includelib    stdlib.lib
  6.  
  7. dseg        segment    para public 'data'
  8.  
  9. ; Variables used by this program.
  10.  
  11.  
  12. ; MS-DOS EXEC structure.
  13.  
  14. ExecStruct    dw    0            ;Use parent's Environment blk.
  15.         dd    CmdLine            ;For the cmd ln parms.
  16.         dd    DfltFCB
  17.         dd    DfltFCB
  18.  
  19. DfltFCB        db    3,"           ",0,0,0,0,0
  20. CmdLine        db    0, 0dh            ;Cmd line for program.
  21. PgmName        dd    filename        ;Points at pgm name.
  22. filename    byte    "c:\command.com",0
  23.  
  24. dseg        ends
  25.  
  26. cseg        segment    para public 'code'
  27.         assume    cs:cseg, ds:dseg
  28.  
  29.  
  30. Main        proc
  31.         mov    ax, dseg        ;Get ptr to vars segment
  32.         mov    ds, ax
  33.  
  34.         MemInit                ;Start the memory mgr.
  35.  
  36.  
  37.  
  38.  
  39. ; Okay, we've built the MS-DOS execute structure and the necessary
  40. ; command line, now let's see about running the program.
  41. ; The first step is to free up all the memory that this program
  42. ; isn't using.  That would be everything from zzzzzzseg on.
  43. ;
  44. ; Note: unlike some previous examples in other chapters, it is okay
  45. ; to call Standard Library routines in this program after freeing
  46. ; up memory.  The difference here is that the Standard Library
  47. ; routines are loaded early in memory and we haven't free up the
  48. ; storage they are sitting in.
  49.  
  50.         mov    ah, 62h            ;Get our PSP value
  51.         int    21h
  52.         mov    es, bx
  53.         mov    ax, zzzzzzseg        ;Compute size of
  54.         sub    ax, bx            ; resident run code.
  55.         mov    bx, ax
  56.         mov    ah, 4ah            ;Release unused memory.
  57.         int    21h
  58.  
  59.  
  60. ; Tell the user what is going on:
  61.  
  62.         print
  63.         byte    cr,lf
  64.         byte    "RUNDOS- Executing a copy of command.com",cr,lf
  65.         byte    "Type 'EXIT' to return control to RUN.ASM",cr,lf
  66.         byte    0
  67.  
  68. ; Warning!  No Standard Library calls after this point.  We've just
  69. ; released the memory that they're sitting in.  So the program load
  70. ; we're about to do will wipe out the Standard Library code.
  71.  
  72.         mov    bx, seg ExecStruct
  73.         mov    es, bx
  74.         mov    bx, offset ExecStruct    ;Ptr to program record.
  75.         lds    dx, PgmName
  76.         mov    ax, 4b00h        ;Exec pgm
  77.         int    21h
  78.  
  79. ; In MS-DOS 6.0 the following code isn't required.  But in various older
  80. ; versions of MS-DOS, the stack is messed up at this point.  Just to be
  81. ; safe, let's reset the stack pointer to a decent place in memory.
  82. ;
  83. ; Note that this code preserves the carry flag and the value in the
  84. ; AX register so we can test for a DOS error condition when we are done
  85. ; fixing the stack.
  86.  
  87.         mov    bx, sseg
  88.         mov    ss, ax
  89.         mov    sp, offset EndStk
  90.         mov    bx, seg dseg
  91.         mov    ds, bx
  92.  
  93. ; Test for a DOS error:
  94.  
  95.         jnc    GoodCommand
  96.         print
  97.         byte    "DOS error #",0
  98.         puti
  99.         print
  100.         byte    " while attempting to run COMMAND.COM",cr,lf
  101.         byte    0
  102.         jmp    Quit
  103.  
  104.  
  105. ; Print a welcome back message.
  106.  
  107. GoodCommand:    print
  108.         byte    "Welcome back to RUNDOS.  Hope you had fun.",cr,lf
  109.         byte    "Now returning to MS-DOS' version of COMMAND.COM."
  110.         byte    cr,lf,lf,0
  111.  
  112. ; Return control to MS-DOS
  113.  
  114. Quit:        ExitPgm
  115. Main        endp
  116. cseg        ends
  117.  
  118. sseg        segment    para stack 'stack'
  119.         dw    128 dup (0)
  120. endstk        dw    ?
  121. sseg        ends
  122.  
  123. ; Set aside some room for the heap.
  124.  
  125. zzzzzzseg    segment    para public 'zzzzzzseg'
  126. Heap        db    200h dup (?)
  127. zzzzzzseg    ends
  128.         end    Main
  129.