The MASM Forum

64 bit assembler => 64 bit assembler. Conceptual Issues => Topic started by: ragdog on January 13, 2017, 05:11:55 AM

Title: Ml64 If/else problem
Post by: ragdog on January 13, 2017, 05:11:55 AM
Hello all

Have the Masm64 (ml64) a problem with the If/else statement?

error A2052:forced error : Bad conditional operator.

.if (rax !=   INVALID_HANDLE_VALUE)

Greets,
Title: Re: Ml64 If/else problem
Post by: Vortex on January 13, 2017, 05:23:18 AM
Hi ragdog,

Reading \masm32\macros64\vasily.inc :

     Operator      Meaning

     ==            Equal
     {}            Not equal
     }             Greater than
     }=            Greater than or equal to
     {             Less than
     {=            Less than or equal to
     &             Bit test (format: expression & bitnumber)
     ~             Logical NOT
     |          Bit test
     &&            Logical AND

     ||            Logical OR


.if (rax {} INVALID_HANDLE_VALUE)
Title: Re: Ml64 If/else problem
Post by: ragdog on January 13, 2017, 05:48:15 AM
Thank you Vortex

What is this for skurril new If/else statments and Operator ?
I think i will be not a friend of Masm64 with ML64.

I love the old syntax like Masm32 .

Greets,
Title: Re: Ml64 If/else problem
Post by: Vortex on January 13, 2017, 06:28:00 AM
Hi ragdog,

Vasily had to implement those macros while creating the HLL constructs for ml64 if I am not wrong.
Title: Re: Ml64 If/else problem
Post by: ragdog on January 13, 2017, 06:37:56 AM
Correct

But i have think i can use ml64 without the extern If/else macos from Vasily

Know read i

QuoteML64 doesn't support high level language constructs

Or Invoke macro.

Ml64 is for the Cat  :icon_eek:
Title: Re: Ml64 If/else problem
Post by: hutch-- on January 13, 2017, 09:21:21 AM
ML64 comes unconfigured and it required macros to make it usable for general purpose coding. The work I have done so far includes a stack frame macro and an invoke macro, both of which work correctly. The runtime comparison code that Vasily wrote had to substitute "{" for "<" and "}" for ">" because ML64 does not allow the use of < > in macro code. I have been using Vasily's runtime comparison code for some time now and it all works fine.

In the MACRO file that is done so far, the .switch macro originally written by Greg Falen works fine. Have a look at the most recent help file I have posted for the details of how the stack frame and invoke work.
Title: Re: Ml64 If/else problem
Post by: ragdog on January 13, 2017, 08:32:59 PM
Hello Hutch

Yes it works your Masm64 with macros,but i use in Masm32 the  HLL constructs (Operator)

I'm not a friend of .switch macro

Ok ml64 support not the HLL constructs but is not usefull to change the Vasily Macros to the old Operator?
like


! ,!= ,& ,&& ,< ,<= ,== ,> ,>= ,|| etc.


To use a brace  ({} Not equal) is not useful.

Following situation:

I have a cpp source or Masm32 all use "! ,!= ,& ,&& ,< ,<= ,== ,> ,>= ,||   etc."
Now i port  this code to Masmx64 ,i must change many code and operator this is not useful.

But I think you know it best.

Regards,
Title: Re: Ml64 If/else problem
Post by: jj2007 on January 13, 2017, 09:07:57 PM
Quote from: ragdog on January 13, 2017, 08:32:59 PMTo use a brace  ({} Not equal) is not useful.

Try a google images search for ugly braces (warning, not for the faint of heart!)
Title: Re: Ml64 If/else problem
Post by: hutch-- on January 14, 2017, 05:47:32 AM
ragdog,

The problem is this, Microsoft do not provide any high level support and 64 bit MASM comes unconfigured but it has a near identical pre-processor which allow much of the high level operators to be emulated in a similar form to the old 32 bit version. 64 bit MASM is simply not compatible with the old 32 bit version and is a lower level assembler so there is no simple porting available. Without the endless prototyping and notation restrictions it is simpler and faster to use but it comes with a few restrictions of its own, one is that the angle brackets < > are treated as notation for structures in the .data .data? sections which excludes them as operators for writing macros.

With the work I have done with 64 bit MASM, it has allowed me to change bits and pieces, fix odd problems here and there which I have not been able to do in the 32 bit version as you don't change a system and break anyone's code that has used it. As far as the curly braces, if you want to use 64 bit MASM and don't want to use them, do your comparisons with normal mnemonics.

You can look at alternative assemblers, FASM is known to be reliable, for Linux GAS is a good tool, JWASM has the notation you want but is a dead project or you can try the Watcom forks of JWASM as they are being developed. POASM is well written and has the support of a very good tool set but very little backup as Pelle is mainly interested in his C compiler and tools.
Title: Re: Ml64 If/else problem
Post by: ragdog on January 14, 2017, 06:31:34 AM
Yes i know Hutch

I test the last days alternative assemblers HJwasm,Posasm, and now Ml64
to find the optimal x64 assembler for me.


Title: Re: Ml64 If/else problem
Post by: hutch-- on January 16, 2017, 03:10:51 AM
Here is a small example of Vasily's alternate run time comparison operators.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    LOCAL var   :QWORD

    mov var, 0

    .if var == 1
      conout "var = 1",lf
    .elseif var } 2
      conout "var is greater than 2",lf
    .else
      conout "Nope, I dunno",lf
    .endif

    .if var { 1 || var } -1
      conout "eureka",lf
    .endif

    waitkey

    invoke ExitProcess,0

    ret

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end


Here is an expanded version.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    LOCAL var   :QWORD

    mov var, 0

  ; --------
  ; IF block
  ; --------
    .if var == 1
      conout "var = 1",lf
    .elseif var } 2
      conout "var is greater than 2",lf
    .else
      conout "Nope, I dunno",lf
    .endif

    .if var { 1 || var } -1
      conout "eureka",lf
    .endif

  ; ------------
  ; switch block
  ; ------------
    .switch var
      .case 0
        conout "You selected 0",lf
      .case 1
        conout "You selected 1",lf
      .case 2
        conout "You selected 2",lf
      .case 3
        conout "You selected 3",lf
      .case 4
        conout "You selected 4",lf
      .case 5
        conout "You selected 5",lf
    .endsw

    waitkey "Loop code, press any key ...."

  ; ---------
  ; loop code
  ; ---------
    mov var, 100

  lpst:
    conout str$(var),lf
    sub var, 1
    jump lpst WHILE var GT 0

    waitkey

    invoke ExitProcess,0

    ret

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end
Title: Re: Ml64 If/else problem
Post by: TouEnMasm on July 14, 2020, 03:16:42 PM

