KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q44923: MASM Calling C Making MASM Main Routine

Article: Q44923
Product(s): See article
Version(s): 5.10
Operating System(s): MS-DOS
Keyword(s): ENDUSER | | mspl13_masm
Last Modified: 30-AUG-1989

You can make a program that starts with MASM and calls C. This method
of programming is not recommended because starting with MASM will
mean that the C start-up code will not be executed, which may cause
future problems calling some of the C library functions. Run-time
error messages may be affected as well as routines that use system
symbols.

The following is an example of the macro-assembler main routine
which calls a C routine.

        .MODEL LARGE,C
        .CODE
        EXTRN CSUB
MAIN    PROC           ; Must call main (_main without ,C)
        PUSH     AX             ; Push argument on stack
        PUSH     BX             ; Push another argument
        CALL     CSUB   ; Call C subroutine
        ADD   SP,4      ; Fix-up stack after C subroutine
MAIN ENDP
        END            ; Do not specify starting location

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.