[net.micro.pc] A peculiar MASM problem

cjdb@sphinx.UChicago.UUCP (Charles Blair) (09/25/86)

I can't think of a better place to request help on the following
problem, so here goes.

I have been working on an 8086 assembler problem that has seven source
files. I installed push/pop in it and have been using it for a while
without problems. For greater ease of maintenance, I broke one module
into two.  Since then, push only works the first time it is invoked,
not the second and subsequent times; I've determined that the push proc
is being called, but it seems to return to the caller without executing
any of the code. From then on the program seems to work fine: it
doesn't hang. However, if executing the program from SYMDEB, I have no
problems pushing to the exec as many times as I want (so the debugger
per se is useless in helping me to localize the problem). Also, if I
run the program as a child of itself (i.e., push out of it the first
time, then reload it), I also have no problems pushing out at will. But
when I exit to DOS and then exit back to the parent, again I can't
push, since I've already pushed once. One final observation: if I
eliminate one of the source files in the link step (and I've tried
it with three files in turn, with the same result), push/pop again
works fine, every time.

I've looked at the obvious, like not terminating data segments
properly, not deallocating too much memory before pushing, and so on.

Clearly, I can't expect any reader of this to help me on the basis of
the short description of the problem I have given, unless such a reader
has encountered a similar problem. I'd be interested in hearing from
any such reader, since I can't formulate a proper hypothesis as to the
cause of the problem given the program behavior clues as indicated
above. Thanks in advance.


-- 
Charles Blair   			    ..!ihnp4!gargoyle!sphinx!cjdb
The University of Chicago		    lib.cb%chip@UChicago.Bitnet

cjdb@sphinx.UChicago.UUCP (Charles Blair) (09/26/86)

Well, I've solved my own problem, and I post the solution in case
anyone else runs into the problem described in the original posting,
and in case some knowledgeable person can offer some further
clarificatory words.

Both Norton (Programmer's Guide) and Ray Duncan in the new *Advanced
MSDOS* (Microsoft Press, 1986) point out that the SS and SP registers
need to be saved into variables within the code segment before
executing the EXEC function call, and need to be restored from those
variables right after control is returned to the program. I had been
doing this right before pushing all the other registers onto the stack
in preparation for making the call itself. This worked, except under
the conditions described in the previous posting. I have since moved
the definition of these variables to right after the beginning of the
code segment in the same module, i.e., out of the proc that made the
EXEC call. This seems to work fine. I decided that this might be the
problem after determining that when push failed, it failed right after
stepping through the two defines, one for SP and one for SS. Right
after those two lines were "executed," the code seemed to return to the
caller: the rest of the proc never got executed. I'd appreciate hearing
form anyone with a firmer grasp of what really went wrong here, i.e.,
what the real pitfalls are in making this call, and I apologize to the
non-MASMers who might be reading this. Thanks in advance.



-- 
Charles Blair   			    ..!ihnp4!gargoyle!sphinx!cjdb
The University of Chicago		    lib.cb%chip@UChicago.Bitnet