flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Complex conditions in .IF, .WHILE...

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 09 Jan 2006, 20:25
Hello,

I have been reading through the documentation but I don't find the solution for this.

I have read that FASM supports structure conditions like in C, Delphi... (.IF, .WHILE...)

Is there any way to do more complex conditions check in FASM:

.while (eax && ebx) || ecx
bla, bla, bla

I know that it's possible in MASM.

Thanks.
Post 09 Jan 2006, 20:25
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 10 Jan 2006, 01:10
Funny coincidece, I was just thinking about finally writing a macro that would parse such expressions. I will post it here as soon as I finish it.
Post 10 Jan 2006, 01:10
View user's profile Send private message Visit poster's website Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi 10 Jan 2006, 03:17
useful... to decrease ammount of lines of code Smile
and does code easier to read for ppl who code with hlls too Smile

_________________
When We Ride On Our Enemies
support reverse smileys |:
Post 10 Jan 2006, 03:17
View user's profile Send private message MSN Messenger Reply with quote
shism2



Joined: 14 Sep 2005
Posts: 248
shism2 10 Jan 2006, 03:47
I think it looks better....

.while eax and ebx ? ebx

what does || means ?
Post 10 Jan 2006, 03:47
View user's profile Send private message Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi 10 Jan 2006, 03:53
|| = | = OR
&& = & = AND

atleast in mIRC scripting Laughing || = OR

_________________
When We Ride On Our Enemies
support reverse smileys |:
Post 10 Jan 2006, 03:53
View user's profile Send private message MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 10 Jan 2006, 05:23
tomasz: with your macros people will soon perform rep scasb/DF=0 with
Code:
.while ([es:edi] != eax) && (ecx))
  dec ecx
  inc edi
.endwhile    

:]. Or even like this (with macros you showed some time ago):
Code:
mov ecx,0
.while ecx<10
  getinput(<getstdhandle(STD_IN)>)
  .if eax==-1
    error("Can't read input")
  .else
    mov [array+ecx], eax
  .endif
.endwhile    

Crying or Very sad Crying or Very sad
Wink

btw: don't you think it's stupid convention to start macro names with "." in FASM? I know it comes from TASM/whatever, but symbols starting with "." already means something in FASM, and these cause problems and confuse. Rather use "_" prefix or maybe someone can think of some very short descriptive prefix for these macros.
Post 10 Jan 2006, 05:23
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 10 Jan 2006, 06:47
Thanks guys!

Tomasz, can't wait to see that new macro in action! Very Happy

I think assembler is great but it's also good to use high level syntax. One day we will get back to some "old" assembly application that we did and believe me, if you don't have a clear assembly code (comments, structured...) you will be amazed about what the hell you were coding at each line Smile

Well, at least from my experience, which has been a many hell years programming in assembly Smile

BTW: I think that ".if" ".while"...style is quite good for me. If you use it many times, you will fill confortable with it and you will write the dot "." unconsciously Smile
Post 10 Jan 2006, 06:47
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 10 Jan 2006, 15:21
alorent wrote:
One day we will get back to some "old" assembly application that we did and believe me, if you don't have a clear assembly code (comments, structured...) you will be amazed about what the hell you were coding at each line Smile

Well, BTW, I have almost no comments in fasm's sources, but still have no such problems with my code, even the parts written six years ago. Wink Well, the label naming and some code conventions do help, anyway...
Post 10 Jan 2006, 15:21
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 10 Jan 2006, 16:53
vid wrote:
tomasz: with your macros people will soon perform rep scasb/DF=0 with (...)

Well, I personally don't recommend using such macros, and you will never meet them in any piece of my code*, but I just want to make such macros as a kind of demonstration, like "OK, you can do it with fasm... So what?"

And, BTW, to be compatible with fasm's syntax conventions, it would have to be like:
Code:
.while (eax & ebx) | ecx     
and this is what I'd like to implement.

* I'm the kind of programmer that learned programming starting with the good old BASIC, where you had to use things like "IF A=1 THEN GOTO 100". And even though I then also learned the structured languages, the constructions like the mentioned one are still more readable and "natural" for me than any IF/ENDIF etc. And for this very reason I find CMP/JE much more readable than any .if-like macros. Well, a matter of habit, one might say; but I am a declared adversary of structured programming. Nevertheless, I implement things that I don't like as a macro packages, so I don't have to put something I dislike into my assembler, but the people that prefer it can still extend the assembler with macros to be able to do it.
Post 10 Jan 2006, 16:53
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 10 Jan 2006, 18:42
Tomasz Grysztar wrote:
* I'm the kind of programmer that learned programming starting with the good old BASIC, where you had to use things like "IF A=1 THEN GOTO 100". And even though I then also learned the structured languages, the constructions like the mentioned one are still more readable and "natural" for me than any IF/ENDIF etc. And for this very reason I find CMP/JE much more readable than any .if-like macros. Well, a matter of habit, one might say; but I am a declared adversary of structured programming. Nevertheless, I implement things that I don't like as a macro packages, so I don't have to put something I dislike into my assembler, but the people that prefer it can still extend the assembler with macros to be able to do it.


