bright@dataioDataio.UUCP (Walter Bright) (03/19/86)
I have recently spent much time tracking down an obscure problem with .EXE files, and am posting this so others may avoid it. The problem is that the code would work fine if there was more than 64k of free memory available past the end of the program, but would lock up the PC if there was less. I eventually traced the cause to the values of SP and SS as set by the .EXE file. It seems that there must be some allocated stack in the .EXE file, even if the first instruction executed is a CLI (turn off interrupts). Since in my program I set up my own stack, I had a stack segment with 1 byte in it (to get rid of the silly warning from LINK). MS-DOS fired up the program with SS pointing to the segment, and SP having a value of 2 in it. The crash is apparently caused by a segment wrap occurring. Note that you can't use DEBUG to single step a program with this problem. This problem exists in MS-DOS 3.0 and 3.1, and probably in the others too. This requirement is not documented. Also, methinks the linker should give a warning about this.