home *** CD-ROM | disk | FTP | other *** search
- Converting Mixed-Language Source Files
-
- This directory contains mixed-language example programs and macros.
-
- The following source files are the sample programs from Chapter 6,
- "Assembly-to-High-Level Interface," of the Mixed-Language Programming
- Guide:
-
- BA.ASM Assembly module to be called from BASIC
- CA.ASM Assembly module to be called from C
- FA.ASM Assembly module to be called from FORTRAN
- PA.ASM Assembly module to be called from Pascal
- BAMAIN.BAS BASIC main program that calls assembly module
- CAMAIN.C C main program that calls assembly module
- FAMAIN.FOR FORTRAN main program that calls assembly module
- PAMAIN.PAS Pascal main program that calls assembly module
-
- In addition, the following files are provided:
-
- POWER2.ASM Macro version of assembly module that can be called
- from BASIC, C, FORTRAN, or Pascal.
- MIXED.INC Mixed language macros.
- MIXED.DOC This file.
-
- The version of MIXED.INC provided with MASM 5.1 is smaller than the
- MASM 5.0 version because most of the functionality has now been built
- into MASM and the macros are no longer needed. The following macros
- are still supported in MIXED.INC:
-
- Macro Purpose
-
- ifFP Assembles statement if the memory model uses far data
-
- FP Provides ES override if the memory model uses far data
-
- pLes Loads data (through ES for far data)
-
- pLds Loads data (through DS for far data)
-
- To use these macros with MASM 5.1, you should include MIXED.INC after
- using .MODEL. The macro syntax is shown below:
-
- ifFP statement
-
- Assembles the statement if the memory model uses far data. This
- macro can be used to push segment registers or take other
- action that is only required for far data. For example,
-
- ifFP push ds
-
- pushes the DS register in compact, large, and huge memory
- models, but has no effect in small and medium models.
-
- FPoperand
-
- Gives an ES override if the memory model uses far data. In
- models that use near data, FP is null. For example,
-
- mov ax,FP[bx]
-
- assembles as
-
- mov ax,es:[bx]
-
- in compact, large, and huge memory models, but as
-
- mov ax,[bx]
-
- in small and medium models.
-
- pLes register,address
- pLds register,address
-
- Loads a pointer from the specified address to the specified
- register. If the memory model uses far data, the segment
- portion of the address will be moved into ES or DS, depending
- on the macro used. For example,
-
- pLes bx,arg1
-
- is assembled as
-
- les bx,arg1
-
- in compact, large, and huge memory models, but as
-
- mov bx,arg1
-
- in small and medium models.
-
- The other macros in the MASM 5.0 version of MIXED.INC are provided for
- compatibility with MASM 5.0, but are not documented. The rest of this
- file discusses compatibility options for source code that uses 5.0
- high-level-language macros. If you did not own MASM 5.0, you should
- ignore the rest of this file. Do not use the other macros in
- MIXED.INC.
-
- You can use the following macros if you have source code that uses the
- macros provided with MASM 5.0.
-
- Macro Purpose
-
- setModel Sets memory model passed from a DOS command line.
- No longer needed because the expression operator
- now enables you to evaluate text macros passed
- from the command line directly.
-
- hProc Initializes a procedure. Replaced by new
- attributes of the PROC directive when you
- specify a language argument to the .MODEL
- directive.
-
- hLocal Initializes local variables. Replaced by new
- functionality of the LOCAL directive.
-
- hRet Returns from a procedure. Replaced by new
- functionality of the RET instruction.
-
- hEndp Terminates a procedure. Replaced by new
- functionality of the ENDP directive.
-
- The 5.1 versions of these macros are different than the MASM 5.0
- versions. The new macros use new MASM features to simulate the same
- functionality more efficiently. Do not use the MIXED.INC provided with
- MASM 5.0. It will not work under MASM 5.1.
-
- Rather than use the old macros, you may want to convert your source
- files to use the built-in mixed language features of MASM 5.1. The
- conversion is straightforward and can be done easily with a text
- editor.
-
- The following changes can be made to source files that use macros from
- the 5.0 MIXED.INC. The source file POWER2.ASM on the MASM 5.1
- distribution disk is an example of a converted source file. You can
- compare it with the POWER2.ASM supplied with MASM 5.0.
-
- o You must define a a memory model argument and a language argument
- to the .MODEL directive to use the new mixed-language features of
- MASM 5.1. You can do this within the source file:
-
- .MODEL small, c
-
- Alternately, you can pass the arguments in from the command line
- using /D. In MASM 5.0, you had to use the setModel macro to
- receive a model argument passed on the command line. You only
- needed to define the language symbol "cLang" for C; no
- definition was needed for other languages.
-
- The 5.0 source line to accept the argument would be:
-
- setModel
-
- For MASM 5.1, change to:
-
- % .MODEL model,lang
-
- Notice that the expression operator (%) is required so that MASM
- can evaluate text arguments passed from the command line.
-
- The 5.0 command line to define C small model would be:
-
- MASM /MX /Dmodel=small /DcLang power2;
-
- For MASM 5.1, change this to:
-
- MASM /MX /Dmodel=small /Dlang=C power2;
-
- o Replace references to the hProc macro with the PROC directive.
- Remember, new features of the PROC directive only work when a
- language argument is given for the .MODEL directive. The 5.0
- macro syntax was:
-
- hProc <name [NEAR|FAR]> [,<USES reglist>] [,arglist]
-
- The 5.1 syntax is:
-
- name PROC [NEAR|FAR] [,USES reglist] [,arglist]
-
- The syntax for each MASM 5.0 argument in the arglist was
-
- argument[:[NEAR|FAR] type]
-
- where the type could be BYTE, WORD, DWORD, FWORD, QWORD, TBYTE, or
- PTR (to indicate that the variable is a pointer).
-
- The syntax for each MASM 5.1 argument is:
-
- argument[:[[NEAR|FAR] PTR] type]
-
- where the type can be BYTE, WORD, DWORD, FWORD, QWORD, TBYTE, or a
- structure type. Note that structure types can now be given. Also,
- PTR is part of the syntax rather than a type. If PTR is given with
- a type, then it means that the variable is a pointer to a variable
- of the given type. This information makes no difference in what
- MASM assembles, but it can be used by the CodeView debugger.
-
- For example, consider the following MASM 5.0 source line:
-
- hProc <doTask FAR>, <USES si di>, count:BYTE, array:PTR, number
-
- It should be changed to the following for MASM 5.1:
-
- doTask PROC FAR USES si di, count:BYTE, array:PTR WORD, number
-
- Notice that the array is now declared as pointer to a word (or an
- array of words). In the 5.0 syntax it was simply a pointer to an
- object of undefined size.
-
- o Replace references to the hLocal macro with the LOCAL directive.
- The syntax for the 5.0 hLocal macro was:
-
- hLocal varlist
-
- The MASM 5.1 syntax is:
-
- LOCAL varlist
-
- The syntax for each 5.0 variable was:
-
- variable[:[NEAR|FAR] type]
-
- The syntax for each 5.1 variable is:
-
- variable[[count]][:[[NEAR|FAR] PTR] type]
-
- The difference is the same as the difference for arguments to the
- PROC directive. In addition, you can allocate local arrays by
- specifying a count (in brackets) following the variable name. For
- example:
-
- LOCAL work[20]:WORD, string:PTR BYTE
-
- This allocates a local array of 20 words called "work" and a
- pointer to byte (called "string").
-
- o Replace references to the hRet macro with the RET instruction.
-
- o Replace references to the hEndp macro with the ENDP directive
- preceded by the procedure name. For example, change
-
- hEndp
-
- to
- procname ENDP
-
- o Under MASM 5.1, labels within a procedure are local to the
- procedure if the language argument is given for the .MODEL
- directive. For example, if you use the label "exit:" in one
- procedure, you can use it again in another procedure. A label
- inside a procedure can be made global to the source file by
- putting two colons after it (example, "glabel::"). Under MASM
- 5.0 all labels were global to the source file.
-
- o Note that the 5.0 macros did not automatically handle 80386
- features such as 32-bit pointers. The 5.1 features do. For
- example, if you use the .386 directive before the .MODEL directive
- to enable 32-bit segments, near pointers declared with PTR will be
- 32 bits wide and far pointers will be 48 bits wide.
-