home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / UE311C.ZIP / EXECPR.ASM < prev    next >
Assembly Source File  |  1990-08-16  |  2KB  |  108 lines

  1. ;    EXECPR: execute a program directly using dos exec call.
  2. ;    
  3. ;    calling sequence = execpr(prog, pblock);
  4. ;        char *prog = 
  5. ;            where progname is the full file spec with extension
  6. ;        char *pblock =
  7. ;            ptr to the parameter block for the exec call
  8. ;    RETURNS:
  9. ;            -n    DOS error number
  10. ;             0    successfull call
  11. ;            +n    child return code
  12. ;
  13. ;    THIS IS A FAR CALL/LARGE DATA VERSION
  14.  
  15. args    equ 6    ; offset of arguments -- large model
  16.  
  17. _TEXT    segment    byte public 'CODE'
  18. ;DGROUP    group    _CODE
  19.     assume    cs:_TEXT
  20.  
  21. ;    declare procedure names
  22.  
  23.     public    _execpr
  24.  
  25. _execpr    proc    far
  26.  
  27. ;  do C setup
  28.  
  29.     push    bp
  30.     mov    bp,sp
  31.     push    ds
  32.  
  33. ;    set up the pointer to the asciiz string with program/path names
  34.  
  35.     mov ax, [bp+args+2]
  36.     mov ds, ax
  37.     mov dx, [bp+args+0]
  38.  
  39. ;    set up the pointer to the parameter block
  40.  
  41.     mov ax, [bp+args+6]
  42.     mov es, ax
  43.     mov bx, [bp+args+4]
  44.  
  45. ;    set the function number
  46.  
  47.     mov ah, 4bh        ;execute a program [DOS 4Bh call]
  48.  
  49. ;    set up the function value
  50.  
  51.     mov al, 0        ;load and execute program
  52.  
  53. ; save all registers in our stack area
  54.     push bx
  55.     push cx
  56.     push dx
  57.     push si
  58.     push di
  59.     push ds
  60.     push es
  61.     push bp
  62.  
  63.     mov cs:ss_save,ss        ; save ss
  64.     mov cs:sp_save,sp        ; save sp
  65.     int 21h                ; go exec program
  66.     mov ss, cs:ss_save        ; restore the stack seg/pointer
  67.     mov sp, cs:sp_save
  68.     jc failed            ; jump if dos error occurs
  69.  
  70. ; exec successful - get child's return code
  71.  
  72.     mov ah, 4dh            ; Get return code of a Subprocess
  73.     int 21h
  74.     jmp return            ; return code is now in AX
  75.  
  76. ;    exec failed. Negate and pass through the AX return code
  77.  
  78. failed:
  79.     neg ax
  80.  
  81. ; now reset all registers and return
  82.  
  83. return:
  84.  
  85. ; restore all registers from our stack
  86.     pop bp
  87.     pop es
  88.     pop ds
  89.     pop di
  90.     pop si
  91.     pop dx
  92.     pop cx
  93.     pop bx
  94.  
  95.     pop ds
  96.     pop bp                ; restore for C
  97.     ret
  98.  
  99. _execpr    endp
  100.  
  101. ;
  102. ; data area for exec prog
  103. ss_save        dw    ?
  104. sp_save        dw    ?
  105.  
  106. _TEXT    ends
  107.     end
  108.