flat assembler
Message board for the users of flat assembler.

Index > Main > @@: "error: already defined"?

Author
Thread Post new topic Reply to topic
Grom PE



Joined: 13 Mar 2008
Posts: 114
Location: i@grompe.org.ru
Grom PE 14 Jul 2008, 21:12
Why this code gives an error?

Code:
macro mymacro
{
  @@:
}

repeat 5
  mymacro
end repeat    


How can I use macros with labels in "repeat" blocks then?
Post 14 Jul 2008, 21:12
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 14 Jul 2008, 21:32
In short: use REPT instead of REPEAT.

Code:
macro mymacro
{ 
  @@: 
} 

rept 5
{
  mymacro
}    
Post 14 Jul 2008, 21:32
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 14 Jul 2008, 21:33
You could use rept instead (and with its limitations with the counter), however, I wonder if this is a bug or not, it would be perfectly understandable for the case of non anonymous labels, but since @@ is an special case I would expect different behavior.
Post 14 Jul 2008, 21:33
View user's profile Send private message Reply with quote
Grom PE



Joined: 13 Mar 2008
Posts: 114
Location: i@grompe.org.ru
Grom PE 14 Jul 2008, 21:39
Oh well. That was just minimal code that gives an error.
I can't use "rept" because I have some assembly-time calculations and break in the loop.
Is there assembly-time solutions?

"while" doesn't solve this too, so I'm stuck.
Post 14 Jul 2008, 21:39
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 14 Jul 2008, 22:00
Code:
format pe gui 4.0
macro mymacro
{
local someLabel

someLabel = $
  jne someLabel
}

cmp eax, eax
repeat 5
  mymacro
end repeat
int3       


Code:
00401000 > 39C0             CMP EAX,EAX
00401002  -75 FE            JNZ SHORT macro.00401002
00401004  -75 FE            JNZ SHORT macro.00401004
00401006  -75 FE            JNZ SHORT macro.00401006
00401008  -75 FE            JNZ SHORT macro.00401008
0040100A  -75 FE            JNZ SHORT macro.0040100A
0040100C   CC               INT3    
Post 14 Jul 2008, 22:00
View user's profile Send private message Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP 14 Jul 2008, 22:05
^^ I think he means that the 'local' directive might help you out with labels inside of macros.
Post 14 Jul 2008, 22:05
View user's profile Send private message Visit poster's website Reply with quote
Grom PE



Joined: 13 Mar 2008
Posts: 114
Location: i@grompe.org.ru
Grom PE 14 Jul 2008, 22:07
LocoDelAssembly, thank you! It works like a charm =)
Post 14 Jul 2008, 22:07
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 14 Jul 2008, 22:09
The local is just for the purpose of making the assembly-time variable inaccessible outside the scope of the macro, the thing that fix the problem is using a variable instead of a label.
Post 14 Jul 2008, 22:09
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.