flat assembler
Message board for the users of flat assembler.

Index > Main > equ with if

Author
Thread Post new topic Reply to topic
CandyMan



Joined: 04 Sep 2009
Posts: 413
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan 12 Nov 2017, 18:03
Code:
Bitness =       16

if Bitness=16
BaseReg equ     bp
else
BaseReg equ     ebp
end if
        mov     al,[BaseReg+4] ;always ebp    

it is possible to replace "equ" with something, if only works with "Bitness=16" and "Bitness=32" without using the separate file?

_________________
smaller is better
Post 12 Nov 2017, 18:03
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 12 Nov 2017, 18:06
You can replace the if with match and make bitness an equ.
Code:
Bitness equ       16

match =16,Bitness {
  BaseReg equ     bp
}
match =32,Bitness {
  BaseReg equ     ebp
}    
Post 12 Nov 2017, 18:06
View user's profile Send private message Visit poster's website Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 413
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan 12 Nov 2017, 18:09
thank you!
Post 12 Nov 2017, 18:09
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 12 Nov 2017, 18:17
Alternatively:
Code:
Bitness = 16

if Bitness=16
  label BaseReg at bp
else
  label BaseReg at ebp
end if    
Post 12 Nov 2017, 18:17
View user's profile Send private message Visit poster's website Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 413
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan 12 Nov 2017, 18:32
Tomasz, your alternative is the best!
Post 12 Nov 2017, 18:32
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 12 Nov 2017, 18:47
Note that it has a potential problem that you cannot re-define BaseReg for other part of code when it is defined as a label. If such problem occurs, you can get around it with a simple "undefine" macro:
Code:
macro undefine name
 { local new
   define name new }

Bitness = 32

undefine BaseReg
if Bitness=16
  label BaseReg at bp
else
  label BaseReg at ebp
end if    
Post 12 Nov 2017, 18:47
View user's profile Send private message Visit poster's website Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 413
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan 12 Nov 2017, 22:34
version with "equ" however is better because it doesn't refer only to addressing.
Code:
push BaseReg ;push (e)bp is possible    

_________________
smaller is better
Post 12 Nov 2017, 22:34
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 12 Nov 2017, 22:54
Oh, you're right. This is a limitation of fasm 1 engine that I managed to get rid of in fasm g.
Post 12 Nov 2017, 22:54
View user's profile Send private message Visit poster's website 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.