BUG: SIB MOV EAX,[EAX+EBP] Generates Incorrect Code (97110)
The information in this article applies to:
- Microsoft Macro Assembler (MASM) 6.0
- Microsoft Macro Assembler (MASM) 6.0a
- Microsoft Macro Assembler (MASM) 6.0b
- Microsoft Macro Assembler (MASM) 6.1
- Microsoft Macro Assembler (MASM) 6.1a
- Microsoft Macro Assembler (MASM) 6.11
This article was previously published under Q97110 SYMPTOMS
An attempt to use scaled index base (SIB) indirect operands may fail.
If EBP is used and the stack and data segments do not have the same
base address, the generated code executes incorrectly. In addition, if
EBP is used as the index register, it is coded as the base register,
which generates an additional byte in the instruction encoding.
CAUSE
When the code does not use a scaling factor, the Microsoft Macro
Assembler (MASM) may reverse the base and index registers. When this
occurs, MASM incorrectly treats the first register as the index and
the second register as the base in an SIB indirect operand.
If the code uses EBP or ESP as the base register, the indirect operand
should access memory through the stack segment. When the code uses any
other register as the base register, the indirect operand should
access memory through the data segment. Because the assembler reverses
the base and index registers, it uses the index register to determine
the segment through which to access memory. However, the ESP register
can be used only as a base register. Therefore, the problem occurs
only when the code uses the EBP register.
RESOLUTION
To work around this problem, use a scaling factor to explicitly
indicate which register is the index register. The sample below
demonstrates this procedure.
STATUS
Microsoft has confirmed this to be a problem in MASM versions 6.0,
6.0a, 6.0b, 6.1, 6.1a, and 6.11. We are researching this problem and
will post new information here in the Microsoft Knowledge Base as it
becomes available.
Modification Type: | Minor | Last Reviewed: | 10/30/2003 |
---|
Keywords: | KB97110 |
---|
|