No Error Given for Same Register Listed Twice in USES Clause

ID Number: Q72727

6.00 | 6.00

MS-DOS | OS/2

Summary:

The USES clause was added to the PROC directive with the release of

the Microsoft Macro Assembler (MASM) version 6.0. With USES, it is

possible to specify the registers that your procedure will use. The

assembler will then save the registers on the stack at function entry

and restore them upon exit, saving the programmer from having to do

so.

If you mistakenly list the same register twice in the USES clause,

MASM will not generate a warning. This is correct behavior and the

assembler will just generate code to push and pop the register twice.

The sample code below illustrates this situation. In this example, the

ES, DI, DS, SI, and CX registers were meant to be saved. However, DI

is inadvertently saved twice, and SI is not saved at all. It is the

programmer's responsibility to catch this type of error.

Sample Code

-----------

; Assemble Options Needed: /Fl /Sg /c

.model small, c

.stack

.data

.code

StrCmp PROC USES es di ds di cx,

string1:FAR PTR, string2:FAR PTR, len:WORD

cld

mov cx, len

les di, string1

lds si, string2

repe cmpsb

mov ax, cx

StrCmp ENDP

END