Is it not possible to modify the Vasily.inc to change {} in != and so on.
Title: Re: Ml64 If/else problem
Post by: hutch-- on July 14, 2020, 04:47:35 PM
Vasily's notation also supports an alternative, the second using the logic notation tilde. "~".

    {}             Not equal
    ~=             Not equal        (alternative)

For people who cannot read Vasily's notation. This is a higher level notation that can do memory to memory comparisons.

  HIGH LEVEL .If BLOCK

    .If condition
      ; your code

    .ElseIf condition
      ; your code

    .ElseIf condition
      ; your code

    .Else
      ; your code

    .EndIf

  COMPARISON RUN TIME OPERATORS

    eq      equals
    ne      not equal
    ge      greater than or equal
    gt      greater than
    le      less than or equal
    lt      less than

    The run time operators are the same as the familiar notation used by the MASM pre-processor.
Title: Re: Ml64 If/else problem
Post by: TouEnMasm on July 14, 2020, 06:47:20 PM
 :thumbsup:
but need the sample,the BNF grammar say:
Quote
controlIf
    .IF     cExpr ;;
    directiveList
    ⟦ controlElseif ⟧
    ⟦ .ELSE ;;
    [directiveList⟧
    .ENDIF ;;
the search cExpr give:
Quote
cExpr
    aExpr | cExpr || aExpr


and the compiler say "error syntax"



Title: Re: Ml64 If/else problem
Post by: hutch-- on July 14, 2020, 08:24:31 PM
I have seen this stuff before but Microsoft data for MASM mixes 16, 32 and 64 bit and most of it is not compatible with each other version. I use the 64 bit version completely independently from the old ML.EXE 16 and 32 bit versions and most of its capacity has had to be determined empirically as the documentation is appalling.

RE: The original topic, the 64 bit version does not support the 32 bit version .IF notation so I have used Vasily's version with some wrappers around it. With enough practice the pre-processor in 64 bit MASM can get most things done but its a bit tedious and badly documented as usual.
Title: Re: Ml64 If/else problem
Post by: TouEnMasm on July 14, 2020, 10:25:26 PM
" bit tedious and badly documented as usual."
I agree with that  :toothy:.
As the subject is ML64 bits,I was speaking about ML64.exe .
Too bad,another hope who fall.
Stay,a modify of vasily.inc,must be possible.
Title: Re: Ml64 If/else problem
Post by: TouEnMasm on July 14, 2020, 11:29:17 PM
 :icon_idea:
I modify the vasily.inc so now,he recognize != instead of {}
I have put ECHO to follow the macro path.
I have made two modifies with two comments ;------ToutEnMasm modify -----
You don't need any more include to make it run,ML64 is enough.It's the minimal version that I have always posted + vasily.inc.

---------------------------------------------- LATER ------------------------------------------------------------------
don't work,made an error on }
Bad news,I had no see that the char ! and < aren't view by the ECHO,ALL is lost,must stay as it is,it is better
Title: Re: Ml64 If/else problem
Post by: TouEnMasm on May 09, 2021, 04:52:46 PM
Hello,
Surprise, I refind this post searching in the web.
I take the opportunity to make a hello at microsoft.
The bug is in the title,the sign ! disappear when put in a constant.


include master_ml64.inc
includelib msvcrt.lib
;Microsoft (R) Macro Assembler (x64) Version 14.28.29914.0
;https://docs.microsoft.com/en-us/windows/win32/debug/pe-format
;http://masm32.com/board/index.php?topic=5941.15
;imagehelp.sdk
MessageBox MACRO hWnd:REQ,lpText:REQ,lpCaption:REQ,uType:REQ
IFDEF __UNICODE__
externdef __imp_MessageBoxW:PPROC
invoke __imp_MessageBoxW,hWnd,lpText,lpCaption,uType
ELSE
externdef __imp_MessageBoxA :PPROC
invoke __imp_MessageBoxA,hWnd,lpText,lpCaption,uType
ENDIF
EXITM<>
ENDM

.const

essai TEXTEQU <"bug here-!-'{&#-|([-|`_\ç^à@)]=}²ô$¤!r">
;ASCII printable characters (character code 32-127)
.data
chaineascii db "a",32,"a",33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56
db 57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81
db 82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106
db 107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,0


titre db essai,0
;-------------------
.code
WinMain proc hInst:QWORD,hPrevInst:QWORD,lpCmdLine:QWORD,nShowCmd:DWORD
Local hr:QWORD
MessageBox ( NULL,addr chaineascii,addr titre,MB_OK)
ret
WinMain endp
end
Title: Re: Ml64 If/else problem
Post by: TouEnMasm on May 10, 2021, 01:22:56 AM

Difficult to say if this is a bug or this is because the Hight level Syntax had been deleted from ml64.
The ml 32 Microsoft (R) Macro Assembler Version 14.28.29914.0,show the same thing in the messagebox
but allow !=

;include \masm32\include\
include H:\masm32\include\masm32rt.inc
include H:\masm32\include\windows.inc
includelib user32.lib

;Microsoft (R) Macro Assembler Version 14.28.29914.0
;https://docs.microsoft.com/en-us/windows/win32/debug/pe-format
;http://masm32.com/board/index.php?topic=5941.15

;--------
.const

essai TEXTEQU <"bug here-!-'{&#-|([-|`_\ç^à@)]=}²ô$¤!r">
;ASCII printable characters (character code 32-127)
.data
chaineascii db "a",32,"a",33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56
db 57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81
db 82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106
db 107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,0


titre db essai,0
;-------------------
.code
;WinMain proc hInst:QWORD,hPrevInst:QWORD,lpCmdLine:QWORD,nShowCmd:DWORD
start:
mov eax,1
.if eax != 0           ; HLL and not a normal Macro ?
invoke MessageBox ,NULL,addr chaineascii,addr titre,MB_OK
.endif
;ret
;WinMain endp
end start

Title: Re: Ml64 If/else problem
Post by: jj2007 on May 10, 2021, 06:45:43 AM
include \masm32\include\masm32rt.inc
.code
start:
  tmp$ CATSTR <inkey "** line >, %@Line, <: ever tried to use a string with !<brackets!> ? **">
  % tmp$
  exit
end start


Strangely enough, in this case it works without the escape characters. But I have seen many cases where it didn't.