News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Runtime conditionals

Started by donkey, March 24, 2009, 11:15:42 AM

Previous topic - Next topic

jj2007

Quote from: wjr on May 26, 2009, 12:09:56 AM
instead of the longer ELSEIF expecting a full expression, how about also having a shorter ELIF with just a VALUE, compared as in the initial IF (or possible previous longer ELSEIF):

Masm doesn't distinguish between full expressions and "just a value":

.if eax==123
print chr$("Masm32 is simpler than you thought, right?"), 13, 10
.elseif WM_COMMAND
print chr$("Yeah, that's true ;-", 41), 13, 10
.endif

BlackVortex

Any progress ?

I have wet dreams about win7 64bit + 64bit programming + runtime conditionals

Yusuf

Hoping this gets implemented soon, trying to further my learning after the Bill Aitken's tutorials and am having trouble with tutorials that use conditionals so am stalling til than.

Synfire

I know I've been away for a while, mostly due to school but also because the bulk of my work lately has been centered around GNU/Linux. As most of you might remember I've never really been a fan of the if/endif style coding myself (even though NASM32 has always supported it). But what I think would be much more interesting for GoASM in the line of a conditional system would be a built-in wrapper for call-table comparison using SWITCH/CASE or SELECT/OPTION. For example:

SELECT [uMsg]
OPTION WM_CREATE, OnCreate
OPTION WM_PAINT, OnPaint
OPTION WM_CHAR, OnChar
DEFAULT OnUnknown
ENDSELECT
...
OnCreate:
...
OnPaint:
...
OnChar:
...
OnUnknown:
...


Then have it expand to something like this:

CONST SECTION
GENERATED_TABLE_NAME:
DD WM_CREATE, OnCreate
DD WM_PAINT, OnPaint
DD WM_CHAR, OnChar

CODE SECTION
PUSH Eax, Ecx, Edx
MOV Eax, [uMsg]
MOV Ecx, SIZEOF GENERATED_TABLE_NAME / 8
MOV Edx, ADDR GENERATED_TABLE_NAME
:
DEC Ecx
JS >
CMP [Edx + Ecx * 8], Eax
JNE <
CALL [Edx + Ecx * 8 + 4]
JNC >.TEMP_ENDSWITCH
:
CALL OnUnknown
.TEMP_ENDSWITCH:
POP Edx, Ecx, Eax
...
OnCreate:
...
OnPaint:
...
OnChar:
...
OnUnknown:
...


I used the generic WM_* handler in the above example, but I actually use this style of call-table comparison a lot since it expands better to larger numbers of comparisons than your basic CMP/Jcc. For simple If/Else/Endif is it really so hard to use CMP/Jcc style comparisons? I personally think if you were to create an internal directive for doing comparison's it should probably be something like the above where the user of the directive is likely to be preforming a mass number of comparisons and the directives would not only increase basic readability but improve the output code performance. That's just my two cents. :)

Regards,
Bryant Keller

Yuri

Quote from: Yusuf on July 25, 2009, 10:48:42 PM
Hoping this gets implemented soon, trying to further my learning after the Bill Aitken's tutorials and am having trouble with tutorials that use conditionals so am stalling til than.
From my own experience, I confirm that the lack of if/else is a real difficulty at first. But later you find the way to do without, and now I am rather reluctant to use them (to my own surprise).

I personally would recommend to start learning assembly without all those obfuscating facilities, even only to understand how all this is done in reality, what actually is behind ifs and elses.

BlackVortex

I always disassemble my exes to see how the runtime conditionals (in masm), the frames/procs, the invokes etc get implemented. Also, I like looking at the imports, the header and linker-related stuff.

dedndave

i only use conditionals for library functions
i used to use them so code could be assembled for different memory models
well - don't need that anymore with 32-bit code - lol
i have a hard time reading some code because of all the if thens
it looks too much like a C program, which is something i try to avoid
when you write it yourself, you get to choose how it is structured so that
the cases that occur most often go through the least amount of branching

BlackVortex

Quote from: dedndave on July 26, 2009, 11:53:24 PM
i have a hard time reading some code because of all the if thens
it looks too much like a C program
Errm ? It doesn't look like C, it looks like Masm, you know, the macro assembler ! :wink


cmp,test and jcc look like disassembly   :bdg 

dedndave

lol - it's cool - i work my way through it
usually, i only need to understand a small portion, and i only need it once
i am just old-school (i think that means the same as stubborn, right ?)
i think we all tend to resist change and our preference leans toward the first-learned
well, at least i am not writing ML code in hex - lol

jj2007

Quote from: BlackVortex on July 28, 2009, 01:16:24 PM
Quote from: dedndave on July 26, 2009, 11:53:24 PM
i have a hard time reading some code because of all the if thens
it looks too much like a C program
Errm ? It doesn't look like C, it looks like Masm, you know, the macro assembler ! :wink

Can't help it but to me all this if/else and while and repeat and switch/case stuff looks like good ol' BASIC ::)

dedndave

lol - i remember Basic - - - version 3 i think i had
i still have ms basic compiler v 1.0 in the drawer - lol
this machine has no floppy drives - dang
hafta fire up one of my old machines
i don't even know wth you are talking about with "switch/case stuff"  :lol

jj2007

Quote from: dedndave on July 28, 2009, 03:18:24 PM
i don't even know wth you are talking about with "switch/case stuff"  :lol

Masm:
SWITCH uMsg
CASE WM_COMMAND
  mov ecx, lParam
CASE WM_WINDOWPOSCHANGED
  mov ecx, 123
ENDSW

GfaBasic:
      SWITCH MENU(0)
      CASE 1001
        DoStuff
      CASE whatever
        DoOtherStuff
      ENDSWITCH

dedndave

it looks like Greek, to me, bro  :eek
must have something to do with cases - lol

MichaelW

eschew obfuscation

jj2007

Quote from: MichaelW on July 28, 2009, 06:47:59 PM
http://en.wikipedia.org/wiki/Switch_statement

Strange how many times they have to repeat that language X does not "support" fall-through behaviour. It would have been easier to say that only a handful of C dialects are infected with this horrible disease...