KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q40095: Intra-Segment Near Calls in MASM

Article: Q40095
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

Question:

When there is an intra-module near call in a MASM program, as in the
following example, why does the assembler generate a self-relative,
intra-segment fixup?

foo proc near
    ...
foo ends

bar proc near
    call foo
bar endp

These are unnecessary as indicated in Intel's "8086 Relocatable
Object Module Formats," Appendix 4, which states the following:

   "Self-Relative references within a single LSEG do not require a fixup,
   the translator puts the appropriate value in LOCATION."

The assembler does not have this problem with near JMPs, only with
CALLs.

Response:

It is correct that Intel states that it is not necessary to perform a
fixup for intra-segment calls. However, it is not forbidden to do so.
Microsoft is making efforts to optimize the assembler without causing
a lack of control by the programmer over the code. While some people
desire a given optimization, there are others who would decry it as a
loss of control over their code. There are keywords that allow you to
force various types of calls and jumps such as the SHORT keyword. Yu
may want to check these to see if they offer the control you need.

The workaround for generation of any special opcode is to use the
"dw" or "db" directive in the code segment. The following can be
assembled [2A D2] or [28 D2]:

   sub dl,dl

To get the second generation, you must enter the following:

   db 28h, 0d2h

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.