PRMSM9109004: MASM 5.1 Incorrectly Assembles Lines with LOCK

ID Number: Q76727

5.10 5.10a | 5.10 5.10a

MS-DOS | OS/2

buglist5.10 buglist5.10a fixlist6.00

Summary:

PROBLEM ID: MSM9109004

SYMPTOMS

The Microsoft Macro Assembler (MASM) versions 5.1 and 5.1a will not

flag an error while assembling code that uses the LOCK prefix with

an incorrect instruction. MASM will not generate an error, and the

code generated will run without errors on some machines.

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:

According to the Intel 80386 programmer's reference manual, the LOCK

prefix is valid only with the following instructions:

BT, BTS, BTR, BTC mem, reg/imm

XCHG reg, mem

XCHG mem, reg

ADD, OR, ADC, SBB, AND, SUB, XOR mem, reg/imm

NOT, NEG, INC, DEC mem

The sample code below will assemble with MASM versions 5.1 and 5.1a,

and the LOCK prefix will be embedded before the REP prefix. While the

code generated will run without errors, the processor will generate a

invalid instruction exception (int 6).

MASM version 6.0 will generate the following error when the sample

code is assembled:

FILE.ASM(22): error A2008: syntax error : rep

Sample Code

-----------

; Assemble options needed: none

.MODEL small

.STACK

.DATA

str DB "Hello, world.", 13, 10, "$"

msg DB 16 DUP(?)

.CODE

start: mov ax, @DATA ; Load DS and ES

mov ds, ax

mov es, ax

mov cx, 10h ; Load the SI, DI, and CX

mov si, OFFSET str ; registers for the string

mov dx, OFFSET msg ; transfer. Note DX is loaded

mov di, dx ; for the INT 21h call.

lock rep movsb ; This line does not assemble.

mov ah, 9h ; Request DOS Function 9

; (segment already in DS).

int 21h ; Display string to stdout.

mov ax, 4C00h ; Exit functions with 0 in AL.

int 21h ; Exit Program with Return Code.

END start

Additional reference words: 5.10 5.10a 6.00