NASM汇编器,如何两次定义标签? [英] NASM Assembler, how to define label twice?

查看:94
本文介绍了NASM汇编器,如何两次定义标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有不同的"* .asm"文件需要包含在"main.asm"文件中. 我面临的问题是:在许多文件中,我都以相同的方式(例如,具有相同的名称)声明了诸如"loop","forLoop","whileTag"等标签. 当我尝试%include"file1.asm"和%include"file2.asm"时,它给了我一个编译错误.它说我不能两次声明相同的标签(即file1.asm和file2.asm都声明了"loopHere"标签). 我该如何解决? 谢谢

I have different "*.asm" files that need to be included in the "main.asm" file. The problem I'm facing is that: In many files I have declared labels like "loop", "forLoop", "whileTag" etc... in the same way ( i.e. with the same name ) And when I try to %include "file1.asm" and %include "file2.asm" it gives me a compilation error. It says that I can't declare the same label twice ( i.e. file1.asm and file2.asm, both have "loopHere" label declared ). How do I solve this ? Thanks

本地标签的问题是: 说我有

The problem with local labels is: Say I have

文件1:

.label1
;staff

现在文件2:

;code that uses label1
.label1 ; definition after usage

现在,如果我:

%include "file1.asm"
%include "file2.asm"

生成的main.asm将是:

The resulting main.asm would be:

.label1
;staff
;code that uses label1
.label1 ; definition after usage

第3行的代码实际上将在第1行使用label1,而不是在第4行使用

Code at line 3 would actually use label1 at line one and not the one at line 4

NASM手册的引用

以单个句点开头的标签被视为本地标签,这意味着它与先前的非本地标签相关联.

A label beginning with a single period is treated as a local label, which means that it is associated with the previous non-local label.

我很糟糕,我只是意识到,如果我:

My bad, I just realized that if I:

文件1:

file1: ; add this label
.label1
;staff

现在文件2:

file2: ; add this label
;code that uses label1
.label1 ; definition after usage

一切正常!

通过以下方式访问它们:

Access them with:

file1.label1
file2.label1

推荐答案

带有本地标签.本地标签以点开头.

With local labels. Local labels start with a dot.

Someproc:
.Somelabel:
Ret

Anotherproc:
.Somelabel:
Ret

它们对所在的proc可见.您可以通过在proc名称前添加前缀来从任何位置访问它们.

They are visible to the proc they are in. You can access them from anywhere by prefixing them with the proc name.

Someproc:
.Somelabel:
Ret

Anotherproc:
.Somelabel:
jmp Someproc.Somelabel

这篇关于NASM汇编器,如何两次定义标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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