在 JWasm 中禁用本地标签

Disabling local labels in JWasm

我在汇编指令引用不同过程中的标签的代码时收到一条错误消息。

此代码产生两个错误,汇编程序是 JWasmR v2.12pre:

single segment stack                                                      
assume cs:single,ds:single,ss:single 

start:
    mov ax, cs 
    mov ds, ax                   
    mov ax, 4c00h
    int 21h

func1 proc
label1:
    jmp label2
func1 endp

func2 proc
label2:
    call label1
func2 endp

align 2                          
s16 db 256 dup (0ffh)            
single ends                             
end start

错误信息:

test1.asm(13) : Error A2102: Symbol not defined : label2
test1.asm(20) : Error A2102: Symbol not defined : label1

我认为每个标签符号都是其各自过程的局部。我想全局禁用此功能,或单独绕过它。我试过使用 -Zf 选项使所有符号都变成 public。可以找到文档 here.

在 MASM 5.1x 中,如果您没有使用带有语言类型的 .MODEL 指令,那么 PROC 中的代码标签是全局作用域的。这就是为什么您的代码 assembles 在 MASM 5.1x 中。在 JWASM 和 MASM 6.1+ 中有点不同,因为后跟 : 的代码标签总是在 PROC 中局部作用域。这会导致您看到的错误。 MASM 6.1 documentation 涵盖了这个问题:

MASM 5.1 considers code labels defined with a single colon inside a procedure to be local to that procedure if the module contains a .MODEL directive with a language type

解决方案是在标签后面使用 :: 而不是 : 来将代码标签标记为全局定义。文档接着说:

You can use the double colon operator to define a non-scoped label

使用 :: 应该使您的代码 assemble 具有 MASM 5.1+、6.1+ 和 JWASM。此代码:

func1 proc
label1:
    jmp label2
func1 endp

func2 proc
label2:
    call label1
func2 endp

如果写成:

应该可以工作
func1 proc
label1::
    jmp label2
func1 endp

func2 proc
label2::
    call label1
func2 endp

您可以使用 -Zm 选项(不要与 -mz 混淆)启用 MASM 5.1 兼容性。 运行 JWASM 这种方式应该允许您的代码 assemble 无需任何更改:

jwasm -Zm filename.asm

使用此方法将使 PROC 全局范围内的局部范围标签。发生的其他变化是:

Option -Zm (or setting OPTION M510) will do:
- set OPTION OLDSTRUCTS
- set OPTION DOTNAME
- set OPTION SETIF2:TRUE
- set OPTION OFFSET:SEGMENT (if no model is set)
- set OPTION NOSCOPED (if no model with language specifier is set)
- allow to define data items behind code labels
- allow "invalid" use of REP/REPE/REPNE instruction prefixes
- change precedence of [] and () operator from 1 to 9. Hence expression
  -5[bx] is parsed as (-5)[bx], while without -Zm it is
  parsed as -(5[bx]), which generates an error.

对于 JWASM 和 MASM 6.1+,您还可以使用以下指令在汇编模块的顶部指定无作用域选项:

OPTION NOSCOPED

此选项在 MASM 5.1x 中不存在,因为这是 assembler 的行为。如果使用 MASM 5.1x 进行汇编,则必须从汇编代码中删除该指令。 MASM 6.1 文档将此选项描述为:

The information in this section applies only if the .MODEL directive in your MASM 5.1 code does not specify a language type. Without a language type, MASM 5.1 assumes code labels in procedures have no “scope” — that is, the labels are not local to the procedure. When not in compatibility mode, MASM 6.1 always gives scope to code labels, even without a language type. To force MASM 5.1 behavior, specify either OPTION M510 or OPTION NOSCOPED in your code