3

When I try to declare a variable with the name "name" it doesn't work, it gives me an error, this one there are errors. with the following explanation

(22) wrong parameters: MOV  BL, name
(22) probably no zero prefix for hex; or no 'h' suffix; or wrong addressing; or undefined var: name

here is my code

; multi-segment executable file template.

data segment
    ; add your data here!
    pkey db "press any key...$"
    name db "myname"
ends

stack segment
    dw   128  dup(0)
ends

code segment
start:
; set segment registers:
    mov ax, data
    mov ds, ax
    mov es, ax

    ; add your code here

    MOV BL, name


    ;;;;;

    lea dx, pkey
    mov ah, 9
    int 21h        ; output string at ds:dx

    ; wait for any key....
    mov ah, 1
    int 21h

    mov ax, 4c00h ; exit to operating system.
    int 21h
ends

end start ; set entry point and stop the assembler.

the thing is, if I try any other name for the variable it works, namee, nname, name_, but upper-case doesn't work, I tried searching all over the internet, but either I'm searching wrong, or I don't know what to search for.

Anton Kahwaji
  • 467
  • 4
  • 15
  • 1
    You can try `MOV BL, BYTE PTR [name]` to get the first byte of `name`. – zx485 Oct 23 '18 at 18:05
  • 2
    @zx485 : In MASM(incl TASM/EMU8086 etc) the [] are implied in the absence of the `offset` keyword. so `name` is actually `[name]`. MASM can infer the size from the destination register (and it also matched the `DB` definition of `name`). The end result is that `MOV BL, name`, `MOV BL, [name]` and `MOV BL, BYTE PTR [name]` are all the same. for sake of readability I'd use `[]`. – Michael Petch Oct 23 '18 at 21:12

1 Answers1

7

NAME is the name of a MASM directive and is considered a reserved word. Using reserved words as variable names will cause problems. the NAME directive in particular doesn't do anything useful as the documentation suggests MASM simply ignores it. From the MASM manual:

NAME modulename

Ignored.

In EMU8086 there isn't any real way around this except to rename the name variable to something else.

In MASM 5.x+ you may be able to work around this problem by using the OPTION directive this way:

OPTION NOKEYWORD:<NAME>

OPTION NOKEYWORD is defined this way in the MASM manual:

MASM reserved words are not case sensitive except for predefined symbols (see “Predefined Symbols,” later in this chapter).

The assembler generates an error if you use a reserved word as a variable, code label, or other identifier within your source code. However, if you need to use a reserved word for another purpose, the OPTION NOKEYWORD directive can selectively disable a word’s status as a reserved word.

For example, to remove the STR instruction, the MASK operator, and the NAME directive from the set of words MASM recognizes as reserved, use this statement in the code segment of your program before the first reference to STR, MASK, or NAME:

OPTION NOKEYWORD:<STR MASK NAME>
Michael Petch
  • 46,082
  • 8
  • 107
  • 198