The MASM Forum

Projects => MASM32 => Topic started by: jj2007 on December 16, 2013, 09:18:17 PM

Title: exit macro shows inconsistent behaviour
Post by: jj2007 on December 16, 2013, 09:18:17 PM
include \masm32\include\masm32rt.inc

if 0        ; MasmBasic redefinition of the Masm32 macro (this is not the Exit (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1010) macro!)
        exit macro optional_return_value:=<0>
              invoke ExitProcess, optional_return_value        ; works correctly
        ENDM
else
  ; original macro from \Masm32\macros\macros.asm (180016 bytes, 3 Dec 2011)
  ; --------------------------------------------------------
  ; exit macro with an optional return value for ExitProcess
  ; --------------------------------------------------------
    exit MACRO optional_return_value
      IFNDEF optional_return_value
        invoke ExitProcess, 0
      ELSE
        invoke ExitProcess,optional_return_value
      ENDIF
    ENDM
endif

.code
start:
        int 3
        exit         ; push 0
        exit 123     ; push 0
        exit ecx     ; push ecx

end start


Behaviour by assembler:
ML 6.14, 6.15, JWasm:  0, 0, ecx
ML 8.0 ... 10.0:       0, 0, 0 (!)
Title: Re: exit macro shows inconsistent behaviour
Post by: dedndave on December 16, 2013, 09:52:30 PM
exit    MACRO   optional_return_value:=<0>
        INVOKE  ExitProcess,optional_return_value
ENDM
Title: Re: exit macro shows inconsistent behaviour
Post by: jj2007 on December 16, 2013, 11:46:18 PM
Quote from: dedndave on December 16, 2013, 09:52:30 PM
exit    MACRO   optional_return_value:=<0>
        INVOKE  ExitProcess,optional_return_value
ENDM

Yes, that's what I use (see above) in MasmBasic as replacement for the original Masm32 macro, ever since JWasm greeted me the first time with Warning A4248: IF[n]DEF expects a plain symbol as argument: IFNDEF 123

I never use exit, simply because Exit handles some other issues (closing files & libraries etc). I just stumbled over this bug by accident when ExitCode() (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1048) didn't return what I expected.
Title: Re: exit macro shows inconsistent behaviour
Post by: dedndave on December 17, 2013, 12:43:19 AM
you know me - i am far from a macro guru   :P
(i always turn to you and qWord for macros - lol)

but - shouldn't IFNB be used ?

which brings up an interesting point
doesn't qWord have a human name ?
or is he some code-crunching robot ?
Title: Re: exit macro shows inconsistent behaviour
Post by: jj2007 on December 17, 2013, 01:46:03 AM
> but - shouldn't IFNB be used ?
That would indeed work better, but value:=<0> is more elegant.

The problem, by the way, is caused by different "opinions" about what is defined and what's not:
OxPT_Assembler MLv615
NOT defined: <>
NOT defined: <123>   ; a number is never "defined", i.e. it's not a name
defined: <ecx>   ; a register is "defined" for ML 6.14 + 6.15

OxPT_Assembler MLv8
NOT defined: <>
NOT defined: <123>
NOT defined: <ecx>   ; a register is not "defined" for ML 8.0 and higher

OxPT_Assembler JWasm
NOT defined: <>
NOT defined: <123>
NOT defined: <ecx>   ; same for JWasm: a register is not "defined"


Quote from: dedndave on December 17, 2013, 12:43:19 AM
doesn't qWord have a human name ?

In my Masm32 installation, only JWasm recognises qWord as "defined" ::)
Title: Re: exit macro shows inconsistent behaviour
Post by: hutch-- on December 17, 2013, 03:11:30 AM
Interesting,


  ; --------------------------------------------------------
  ; exit macro with an optional return value for ExitProcess
  ; --------------------------------------------------------
    exit MACRO optional_return_value
      IFNDEF optional_return_value
        invoke ExitProcess, 0
      ELSE
        invoke ExitProcess,optional_return_value
      ENDIF
    ENDM


This macro was written for MASM and has been working well for years.
Title: Re: exit macro shows inconsistent behaviour
Post by: dedndave on December 17, 2013, 04:18:00 AM
it terminates the program
but how often do we really examine the exit code ?
it went unnoticed because it hasn't been "fully" tested with newer versions of masm
i can see how it's hard to devise a 100% test, everytime something changes
Title: Re: exit macro shows inconsistent behaviour
Post by: jj2007 on December 17, 2013, 05:49:16 AM
Quote from: hutch-- on December 17, 2013, 03:11:30 AM
This macro was written for MASM and has been working well for years.

One reason may be that the most frequently used parameter is "defined":

exit msg.wParam  ; works as expected for all assemblers