[net.micro.pc] Apparent MSDOS loader anomaly

donk@dshovax.UUCP (don kinzer x2192) (01/29/85)

 A while back I posted an article relating a problem I had noticed
 with the DOS loader where some bytes of a program were being bashed
 before execution even began.  This was observed under both DOS V2.10
 and V3.0.  I've discovered the cause of the problem and the solution.

Background
 The load module that I was building was a .EXE file.  For reasons
 that aren't germane to this discussion, a stack segment was not
 declared.  Naturally, the linker complained about the lack of the
 stack segment but, being that we often did this without any problems
 (although usually only when eventually generating .COM files), we
 ignored said warning.  The load module indicates that no stack
 segment was declared by the existence of two zero words in the
 formatted portion of the .EXE header, specifically at byte offsets
 0x0e and 0x10, corresponding to the initial values of the stack
 segment (relative to beginning of the load image) and the stack
 pointer respectively.

The Problem
 It seems that whenever the loader loads a .EXE file that has no
 stack declared it always, without regard to the size of the load
 image, writes a zero byte at offsets 0xfffe and 0xffff with respect
 to the start of the load image.  This is only a problem when a) the
 load image is greater than 65534 bytes and b) your application cares
 what is at offset 0xfffe-f.

The Solution
 If your load image (code + data) is greater than 65534 bytes, your 
 application must, to be safe, declare a stack segment.  This will
 cause one or both of the words at offsets 0x0e and 0x10 of the 
 formatted portion of the .EXE header to be non-zero thus preventing
 the undesirable side effect.

 Don Kinzer

       ... ihnp4!hplabs!intelca!omovax!dshovax!donk