Finding Size of Program

Last reviewed: February 21, 1995
Article ID: Q11833
The information in this article applies to:
  • Microsoft Macro Assembler for MS-DOS, versions 1.25, 1.27, 3.0x, 4.0, 5.0, 5.1, and 6.0
  • Microsoft Macro Assembler for OS/2, versions 5.1 and 6.0

The are programming situations in which it is necessary to determine the length of a program at run-time. For example, services (such as MS-DOS function 31H) need this information. Ordinarily, one could define a symbol at the end of a segment known to be loaded last; however, this does not work when linking with libraries because the libraries load after the .OBJ's.

The following is a method that be used to perform the equivolent operation when linking with library files that may rearange the segment order:

Begin your program with a list of declarations for all segments in your program. This will solve the load-order problem. However, if your segments are all named to classes and the order of the classes is all that is important, you only need one segment declaration per class.

Define a new and empty segment to be the last segment in your load image. Place your empty segment at the end of the list. The following is an example:

   ; Declarations to fix the load order. First, MYCODE
   ; and all segments of class CODE.

   MYCODE SEGMENT 'CODE'
   MYCODE ENDS

   ; Next MYDATA and all segments of class DATA

   MYDATA SEGMENT PUBLIC 'DATA'
   MYDATA ENDS

   ; Finally, LASTSEG.

   LASTSEG SEGMENT
   LASTSEG ENDS

In the above, LASTSEG is the last segment in the load order (assuming all other segments in the program belong to either class CODE or DATA) and thus marks the beginning of free memory above the load image.

If your segment declarations occur randomly throughout your source files and libraries, the solution is not as simple. The method to use is to make a new library, to be linked in last, that defines this last empty segment and a label in this segment. (You must have a reference to this label in some part of the program so the linker will pull in this library.)


Additional reference words: 1.25 1.27 3.0x 4.00 5.00 5.10 6.00
KBCategory: kbprg
KBSubCategory: MASMLngIss


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.