1
votes

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
I would come up with new names for each label, but I don't feel comfortable inventing a new loop name for each loop I write, there must be a way to tell NASM to make the labels unique.Fresco
I would solve it with local labels.rkhb
Or maybe don't include but link.Jester

1 Answers

3
votes

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