[net.micro.pc] Question about DOS function 21

starr@shell.UUCP (Bob Starr) (12/20/83)

Is  there  something  which  prevents  DOS function 21 from being
called recursively?

For example, let's say function 21 calls function  A.  I  replace
function  A with my own routine. Within function A, I need to use
a facility in function 21, so I invoke it via  an  interrupt  21.
After  invoking function 21 from within function A, I am returned
to function A (as I should be). Function A cannot seem to perform
a proper return  back  to  function  21,  though  (where  it  was
originally called from).

Perhaps  I  am	doing  something  wrong,  as this problem is more
complicated than presented above (i.e. when interrupt 21  invokes
(my)  function A, and function A invokes int 21, int 21 reinvokes
function A... but I think I am protected against internal  (func-
tion A, specifically) recursion problems).

Can  anyone  help?  I  have been struggling with this for several
days. My routine A works peachy until I invoke int 21.


P.S.	  I am using DOS 2.0, but want this to work  under  lower
	  versions too. Please respond via mail.



Thanks,
RF Starr

brownc@utah-cs.UUCP (Eric C. Brown) (12/21/83)

No, you can't recursively invoke DOS interrupt 21 because it keeps its
own stack, and it stores the caller's stack in a fixed memory location.

Therefore, if you call DOS interrupt 21 recursively, the previous caller's
stack is lost, and when DOS tries to return to the previous caller, the
stack is fried.

There is a way to 'solve' (i.e., hack around) this problem:  Have your routine
that wants to recursively call DOS intercept the interrupt 21 vector and
save the stack segment and stack pointer, and then just before it wants to
call DOS, preserve the old stack segment/pointer.   After it has finished 
calling DOS, restore the old stack segment/pointer by calling DOS with the
old stack segment/pointer.  This uses up some more stack space, but most 
programs have plenty of stack space.

If you want examples, send me some MAIL and I will send you an example of
what I mean.

		Eric C. Brown

		...!harpo!utah-cs!brownc