flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Complex conditions in .IF, .WHILE... Goto page 1, 2 Next |
Author |
|
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.
|
|||
10 Jan 2006, 01:10 |
|
okasvi 10 Jan 2006, 03:17
useful... to decrease ammount of lines of code
and does code easier to read for ppl who code with hlls too _________________ When We Ride On Our Enemies support reverse smileys |: |
|||
10 Jan 2006, 03:17 |
|
shism2 10 Jan 2006, 03:47
I think it looks better....
.while eax and ebx ? ebx what does || means ? |
|||
10 Jan 2006, 03:47 |
|
okasvi 10 Jan 2006, 03:53
|| = | = OR
&& = & = AND atleast in mIRC scripting || = OR _________________ When We Ride On Our Enemies support reverse smileys |: |
|||
10 Jan 2006, 03:53 |
|
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 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. |
|||
10 Jan 2006, 05:23 |
|
alorent 10 Jan 2006, 06:47
Thanks guys!
Tomasz, can't wait to see that new macro in action! 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 Well, at least from my experience, which has been a many hell years programming in assembly 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 |
|||
10 Jan 2006, 06:47 |
|
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 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. Well, the label naming and some code conventions do help, anyway... |
|||
10 Jan 2006, 15:21 |
|
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 * 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. |
|||
10 Jan 2006, 16:53 |
|
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; 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". PS: Tomasz, comments are always useful, try to add some in sources. Just some hints, maybe put some empty lines between some pair of instructions, so special operations can be separated from each other? |
|||
10 Jan 2006, 18:42 |
|
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" 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 Anyway, I think all is a matter of getting used to something I just was used to cmp/jmp and IF/ELSE/END and I prefer the last one Thanks. |
|||
10 Jan 2006, 21:05 |
|
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 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. |
|||
10 Jan 2006, 21:47 |
|
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 Thanks. |
|||
10 Jan 2006, 22:44 |
|
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
Last edited by Tomasz Grysztar on 15 Jan 2006, 17:23; edited 1 time in total |
|||||||||||
11 Jan 2006, 20:54 |
|
shism2 11 Jan 2006, 21:33
is there a possibilty of you adding author ( asmgges ) hll .on macros ?
|
|||
11 Jan 2006, 21:33 |
|
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. |
|||
11 Jan 2006, 22:21 |
|
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?
|
|||
11 Jan 2006, 22:25 |
|
alorent 11 Jan 2006, 23:06
Hello Tomasz,
I'm using version 1.65.5. Is this OK? Thanks. |
|||
11 Jan 2006, 23:06 |
|
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). |
|||
11 Jan 2006, 23:14 |
|
alorent 11 Jan 2006, 23:29
Hello Tomasz,
Sorry, I had a big disorder in my include files Anyway, trying with this example fails: include 'if.inc' .if byte [esi] = '5' .endif Is that syntax OK to check to char('5')? Thanks |
|||
11 Jan 2006, 23:29 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.