为什么变量名是“name"不允许在程序集 8086 中使用? [英] Why is the variable name "name" not allowed in assembly 8086?

查看:16
本文介绍了为什么变量名是“name"不允许在程序集 8086 中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试声明一个名为name"的变量时,它不起作用,它给了我一个错误,这个有错误.有以下解释

(22) 错误的参数:MOV BL, name(22) 十六进制可能没有零前缀;或没有h"后缀;或地址错误;或未定义的 var: name

这是我的代码

<代码>;多段可执行文件模板.数据段;在此处添加您的数据!pkey db "按任意键...$"名称数据库我的名字"结束堆栈段dw 128 重复 (0)结束代码段开始:;设置段寄存器:mov ax, 数据mov ds, ax移动,斧头;在此处添加您的代码MOV BL,名称;;;;;lea dx, pkey动啊,9整数 21 小时;ds:dx 处的输出字符串;等待任何键....动啊,121 小时移动斧头,4c00h;退出操作系统.21 小时结束结束开始;设置入口点并停止汇编程序.

问题是,如果我为它工作的变量尝试任何其他名称,nameennamename_,但是大写不起作用,我尝试在整个互联网上搜索,但要么我搜索错误,要么我不知道该搜索什么.

解决方案

NAMEMASM 指令的名称,被视为保留字.使用保留字作为变量名会导致问题.特别是 NAME 指令没有做任何有用的事情,因为文档建议 MASM 只是忽略它.来自MASM手册:><块引用>

NAME 模块名

忽略.

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

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

OPTION NOKEYWORD:

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

<块引用>

MASM 保留字不区分大小写,除了预定义的符号(参见本章后面的预定义符号").

如果使用保留字作为变量,汇编器会产生错误,代码标签或源代码中的其他标识符.然而,如果您需要将保留字用于其他目的,即 OPTIONNOKEYWORD 指令可以有选择地禁用单词的状态作为保留字.

比如去掉STR指令,MASK运算符,以及 MASM 识别的一组单词中的 NAME 指令作为保留,在程序的代码段中使用此语句在第一次引用 STR、MASK 或 NAME 之前:

OPTION NOKEYWORD:

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.

解决方案

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>

这篇关于为什么变量名是“name"不允许在程序集 8086 中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