flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Macro select-case (switch) with comparison table

Author
Thread Post new topic Reply to topic
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode
Hallo all,
<reedited> /an old select/case macro
Example of use:
... read new post


Last edited by hopcode on 01 Sep 2008, 04:56; edited 1 time in total
Post 22 Aug 2008, 10:29
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17287
Location: In your JS exploiting you and your system
revolution
hopcode: Good, but keep in mind that break is already a keyword, so you are overriding it's normal function.

I have to confess I had not realised that the fasm macros in the download didn't have select/case/break/etc. set.
Post 22 Aug 2008, 10:43
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Using macro for "break" or "continue" in assembly is somewhat retarded... "break" and "continue" are HLL substition for most-often used cases of "goto"/"jmp".

Same for doing "case" without jump table in assembly. "case" command is exactly the best example where HLL code has advantage over Asm code - compiler can analyze list of options, and generate ideal code for it (combination of conditional jumps and binary search(es)). There are even specialized tools like "flex", which do nothing else but this. If course you *can* do it in asm, but in practice your code would become unreadable, unmaintainable, etc... so no one really does it.
Post 22 Aug 2008, 14:33
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode
vid wrote:
Using macro for "break" or "continue" in assembly is somewhat retarded... "break" and "continue" are HLL substition for most-often used cases of "goto"/"jmp".Same for doing "case" without jump table in assembly. ...

Thank you vid for your note. I agree totally with you: "break","continue","select","case" are all for HLL. Personally, i dont like them. They can be avoided with no difficulty by coding them manually to get the best code in a short time:
...
mov eax,[wmsg]
cmp eax,WM_CLEAR
jz codeforWM_CLEAR
cmp eax,WM_COMMAND
jz codeforWM_COMMAND
...
But i find the real problem with fasm 1.67 in the building up of the jump table:
1- jump table (or comparison table)
2- code to execute (always forwarded)

Anyway, if i do not err, a switch-case system is already a high level abstraction, it is to say, an abstract construct in relation to the way of assembler coding. In this case other compilers or preprocessor could do their work with their optimization. For this reason i dont like this construct: it is too much "high", too much "interpreted" and interpretable, too much abstract.

I have tried different solutions to build up a jump table. None of them satisfies completely me. In conclusion, what i aimed to was avoiding writing always the same code, particularly for windowprocs. I will put examples later in my Winmacro thread...
...
hopcode
Post 23 Aug 2008, 01:27
View user's profile Send private message Visit poster's website Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode
revolution wrote:
keep in mind that break is already a keyword, so you are overriding it's normal function.

Thank you,revolution, i have totally forgotten the break directive. At the moment i dont know how to use a "break" instruction macro that avoids interference with the break directive. I have found an opportunity in the use of a "continue" instruction instead of "break" (as a matter of fact i have used the "break" instruction as a way to jump to the default block).
I find it useful extending the "continue" instruction as shown in the following example of use :
..little improvements..24.08.2008 but i am not at all convinced Confused )
...


Last edited by hopcode on 01 Sep 2008, 04:57; edited 1 time in total
Post 23 Aug 2008, 01:31
View user's profile Send private message Visit poster's website Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode
Hallo all,
here my definitive solution for a select/case with a comparison table...
version updated [Sonntag] - 07.Juni.2009
now it allows things like:
Post 01 Sep 2008, 04:48
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.