Author Topic: exit macro shows inconsistent behaviour  (Read 5862 times)

jj2007

  • Member
  • *****
  • Posts: 10548
  • Assembler is fun ;-)
    • MasmBasic
exit macro shows inconsistent behaviour
« 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 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 (!)

dedndave

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: exit macro shows inconsistent behaviour
« Reply #1 on: December 16, 2013, 09:52:30 PM »
Code: [Select]
exit    MACRO   optional_return_value:=<0>
        INVOKE  ExitProcess,optional_return_value
ENDM

jj2007

  • Member
  • *****
  • Posts: 10548
  • Assembler is fun ;-)
    • MasmBasic
Re: exit macro shows inconsistent behaviour
« Reply #2 on: December 16, 2013, 11:46:18 PM »
Code: [Select]
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() didn't return what I expected.

dedndave

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: exit macro shows inconsistent behaviour
« Reply #3 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 ?

jj2007

  • Member
  • *****
  • Posts: 10548
  • Assembler is fun ;-)
    • MasmBasic
Re: exit macro shows inconsistent behaviour
« Reply #4 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"


doesn't qWord have a human name ?

In my Masm32 installation, only JWasm recognises qWord as "defined" ::)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7544
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: exit macro shows inconsistent behaviour
« Reply #5 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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

dedndave

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: exit macro shows inconsistent behaviour
« Reply #6 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

jj2007

  • Member
  • *****
  • Posts: 10548
  • Assembler is fun ;-)
    • MasmBasic
Re: exit macro shows inconsistent behaviour
« Reply #7 on: December 17, 2013, 05:49:16 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