KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q72698: Using Full Segment Directives with MASM 6.0 HELLO.ASM

Article: Q72698
Product(s): Microsoft Macro Assembler
Version(s): 6.0,6.0a,6.0b
Operating System(s): 
Keyword(s): 
Last Modified: 06-MAY-2001

-------------------------------------------------------------------------------
The information in this article applies to:

- Microsoft Macro Assembler (MASM), versions 6.0, 6.0a, 6.0b 
-------------------------------------------------------------------------------

SUMMARY
=======

The "Microsoft Macro Assembler Programmer's Guide" for MASM version 6.0 has a
HELLO.ASM example for OS/2 on page 458, section 17.3, and has the same example
using INVOKE on page 459. Both examples use simplified dot directives. The code
sample below shows how the examples may be assembled using full segment
directives.

MORE INFORMATION
================

The code that the assembler generates with the INVOKE directive is placed in
comment lines below each INVOKE.

With INVOKE, the assembler generates code depending on the prototypes for the
DosWrite and DosExit functions declared in the include file BSEDOS.INC. Both the
prototypes indicate the PASCAL calling convention. In BSEDOS.INC, DosWrite is
prototyped as:

     DosWrite PROTO FAR PASCAL \ 
              hf:Hfile, bBuf:PVOID, cbBuf:WORD, pcbBytesWritten:PWORD

DosExit is prototyped in BSEDOS.INC as:

     DosExit PROTO FAR PASCAL fTerminate:BOOL, usExitCode:WORD

In OS2DEF.INC, PVOID is typedefined as:

     PVOID TYPEDEF FAR PTR

PWORD is typedefined as:

     PWORD TYPEDEF FAR PTR WORD

BOOL is typedefined as:

     BOOL TYPEDEF WORD

The code generated for INVOKE accomplishes the following:

1. Pushes the arguments for the function DosWrite on the stack (from right to
  left).

2. Pushes the arguments for the DosExit function on the stack (from right to
  left).

3. Exits.

Sample Code
-----------

  ; Assemble options needed: none

         .286

         INCLUDELIB os2.lib
         INCLUDE os2.inc

  DGROUP GROUP _DATA

  STACK  SEGMENT PARA STACK 'STACK'     ;stack segment declared
         WORD   256 dup(?)
  STACK  ENDS

  _DATA      SEGMENT WORD PUBLIC 'DATA'     ;data segment declared
  message    BYTE  "Hello World", 13,10
  bytecount  DWORD ?
  _DATA      ENDS

  _TEXT  SEGMENT WORD PUBLIC 'CODE'     ;code segment declared
         ASSUME   CS:_TEXT, DS:_DATA, SS:STACK

  @Startup:

         INVOKE DosWrite, 1, ADDR message, LENGTHOF message
                             ADDR bytecount

         ;Code generated by INVOKE
         ;------------------------
         ;   push   1                   ;output to Stdout
         ;   push   ds                  ;pass address of msg
         ;   push   OFFSET message
         ;   push   LENGTHOF message    ;pass length of msg
         ;   push   ds
         ;   push   OFFSET bytecount    ;pass address of count
         ;   call   DosWrite

         INVOKE   DosExit,+1h, +0h

         ;Code generated by INVOKE
         ;------------------------
         ;   push   +1h                 ;Ends all threads
         ;   push   +0h                 ;Pass 0 return code
         ;   call   DosExit

  _TEXT  ENDS
         END @Startup

Additional query words: kbinf 6.00 6.00a 6.00b

======================================================================
Keywords          :  
Technology        : kbMASMsearch kbAudDeveloper kbMASM600 kbMASM600a kbMASM600b
Version           : :6.0,6.0a,6.0b

=============================================================================

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.