Microsoft KB Archive/81888

= FIX: MASM Incorrectly Allows Relative Values as Constant =

Article ID: 81888

Article Last Modified on 10/29/2003

-

APPLIES TO


 * Microsoft Macro Assembler 5.1 Standard Edition
 * Microsoft Macro Assembler 5.1a

-



This article was previously published under Q81888



SYMPTOMS
The Microsoft Macro Assembler (MASM) versions 5.1 and 5.1a incorrectly allow relative expressions to be used as constant expressions if the relative expression is used inside an IF1 directive. Instead of generating an error, the assembler uses the current value of the relative expression as a constant expression.



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



MORE INFORMATION
A constant expression is a numeric expression that can be resolved at assembly time. A relative expression is a expression that cannot be resolved at assembly time and must be resolved at link time. Relative expressions include all data and code labels, including the current location counter, $. Anything that generates a fixup record is a relative expression.

MASM 6.0 correctly generates the following error when a relative expression is used in a place where only a constant is allowed:

error A2026: constant expected

Converting MASM 5.1 programs to MASM 6.0 programs that rely on this problem in MASM 5.1 may be difficult. The difference between two relative expressions is a constant expression, and this may be used to replace the single relative expression. The sample code below demonstrates this workaround. This solution may not be valid in all instances. Since MASM 6.0 evaluates these types of expressions on the first pass only, the constant value may not be what was expected if subsequent passes change the values of the relative expressions.

In MASM 6.0, the IF1 directive is always considered true. The IF2 directive is no longer supported in MASM 6.0.

Sample Code
; Assemble options needed: none

.MODEL small

.STACK

.CODE start: mov    ax, @data mov    ds, ax

mov    ax, 4C00h int    21h

IF1

ProgSize      CATSTR   , %$
 * The following line causes an A2026 error in MASM 6.0.


 * The following line assembles error free in MASM 5.1 and MASM 6.0.
 * ProgSize      CATSTR    , %($-start)

ENDIF

%     %OUT    ProgSize

END   start

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

Keywords: kbfix KB81888

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.