flat assembler
Message board for the users of flat assembler.

Index > Main > Conditional equates

Author
Thread Post new topic Reply to topic
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Well I found that conditional equates is not possible in this link http://board.flatassembler.net/topic.php?t=525

But I can't use "=" because I can't put ".r1 = ebx", so what can I do to make conditionals equates?

Code:
    .r1         EQU esi
    .r2         EQU ebx
    .r3         EQU edi

    if hDC eq ebx
      .r1  EQU ebx
      .r2  EQU esi
    else if hDC eq edi
      .r1  EQU edi
      .r3  EQU esi
    else if ~ hDC eq esi
      mov    .r1, hDC
    end if
    


hDC is a param of a macro

The final values after this code are:
.r1 EQU edi
.r2 EQU esi
.r3 EQU esi

There is another way to do this?
Post 07 May 2005, 18:17
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7721
Location: Kraków, Poland
Tomasz Grysztar
[Edit: it is now possible to do conditional preprocessing, the solution proposed here is the tricky one that was used with earlier versions of fasm]
In case if you wanted to use register constants for addressing you could also use directives like:
Code:
label .r1 at ebx    

but it cannot be used for instructions like "mov .r1,hDC" in your code.

For your purpose the trick might look like:
Code:
macro ifeq name1,name2,condmacro,elsemacro
{
   macro ifeq#name1 \{ elsemacro \}
   macro ifeq#name2 \{ condmacro \}
   ifeq#name1
   purge ifeq#name2
   purge ifeq#name1
}

ifeq hDC,ebx,macro_for_ebx ; etc.
    


Last edited by Tomasz Grysztar on 12 Jun 2005, 09:19; edited 2 times in total
Post 07 May 2005, 18:29
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: 4633
Location: Argentina
LocoDelAssembly
Here is the new code:
Code:
    macro B1
    \{
      .r1  EQU ebx
      .r2  EQU esi
    \}
    macro B2
    \{
      .r1  EQU edi
      .r3  EQU esi
    \}
    ifeq hDC, ebx, B1
    ifeq hDC, edi, B2
    if ~hDC in <.r1, .r2, .r3>
      mov    .r1, hDC
    end if
    purge B2
    purge B1
    

But it's still problematic if hDC is a param like "[mem]".
It's possible to fix it?

P.S.: This code is for an inline proc implemented as a macro
Post 08 May 2005, 18:10
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Sorry, I forgot to say the error that FASM throws. Razz

When hDC is [mem] says "Error: extra characters on line" but if I comment "purge ifeq#name1" of your macro it works perfect but ifeqname1 will still defined.

It's a bug in FASM?
Post 08 May 2005, 22:27
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7721
Location: Kraków, Poland
Tomasz Grysztar
When hDC is [mem], so becomes the name1, and that line becomes:
Code:
purge ifeq[mem]    

what is of course bad syntax for "purge" and causes an error.

So the conditional preprocessing trick won't help you here, since it works only with simple symbols without any special characters, and you need the condition checking that is provided only at assembly time (sorry for guiding you into wrong direction). I suggest you to redesign the structure of your code, to something like:
Code:
    .r1 equ esi
    .r2 equ ebx
    .r3 equ edi

    if hDC eq ebx
      .r1 equ ebx
      .r2 equ esi
      your_macro
      restore .r1
      restore .r2
    else if hDC eq edi
      .r1  equ edi
      .r3  equ esi
      your_macro
      restore .r1
      restore .r3
    else if ~ hDC eq esi
      mov    .r1, hDC
      your_macro
   end if

   restore .r1
   restore .r2
   restore .r3    

where "your_macro" would containt the code where you actually use the .r1-.r3 constants.
Post 09 May 2005, 08:46
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: 4633
Location: Argentina
LocoDelAssembly
Yeah, that code works fine Very Happy I just modified it a little because if hdc = esi the macro is not assembled. Thank you for your solution it's looks nice since I need less macros than the previous one and works if hDC is [mem] Very Happy

You say "purge" does not support "[]" but I can define a macro like "abc[def]" without problems and use it. How can I undefine such macro if "purge" can't? I not need to define a macro like "abc[def]", I'm only curious. Razz
Post 09 May 2005, 17:08
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7721
Location: Kraków, Poland
Tomasz Grysztar
This line:
Code:
macro abc[def]    

defines the macro called "abc" with group parameter called "def" (see fasm's manual). So to undefine it you would just use "purge abc".
It's just a concidence that you got valid macro definition with hDC equal to [mem].
Post 09 May 2005, 17:21
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7721
Location: Kraków, Poland
Tomasz Grysztar
Actually I think that even better solution might be something like (just an example):
Code:
macro your_macro .r1,.r2,.r3
 {
   ; ...
 }

    if hDC eq ebx
      your_macro ebx,esi,edi
    else if hDC eq edi
      your_macro edi,ebx,esi
    else if ~ hDC eq esi
      mov    .r1, hDC
      your_macro esi,ebx,edi
    end if    
Post 09 May 2005, 17:26
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: 4633
Location: Argentina
LocoDelAssembly
Actually I read the manual but I thought a space between the name of macro and the arguments was always required Razz

Yep, your new solution is less complex and compact, pity that leaves me like an idiot because solutions like that I must have been able to do it without help Embarassed . Sorry for ask you this things, I'm not new in assembly programming but programming with macros is my first time Razz

Thanks
Post 10 May 2005, 13:30
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-2020, Tomasz Grysztar.

Powered by rwasa.