当我尝试用名称“name”声明一个变量时,它不起作用,它给了我一个错误,这个有错误。
有以下解释
(22) wrong parameters: MOV BL, name
(22) probably no zero prefix for hex; or no 'h' suffix; or wrong addressing; or undefined var: name
这是我的代码
; 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.
问题是,如果我尝试为它工作的变量命名,namee
、nname
、name_
,但大写不起作用,我尝试在整个互联网上进行搜索,但要么我搜索错误,要么我不知道要搜索什么。
最佳答案
NAME
是 MASM 指令的名称,被视为保留字。使用保留字作为变量名会导致问题。 NAME
指令尤其没有做任何有用的事情,因为文档建议 MASM 只是忽略它。来自 MASM manual :
NAME modulename
Ignored.
在 EMU8086 中,除了将 name
变量重命名为其他名称之外,没有任何真正的解决方法。
在 MASM 5.x+ 中,您可以通过以下方式使用 OPTION
指令来解决此问题:
OPTION NOKEYWORD:<NAME>
OPTION NOKEYWORD
在 MASM 手册中是这样定义的:
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>
关于assembly - 为什么程序集 8086 中不允许变量名 "name"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52955216/