Using Full Segment Directives with MASM 6.0 HELLO.ASM

ID: Q72698


The information in this article applies to:
  • Microsoft Macro Assembler for OS/2, 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 :
Version : :6.0,6.0a,6.0b
Platform :
Issue type :


Last Reviewed: January 13, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.