问题
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
File 1:
.label1
;staff
Now file 2:
;code that uses label1
.label1 ; definition after usage
Now if I:
%include "file1.asm"
%include "file2.asm"
The resulting main.asm would be:
.label1
;staff
;code that uses label1
.label1 ; definition after usage
Code at line 3 would actually use label1 at line one and not the one at line 4
Quote from NASM Manual
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:
File 1:
file1: ; add this label
.label1
;staff
Now file 2:
file2: ; add this label
;code that uses label1
.label1 ; definition after usage
Everything works great!
Access them with:
file1.label1
file2.label1
回答1:
With local labels. Local labels start with a dot.
Someproc:
.Somelabel:
Ret
Anotherproc:
.Somelabel:
Ret
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
来源:https://stackoverflow.com/questions/26979005/nasm-assembler-how-to-define-label-twice