KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q39519: Using Conditional-Assembly to Assemble for COM or EXE File

Article: Q39519
Product(s): See article
Version(s): 4.00 5.00 5.10
Operating System(s): MS-DOS
Keyword(s): ENDUSER | | mspl13_masm
Last Modified: 12-JAN-1989

By using assembler symbols, macros, and conditional-assembly,
assembling a file to a COM or EXE file is easy. The following is the
solution:

ifdef   COM
ending  macro   text
        end     start
endm
else
ending  macro   text
        end
endm
endif

_text   segment 'code'
        assume cs:_text
start:  mov     ax, 08000h
        mov     ds, ax
        ...
_text   ends

        ending

Use MASM /DCOM /MX foo.asm for assembling into a COM file. Or use
MASM /MX foo.asm for EXE files.

This example assembles code depending on whether the assembler symbol
COM is defined or not. COM files must have an entry point so the END
directive requires a start address; whereas, EXE files do not require
an entry point.

Under MASM Version 4.00, you can accomplish this with a simple
conditional-assembly block at the end as follows:

ifdef   com
        end     start
endif
        end

MASM Version 5.10 flags this as an error, which it should according to
Page 79 of the "Microsoft Macro Assembler 5.1 Programmer's Guide."
"Any statements following the END directive are ignored by the
assembler." The error occurs because the endif is not being recognized
and "Number of open conditionals: 1" error is displayed.

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.

Copyright Microsoft Corporation 1986-2002.