🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.ibm.pc.programmer
Article #259

Re: Dos function 4Bh without using spawn() in C

#259
From: Fred Smith
Date: Sun, 08 Apr 1990 18:00
32 lines
1957 bytes
In article <1990Apr8.073952.5936@calvin.spp.cornell.edu> richard@calvin.spp.cornell.edu.UUCP (Richard Brittain) writes:
>Hi,
>   I'm wondering if anyone has tried to "roll their own" spawn() with
>TC. 
>So, does anyone have any experience of "gotchas" using this function, which
>that the command line has to begin with a space or DOS is very unhappy, and

>Richard Brittain,                   School of Elect. Eng.,  Upson Hall   
>                                    Cornell University, Ithaca, NY 14853




Well, on some versions of DOS function 4B is not very polite, and when it
returns from the child, it leaves ALL the registers except CS/IP in a
condition known in the trade as "trashed". This means that you cannot
reliably call DOS function 4B from within a piece of C code. Rather you
need to have a short assembler interlude which contains enough space in
the CODE segment for you to save the CS/IP immediately before the INT 21h,
and the very next thing you need to do is restore the stack. I am assuming,
of course, that you previously saved everything you care about (like the
registers, for example) on the stack, so that you can pop them off once
you have restored the SP after returning from the DOS call.

I once wrote a system() in assembler for use with Small-C, and discovered
all this the hard way. Later someone pointed me to the discussion in
Ray Duncan's Advanced MS-DOS, which explains it all nicely, along with
an example, even.

have fun!

Fred
Technical Details
Message-ID: <8569@cg-atla.agfa.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!cg-atla!fredex
References: <1990Apr8.073952.5936@calvin.spp.cornell.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!cg-atla!fredex
From: fredex@cg-atla.agfa.com (Fred Smith)
Newsgroups: comp.sys.ibm.pc.programmer
Subject: Re: Dos function 4Bh without using spawn() in C
Message-ID: <8569@cg-atla.agfa.com>
Date: 8 Apr 90 18:00:44 GMT
References: <1990Apr8.073952.5936@calvin.spp.cornell.edu>
Reply-To: fredex@cg-atla.UUCP (Fred Smith)
Organization: Agfa Compugraphic Division
Lines: 32