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

mitchi

But then if someone doesn't care about runtime conditionals and is happy with cmp/jumps, He will never see the syntax confusion between #IF and IF (or .IF).

wjr

Although somewhat easier to stick with the more familiar syntax, as for another idea along the above lines of combining the two into something new, the shortest simplest syntax I can come with is COND/ON/ENDC (or possibly DO instead of ON, also no BREAK, implied with the switch-like functionality):


WndProc FRAME hWnd, uMsg, wParam, lParam
COND uMsg
ON  WM_PAINT
    ;code to achieve paint
ON  WM_CREATE
    ;code to achieve create
    COND eax>3
        ;code if >3
    ON eax>1
        ;code if >1
    ON
        ;other/default
    ENDC
ON
    ;other/default
ENDC
RET
ENDF

jorgon

A lovely bit of lateral thinking, Wayne.

Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

BlackVortex

#48
Switch and Cond seem cool, but isn't .If more powerful ? Because the coder can specify different expressions in each comparison ?

EDIT: OK, I'm trying to migrate a project from masm to Goasm and I'm looking at a huge nested IF structure, I give up ...  :toothy

jorgon

I have a question for all those runtime conditionals fans!

For the sake of argument, if GoAsm were to provide a SWITCH/CASE facility, how would the high and low message components in the COMMAND and NOTIFY messages best be handled?

For example,

WndProc FRAME hWnd, uMsg, wParam, lParam
SWITCH uMsg
CASE WM_COMMAND
     SWITCH lParam          ;switch the handle of thing sending message
     CASE 0                 ;do next if message is from a menu (zero)
     MOV EAX,[wParam]
           SWITCH AX        ;switch low word of wParam
           CASE MENU_1
                    ----- code to deal with menu click with id of ID MENU_1
           RET
           CASE MENU_2
                    ----- code to deal with menu click with id of ID MENU_2
           RET
           CASE             ;or DEFAULT (menu selection not recognised)
           XOR EAX,EAX      ;return zero
           RET
           ENDSWITCH
     CASE                   ;or DEFAULT (message is not from a menu, but from a control)
     MOV EAX,[wParam]
     SHR EAX,16             ;get hiword (get the control's command)
           SWITCH EAX       ;or AX (switch the command)
           CASE BN_CLICKED
                    ----- code to deal with button clicked
           RET
           CASE BN_DBCLK
                    ----- code to deal with button double clicked
           RET
           CASE             ;or DEFAULT (control command not recognised)
           XOR EAX,EAX      ;return zero
           RET
           ENDSWITCH
    ENDSWITCH
CASE WM_CREATE
     XOR EAX,EAX
     RET
ENDSWITCH
RET
ENDF


Alternatively ..

WndProc FRAME hWnd, uMsg, wParam, lParam
SWITCH [uMsg]
CASE WM COMMAND
     SWITCH [lParam]             ;switch the handle of thing sending message
     CASE 0                      ;do next if message is from a menu (zero)
           SWITCH LW[wParam]     ;switch low word of wParam
           CASE MENU_1
                    ----- code to deal with menu click with id of ID MENU_1
           RET
           CASE MENU_2
                    ----- code to deal with menu click with id of ID MENU_2
           RET
           CASE                  ;or DEFAULT (menu selection not recognised)
           XOR EAX,EAX           ;return zero
           RET
           ENDSWITCH
     CASE                        ;or DEFAULT (message is not from a menu, but from a control)
           SWITCH HW[wParam]     ;switch the command in the high-word of wParam
           CASE BN_CLICKED
                    ----- code to deal with button clicked
           RET
           CASE BN_DBCLK
                    ----- code to deal with button double clicked
           RET
           CASE                  ;or DEFAULT (control command not recognised)
           XOR EAX,EAX           ;return zero
           RET
           ENDSWITCH
    ENDSWITCH
CASE WM_CREATE
     XOR EAX,EAX
     RET
ENDSWITCH
RET
ENDF


In the above, the default switch size is a dword, and the "switch" reference to memory/local param/local data must be in square brackets to provide somewhere to put the switch size, and which also indicates in GoAsm syntax that it is being read from memory.


Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

BlackVortex

I think the first is better/simpler. Comparisons against high/low parts of parameters are too rare to make it so complex, right ? But both look cool.

:green2

Mark Jones

The first does look simpler, but the second is far more powerful! Great idea Jeremy. In WndProcs, it is almost always necessary to split the hiword and loword, so this may not be all that uncommon in practice.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Ramon Sala

I vote for the second! Looks very well!

Ramon
Greetings from Catalonia

mitchi


donkey

I like the second one as well.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

PauloH

I vote for the second. It would help C programmers to look at assembler language with more familiar eyes.

Paulo H.

GregL


jorgon

Oh thanks for the responses. 
Actually I've got an even better suggestion ..

WndProc FRAME hWnd, uMsg, wParam, lParam
SWITCH [uMsg]
CASE WM COMMAND
     SWITCH [lParam]             ;switch the handle of thing sending message
     CASE 0                      ;do next if message is from a menu (zero)
           SWITCH W[wParam]      ;switch low word of wParam
           CASE MENU_1
                    ----- code to deal with menu click with id of ID MENU_1
           RET
           CASE MENU_2
                    ----- code to deal with menu click with id of ID MENU_2
           RET
           CASE                  ;or DEFAULT (menu selection not recognised)
           XOR EAX,EAX           ;return zero
           RET
           ENDSWITCH
     CASE                        ;or DEFAULT (message is not from a menu, but from a control)
           SWITCH W[wParam+2]    ;switch the command in the high-word of wParam
           CASE BN_CLICKED
                    ----- code to deal with button clicked
           RET
           CASE BN_DBCLK
                    ----- code to deal with button double clicked
           RET
           CASE                  ;or DEFAULT (control command not recognised)
           XOR EAX,EAX           ;return zero
           RET
           ENDSWITCH
    ENDSWITCH
CASE WM_CREATE
     XOR EAX,EAX
     RET
ENDSWITCH
RET
ENDF


This has the advantage of not introducing a new "type" and the +2 as addressing the high word would be obvious to assembler programmers.


Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

mitchi


Mark Jones

That works too, this latest variant may seem a little unfamiliar to newcomers, but fits right in with the established GoASM syntax.

About the only thing I can think of at the moment would be to detect if a previous CASE statement has been followed (and if it has, break out), saving the RET in each branch.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08