Error 35: Operand Must Have Size

ID Number: Q12043

4.00

MS-DOS

Problem:

In the following program, the assembler gives "error 35: Operand must

have size":

code1 segment para public 'code'

assume cs:code1

mov ds:[28H],offset prog1

prog1:

c1 ends

In the following program, the assembler again gives "error 35: Operand

must have size":

code2 segment para public 'code'

assume cs:code2

mov ds:[28h],offset prog2

org 0ffh

prog2:

code2: ends

However, the assembler does not give an error message with the

following program:

code3 segment para public 'code'

assume cs:code3

mov ds:[28h],offset prog3

org 100h

prog3:

code3 ends

It seems that MASM generates an error 35 if the offset of prog

relative to the beginning of the segment is less that 256 bytes.

Nevertheless, I have the following workaround:

code4 segment para public 'code'

assume cs:code4

mov word ptr ds:[28h],offset prog4

prog4:

code4 ends

Response:

In the following, your program statement is calculating the offset

from the beginning of your code segment to the label prog2:, then

placing that value into the location to which ds:28h points:

mov ds:[28h],offset prog2

By generating "error 35: Operand must have size," the assembler is

complaining that you told it to move this offset, but you did not

indicate the size of the offset. Your workaround to this problem is

the correct code; however, you must indicate the size of the offset as

follows:

mov byte ptr ds:[28h],offset prog2

The ORG directive moves the next command down the indicated number of

bytes. For example, in your second program you are moving the prog2

label down 099h bytes. By doing so, you are increasing the size of the

offset by 099h bytes.

The assembler is working correctly when it gives you an error in the

first two example programs, complaining that you did not indicate the

size of the data you want moved.

The reason that you do not get this error in your third example is

that the assembler determines the size of the data you want to move

from the program context, without the "byte ptr" directive. Because

you are moving the prog3: label 100H bytes away, the assembler knows

that you are adding 100h words to the offset; it also knows that you

have to be moving a word into ds:[28h] because the offset is at least

one word in size. Thus, the assembler no longer gives you the error

message.

The assembler gives you an error unless it has enough information to

determine what you want to do.

Page 96 of the "Microsoft Macro Assembler Reference" manual states the

following:

"Many assembly-language program listings in books and magazines are

written for assemblers with weak typing for operands. These programs

may produce error messages such as "Illegal size for item" or "Operand

types must match" when assembled as listed using the Microsoft Macro

Assembler. You can correct lines that product errors by using the PTR

operator to assign the correct size to variables."