KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q27835: FIX: Operator "." and the Operator "*"

Article: Q27835
Product(s): Microsoft Macro Assembler
Version(s): 5.0,5.1,5.1a
Operating System(s): 
Keyword(s): 
Last Modified: 06-MAY-2001

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

- Microsoft Macro Assembler (MASM), versions 5.0, 5.1, 5.1a 
-------------------------------------------------------------------------------

SYMPTOMS
========

When using scaled indexed addressing in the following Microsoft Macro Assembler
(MASM) 5.0, 5.1, or 5.1a instruction, the opcode generated is incorrect. Note
that the variable "esi" is being used as an index into a structure and "eax" is
the base.

     mov eax,[eax.esi*2]

The opcodes generated by MASM indicate that MASM is not using scaled indexed
addressing. The code generated by MASM is effectively the same as:

     mov eax,[eax+esi]

CAUSE
=====

The problem occurs because the "." operator has a higher precedence than the "*"
operator. MASM turns:

     [eax.esi*2]

  into

     [(eax+esi)*2]

as a result of the precedence. MASM evaluates "(eax+esi)" as a constant instead
of a register. Thus, the result of the constant expression "(eax+esi)" is
multiplied by two and the addressing mode is lost. This results in MASM
interpretting the operand as [eax+esi]

RESOLUTION
==========

One workaround is to use the "+" operator which has lower precedence than the
"." operator and produces the correct result. Alternately parenthesis can be
used to give higher precedence to the "*" operator.

STATUS
======

Microsoft has confirmed this to be a problem in MASM version 5.0, 5.1, and 5.1a.
This problem was corrected in MASM version 6.0.

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

Under Microsoft MASM 6.0 the following error will be generated.

  error A2026: constant expected

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

  ; Assemble options needed: none

  .386
  _TEXT SEGMENT PARA PUBLIC USE16 'CODE'
    ASSUME cs:_TEXT
  start:
    mov eax,[eax+esi*2]   ; This is the desired instruction
                          ; Note the use of "+" instead of "."
    mov eax,[eax.(esi*2)] ; This is also the desired instruction
                          ; Note the use of () around the "*"
    mov eax,[eax.esi*2]   ; This is the format that is misinterpreted
                          ; Under MASM 6.0 this generates an A2026
    mov eax,[eax+esi]     ; This is what is incorrectly generated
                          ; by MASM 5.0, 5.1, and 5.1a
    mov ax, 4C00h
    int 21h
  _TEXT ENDS

  END start

Additional query words: 5.00 5.10 5.10a buglist5.00 buglist5.10 buglist5.10a fixlist6.00

======================================================================
Keywords          :  
Technology        : kbMASMsearch kbAudDeveloper kbMASM510 kbMASM500 kbMASM510a
Version           : :5.0,5.1,5.1a
Solution Type     : kbfix

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

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.