assembly - 为什么程序集 8086 中不允许变量名 "name"?

标签 assembly x86-16 emu8086

当我尝试用名称“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.

问题是,如果我尝试为它工作的变量命名,nameennamename_,但大写不起作用,我尝试在整个互联网上进行搜索,但要么我搜索错误,要么我不知道要搜索什么。

最佳答案

NAMEMASM 指令的名称,被视为保留字。使用保留字作为变量名会导致问题。 NAME 指令尤其没有做任何有用的事情,因为文档建议 MASM 只是忽略它。来自 MASM manual :

NAME modulename

Ignored.

EMU8086 中,除了将 name 变量重命名为其他名称之外,没有任何真正的解决方法。

MASM 5.x+ 中,您可以通过以下方式使用 OPTION 指令来解决此问题:

OPTION NOKEYWORD:<NAME>

OPTION NOKEYWORDMASM 手册中是这样定义的:

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/

相关文章:

assembly - 以 8086 读取文件,直到文件结束

c - 混淆的 C/asm "Hello, world!"程序,我不明白

assembly - MSP430 中的 sxt 指令到底有什么作用?

c++ - 在 C++ 中调用汇编

c++ - 监控操作码

assembly - 汇编器无法打开文件

assembly - 8086中段寄存器的值是多少?

assembly - 如何将用户输入的16位数字转换为十进制

assembly - 在汇编中显示数据

assembly - 8086随机数生成器(不仅仅是使用系统时间)?