flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > BUG: labels in macros within repeat

Author
Thread Post new topic Reply to topic
peter müller



Joined: 18 Feb 2004
Posts: 4
Location: LE / Germany
peter müller
Hi,

following code doesn't work. also local and @@ dosen't work

macro crc16r_decode {
mov dh,dl
shr dl,1
xor dh,al
test dh,1
jz .no_xor
xor eax, 18005h
.no_xor:
shr eax,1
}

foo:
repeat 8
crc16r_decode
end repeat

see also: http://board.flatassembler.net/topic.php?t=1106

with best regards
peter[/url]
Post 23 Feb 2004, 19:30
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
You cannot define the same label more than once, and it happens when you put it inside the "repeat" block, because it is processed at assembly time.

The only symbols that can be redefined at assembly time are the numeric constants (but you cannot forward-reference when you redefine them at least once).
Post 23 Feb 2004, 19:37
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
Here's the quick and dirty solution with numerical constant as a redefinable moving pointer for base of repeated code (we can't just use constant to keep the pointer to "no_xor", because it cannot be forward-referenced):
Code:
virtual at 0
 mov dh,dl
 shr dl,1
 xor dh,al
 test dh,1
 jz no_xor
 xor eax, 18005h
 no_xor:
 shr eax,1
end virtual

macro crc16r_decode {
 local base
 base = $
 mov dh,dl
 shr dl,1
 xor dh,al
 test dh,1
 jz base+no_xor
 xor eax, 18005h
 ;base+no_xor:
 shr eax,1
}

repeat 8
crc16r_decode
end repeat    
Post 23 Feb 2004, 19:42
View user's profile Send private message Visit poster's website Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
Doesn't local directive imply that given label is local for this macro?

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 23 Feb 2004, 21:34
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
Yes, but this macro is processed only once, at it occurs only once in source. The "repeat" directive is processed at assembly time, when macro is already replaced with the preprocessed instructions, so the "base" is the same symbol in the each repetition, as it is just the same line of preprocessed source.
Post 23 Feb 2004, 22:05
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
Hi, Privalov.
What if there is some preprocessor directive for "phisical" repeading macroses? I know this will enlarge the memory requirements, but if the count is reasonably small, (and it is, in most of the cases) it may solve a lot of problems like above.

Regards.
Post 23 Feb 2004, 22:19
View user's profile Send private message Visit poster's website ICQ Number 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.