lol. I though I was the only one who started with BASIC.. but I was quite a noob there (didn't even now how to use variables, I always coded my 'games' in hardcore fashion, very bad!), but I liked a lot the "IF A=1 THEN GOTO 100" thing. Still, learning C was when I first get a 'real' grasp onto programming, but I, most of the time, find the goto thing easier.. even some test programs I do in C, I usually use if(cond) goto label; Very Happy

Sometimes I prefer the C IF/ENDIF style (or Pascal style), but most of the time I use goto because it seems there's always a little optimization you can add with it. These macros might come handy for some situations, but you should always try to imagine what will be actually assembled if you want to use them correctly, without unnecessary bloat (that's assembly's primary target, isn't it?). One should get the idea of not overusing these macros. It's kinda like "Take the good from both sources, they both have their goodies and flaws". Smile


PS: Tomasz, comments are always useful, try to add some in sources. Smile Just some hints, maybe put some empty lines between some pair of instructions, so special operations can be separated from each other? Wink
Post 10 Jan 2006, 18:42
View user's profile Send private message Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 10 Jan 2006, 21:05
Hello,

Tomasz, I agree with your convention like:

.while (eax & ebx) | ecx

It follows the syntax for the conditional compiler, hence it's "FASM syntax" Smile

About structured convention issues, my experience was that I used also cmp/test/jump and not structured conditions for many years. But later I found structured features in assembler and I found it much better than the cmp/jmp. You know, you forget about naming labels...and sometimes the most difficult thing is to find a good name for a label than the coding itself Smile

Anyway, I think all is a matter of getting used to something Smile I just was used to cmp/jmp and IF/ELSE/END and I prefer the last one Smile

Thanks.
Post 10 Jan 2006, 21:05
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 10 Jan 2006, 21:47
alorent wrote:
and sometimes the most difficult thing is to find a good name for a label than the coding itself Smile

Indeed. But finding such a good name is in my opinion so important that I never feel that my time was wasted, even when it took much longer to make label names than coding.
Though I confess I'm not really satisfied with some of my label creations.
Post 10 Jan 2006, 21:47
View user's profile Send private message Visit poster's website Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 10 Jan 2006, 22:44
Tomasz, talking about structuring directives in FASM.

Is it possible for you to add also ".IF" statements to check status of flags like in MASM?

Example:

.IF ZERO? ---> jz MyLabel

That will add full support for structuring code in FASM Smile

Thanks.
Post 10 Jan 2006, 22:44
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 11 Jan 2006, 20:54
OK, it's here (in attachment), beta version ready for your testing. Below I provide quickly a few samples of what is now possible with this macro package:
Code:
.while (eax & ebx) | ecx
 ; ...
.endw

.if CARRY?
 ; ...
.endif

.repeat
 ; ...
.until ~ ZERO?

.if eax < 5 | ( ebx>=4 & ~ ecx )
 ; ...
.endif    


Description: The new generation .if macros
Download
Filename: IF.INC
Filesize: 8.41 KB
Downloaded: 397 Time(s)



Last edited by Tomasz Grysztar on 15 Jan 2006, 17:23; edited 1 time in total
Post 11 Jan 2006, 20:54
View user's profile Send private message Visit poster's website Reply with quote
shism2



Joined: 14 Sep 2005
Posts: 248
shism2 11 Jan 2006, 21:33
is there a possibilty of you adding author ( asmgges ) hll .on macros ?
Post 11 Jan 2006, 21:33
View user's profile Send private message Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 11 Jan 2006, 22:21
Hello Tomasz,

Well, any .IF condition that I write (simple or complex) fails with the new IF.INC

With previous IF.INC I could at least put simple .IF condition (ie, ".if eax")

Is there anything wrong or I have to include other include files to make it work?

Thanks.
Post 11 Jan 2006, 22:21
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 11 Jan 2006, 22:25
Forgot to note that you need fasm 1.65, since those macros use "define" extensively. Are you using 1.65?
Post 11 Jan 2006, 22:25
View user's profile Send private message Visit poster's website Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 11 Jan 2006, 23:06
Hello Tomasz,

I'm using version 1.65.5.

Is this OK?

Thanks.
Post 11 Jan 2006, 23:06
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 11 Jan 2006, 23:14
Well, and this simplest source works with 1.65.5, at least when I try it:
Code:
include 'if.inc'

.if eax
.endif    

Not mentioning all the samples from my post above (which also work when I test them).
Post 11 Jan 2006, 23:14
View user's profile Send private message Visit poster's website Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 11 Jan 2006, 23:29
Hello Tomasz,

Sorry, I had a big disorder in my include files Smile

Anyway, trying with this example fails:

include 'if.inc'

.if byte [esi] = '5'
.endif

Is that syntax OK to check to char('5')?

Thanks
Post 11 Jan 2006, 23:29
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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.