Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Bugs and Fixes

global variable redeclared

A community discussion post from the original code:zIRON forum.

Replies

0CodErr member
Posts
201
Threads
37
Location
Unknown

It would be better to do it automatically. Now using $labelref() similar to using $_uniquelabel.

I tried to compare $labelref() and $_uniquelabel

program RAW_IMAGE 'test';

#set bits 32;

inline procedure Test_labels1() {  
  $l1 = $labelref();
  eax = $l1; 
$l1:  
}

Test_labels1();
Test_labels1();


inline procedure Test_labels2() {  
  $l1 = $_uniquelabel;
  eax = $l1; 
$_e($l1):  
}

Test_labels2();
Test_labels2();

Result:

00000000  B805000000        mov eax,0x5
00000005  B80A000000        mov eax,0xa
0000000A  B814000000        mov eax,0x14
0000000F  B81D000000        mov eax,0x1d
00000014  5F                pop edi
00000015  5F                pop edi
00000016  5F                pop edi
00000017  305F5F            xor [edi+0x5f],bl
0000001A  5F                pop edi
0000001B  3000              xor [eax],al
0000001D  5F                pop edi
0000001E  5F                pop edi
0000001F  5F                pop edi
00000020  315F5F            xor [edi+0x5f],ebx
00000023  5F                pop edi
00000024  3000              xor [eax],al
Colin admin
Posts
928
Threads
49
Location
Bulgaria

The reason for this is because macro variables can not automatically initialized as a label else it would cause many problems later, not to mention will make it difficult in some cases especially if making a mistake.

e.g.

inline procedure ABC($asal) {
  eax = $asai;
 
  $return eax;
}

Here we have a typo which will go unnoticed because asai will automatically become a label (as a macro variable)

The other difference is $_uniquelabel returns a unique string name as a label whereas $labelref creates an entry into the label manager.

So in your case using labelref you will need to write eax = @$l1;

eax = $label; // eax is the offset of the label

eax = @$label; // eax is the absolute address
0CodErr member
Posts
201
Threads
37
Location
Unknown
The other difference is $_uniquelabel returns a unique string name as a label whereas $labelref creates an entry into the label manager.

Maybe it also is problem?

program RAW_IMAGE 'test';

#set bits 32;

  $l1 = $_uniquelabel;
  $l2 = $_uniquelabel;  
  
___1___0:  
$_e($l1):
$_e($l2):  

Cannot compile because

Reserved label
Colin admin
Posts
928
Threads
49
Location
Bulgaria

This is not a problem, since this is a programmer purposely looking to break the compiler :lol: anyways in this case it will be better to use $labelref.