问题
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.
回答1:
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>
来源:https://stackoverflow.com/questions/52955216/why-is-the-variable-name-name-not-allowed-in-assembly-8086