The MASM Forum

General => The Laboratory => Topic started by: jj2007 on December 31, 2015, 03:45:44 AM

Title: *test & x* Bug in JWasm and AsmC
Post by: jj2007 on December 31, 2015, 03:45:44 AM
include \masm32\include\masm32rt.inc

.code
start:
  push 2

  test byte ptr [esp], 2
  .if !Zero?
print "& 2 set", 13, 10
  .else
print "& 2 not set", 13, 10
  .endif
  test byte ptr [esp], 2
  .if Zero?
print "& 2 not set", 13, 10, 10
  .else
print "& 2 set", 13, 10, 10
  .endif

  .if byte ptr [esp] & 2
print "& 2 set", 13, 10
  .else
print "& 2 not set", 13, 10
  .endif
  .if !byte ptr [esp] & 2
print "& 2 not set", 13, 10
  .else
print "& 2 set", 13, 10
  .endif
  .if !(byte ptr [esp] & 2)
print "& 2 not set", 13, 10, 10
  .else
print "& 2 set", 13, 10, 10
  .endif

  pop ebx

  .if bl & 2
print "& 2 set", 13, 10
  .else
print "& 2 not set", 13, 10
  .endif
  .if !bl & 2
print "& 2 not set", 13, 10
  .else
print "& 2 set", 13, 10
  .endif
  .if !(bl & 2)
print "& 2 not set", 13, 10
  .else
print "& 2 set", 13, 10
  .endif
 
  exit

end start


Output:
JWasm + AsmC:
8*set

ML 6.14 ... 10.0:
2*set/set, not set, set/set, not set, set
Title: Re: *test & x* Bug in JWasm and AsmC
Post by: HSE on December 31, 2015, 12:48:27 PM
Hi jj!

You are right. Perhaps Habran know the problem because he make some flags additions (there is a note in the JWAsm v2.13 source code).

I don't have used ZERO? in any project, and I suspect, Japhet either.

Regards. HSE
Title: Re: *test & x* Bug in JWasm and AsmC
Post by: jj2007 on December 31, 2015, 12:53:17 PM
Quote from: HSE on December 31, 2015, 12:48:27 PMI don't have used ZERO? in any project, and I suspect, Japhet either.

Zero? works fine, it is the bitwise testing in .if !something & 4 that is broken; and only in the negated form without brackets. Fortunately, I had used that only once in 20k lines of code 8)
Title: Re: *test & x* Bug in JWasm and AsmC
Post by: TouEnMasm on December 31, 2015, 07:30:32 PM
I don't get the same result
Intel(R) Core(TM) i3-4150 CPU @ 3.50GHz
Microsoft Windows 10 Famille Version: 10.0.10586
JWasm v2.13, Sep 17 2015  (Compiled by myself VS2015 Windows 10 64 bits version)

Quote
& 2 set
& 2 set

& 2 set
& 2 set
& 2 set

& 2 set
& 2 set
& 2 set


push 2

  test byte ptr [esp], 2
  .if !Zero?
invoke printf_s,TXT("& 2 set", 13, 10)
  .else
invoke printf_s,TXT("& 2 not set", 13, 10)
  .endif
  test byte ptr [esp], 2
  .if Zero?
invoke printf_s,TXT("& 2 not set", 13, 10, 10)
  .else
invoke printf_s,TXT("& 2 set", 13, 10, 10)
  .endif

  .if byte ptr [esp] & 2
invoke printf_s,TXT("& 2 set", 13, 10)
  .else
invoke printf_s,TXT("& 2 not set", 13, 10)
  .endif
  .if !byte ptr [esp] & 2
invoke printf_s,TXT("& 2 not set", 13, 10)
  .else
invoke printf_s,TXT("& 2 set", 13, 10)
  .endif
  .if !(byte ptr [esp] & 2)
invoke printf_s,TXT("& 2 not set", 13, 10, 10)
  .else
invoke printf_s,TXT("& 2 set", 13, 10, 10)
  .endif

  pop ebx

  .if bl & 2
invoke printf_s,TXT("& 2 set", 13, 10)
  .else
invoke printf_s,TXT("& 2 not set", 13, 10)
  .endif
  .if !bl & 2
invoke printf_s,TXT("& 2 not set", 13, 10)
  .else
invoke printf_s,TXT("& 2 set", 13, 10)
  .endif
  .if !(bl & 2)
invoke printf_s,TXT("& 2 not set", 13, 10)
  .else
invoke printf_s,TXT("& 2 set", 13, 10)
  .endif
Title: Re: *test & x* Bug in JWasm and AsmC
Post by: jj2007 on December 31, 2015, 10:11:23 PM
Quote from: ToutEnMasm on December 31, 2015, 07:30:32 PM
I don't get the same result

If you really tried with different assemblers, why did you post only one executable? It should be one for ML and one for JWasm or AsmC.

Btw your code doesn't assemble, fatal error A1000: cannot open file : sdk32.inc
And of course, your exe doesn't run, because it requires an exotic DLL that is not present on my Win7-64 installation.

Title: Re: *test & x* Bug in JWasm and AsmC
Post by: TWell on December 31, 2015, 11:10:43 PM
.386
.model flat,c
option casemap :none

TXT MACRO your_text:VARARG
    LOCAL text_string
    .data
     text_string db your_text,0
    .code
    EXITM <addr text_string>
ENDM

printf proto c args:vararg
_getch proto c
exit proto c :dword
includelib msvcrt.lib

.code

main PROC C argc:DWORD,pargv:DWORD
;---- code here --------
push 2

  test byte ptr [esp], 2
  .if !Zero?
invoke printf,TXT("& 2 set", 13, 10)
  .else
invoke printf,TXT("& 2 not set", 13, 10)
  .endif
  test byte ptr [esp], 2
  .if Zero?
invoke printf,TXT("& 2 not set", 13, 10, 10)
  .else
invoke printf,TXT("& 2 set", 13, 10, 10)
  .endif

  .if byte ptr [esp] & 2
invoke printf,TXT("& 2 set", 13, 10)
  .else
invoke printf,TXT("& 2 not set", 13, 10)
  .endif
  .if !byte ptr [esp] & 2
invoke printf,TXT("& 2 not set", 13, 10)
  .else
invoke printf,TXT("& 2 set", 13, 10)
  .endif
  .if !(byte ptr [esp] & 2)
invoke printf,TXT("& 2 not set", 13, 10, 10)
  .else
invoke printf,TXT("& 2 set", 13, 10, 10)
  .endif

  pop ebx

  .if bl & 2
invoke printf,TXT("& 2 set", 13, 10)
  .else
invoke printf,TXT("& 2 not set", 13, 10)
  .endif
  .if !bl & 2
invoke printf,TXT("& 2 not set", 13, 10)
  .else
invoke printf,TXT("& 2 set", 13, 10)
  .endif
  .if !(bl & 2)
invoke printf,TXT("& 2 not set", 13, 10)
  .else
invoke printf,TXT("& 2 set", 13, 10)
  .endif
 
invoke _getch
invoke exit,0
main endp
end main
& 2 set
& 2 set

& 2 set
& 2 set
& 2 set

& 2 set
& 2 set
& 2 set
Title: Re: *test & x* Bug in JWasm and AsmC
Post by: jj2007 on December 31, 2015, 11:47:27 PM
Tim,

You don't specify whether your exe was build with ML or with JWasm/AsmC. The whole point of this thread is that different assemblers produce different code.

Build it again with ML to see the difference.
Title: Re: *test & x* Bug in JWasm and AsmC
Post by: TWell on January 01, 2016, 12:22:59 AM
Microsoft (R) Macro Assembler Version 12.00.21005.1
& 2 set
& 2 set

& 2 set
& 2 not set
& 2 set

& 2 set
& 2 not set
& 2 set

Microsoft (R) Macro Assembler Version 14.00.23419.0
& 2 set
& 2 set

& 2 set
& 2 not set
& 2 set

& 2 set
& 2 not set
& 2 set

JWasm v2.12pre, Nov 27 2013, Masm-compatible assembler.
& 2 set
& 2 set

& 2 set
& 2 set
& 2 set

& 2 set
& 2 set
& 2 set

Pelles Macro Assembler, Version 8.00.1
& 2 set
& 2 set

& 2 set
& 2 set
& 2 set

& 2 set
& 2 set
& 2 set
Title: Re: *test & x* Bug in JWasm and AsmC
Post by: HSE on January 01, 2016, 02:42:27 AM
There is no problem with ZERO? or !ZERO?

The difference is that ML ignore "!" when you are using "&" without parenthesis

JWAsm, AsmC and POAsm are correct.

Notes (JJ code):

include \masm32\include\masm32rt.inc

.code
start:
  push 2
                                            ;ML     JWASM
  test byte ptr [esp], 2                    ;   test byte ptr ss:[esp],2    BOTH
  .if !ZERO?                                ;je     je
print "& 2 set", 13, 10
  .else
print "& 2 not set", 13, 10
  .endif
  test byte ptr [esp], 2                   
  .if ZERO?                                 ;jne    jne
print "& 2 not set", 13, 10, 10
  .else
print "& 2 set", 13, 10, 10
  .endif
                                            ;   test byte ptr ss:[esp],2    BOTH
  .if byte ptr [esp] & 2                    ; je      je
print "& 2 set", 13, 10
  .else
print "& 2 not set", 13, 10
  .endif
  .if !byte ptr [esp] & 2                   ; je      jne
print "& 2 not set", 13, 10
  .else
print "& 2 set", 13, 10
  .endif
  .if !(byte ptr [esp] & 2)                 ; jne      jne
print "& 2 not set", 13, 10, 10
  .else
print "& 2 set", 13, 10, 10
  .endif

  pop ebx
                                            ;   test bl,2   BOTH
  .if bl & 2
print "& 2 set", 13, 10              ; je      je
  .else
print "& 2 not set", 13, 10
  .endif
  .if !bl & 2                               ; je      jne
print "& 2 not set", 13, 10
  .else
print "& 2 set", 13, 10
  .endif
  .if !(bl & 2)                             ; jne   jne       
print "& 2 not set", 13, 10
  .else
print "& 2 set", 13, 10
  .endif
 
  exit

end start


I'm using the X32dbg (from X64dbg package), apparently very related to OllyDbg
Title: Re: *test & x* Bug in JWasm and AsmC
Post by: jj2007 on January 01, 2016, 03:01:04 AM
Quote from: HSE on January 01, 2016, 02:42:27 AM
There is no problem with ZERO? or !ZERO?

Indeed.

QuoteThe difference is that ML ignore "!" when you are using "&" without parenthesis

JWAsm, AsmC and POAsm are correct

This is the interesting question:

.if !somevar & 2

Let's use eax as somevar:
  mov eax, 2
  not eax   ; not is the meaning of the exclamation mark; eax is now -3
  and eax, 2

So what is -3 and 2?

ZERO.
Title: Re: *test & x* Bug in JWasm and AsmC
Post by: HSE on January 01, 2016, 03:57:26 AM
Your logic sounds fantastic!  :biggrin:

But the expression isn't a logical equation, is an instruction for "if .. endif".
                                                                                      (control-flow directive is the name)
"&" means ","
"!" means "jump if not equal"
Title: Re: *test & x* Bug in JWasm and AsmC
Post by: jj2007 on May 06, 2016, 07:43:39 AM
Attached source causes an exception in AsmC. Sorry, it's a confused source, and needs the attached beta, but attempts to isolate the problem were not successful :(

Endsw_ MACRO tmodeX:=<auto>
LOCAL is, tmp$, cases, curCase, ctCase, ctImm, c$, swa$, cL$, cR$, lbl$, tmode, tmodeCt, MbSwMin, MbSwMax
  retn
  @CatStr(<swa$ equ !<swArg$!>>, %MbSct)      ; causes exception with AsmC
;   @CatStr(<swa$ equ swArg$>, %MbSct)
  @CatStr(<swEnd>, %MbSct, <:>)


CPU Disasm
Address              Hex dump               Command                            Comments
0043091B             À.  C2 0800            retn 8
0043091E                 00                 db 00
0043091F                 00                 db 00
00430920             Ú$  57                 push edi                           ; asmc.00430920(guessed Arg1,Arg2)
00430921             ³.  52                 push edx
00430922             ³.  8B4C24 10          mov ecx, [arg2]
00430926             ³.  8B7C24 0C          mov edi, [arg1]
0043092A             ³. EB 05              jmp short 00430931
0043092C             ³>  8907               Úmov [edi], eax
0043092E             ³.  83C7 04            ³add edi, 4
00430931             ³>  8B01               +mov eax, [ecx]  <<<<<<<<<<< exception: ecx is zero #########
00430933             ³.  83C1 04            ³add ecx, 4
00430936             ³.  8D90 FFFEFEFE      ³lea edx, [eax+FEFEFEFF]
0043093C             ³.  F7D0               ³not eax
0043093E             ³.  23D0               ³and edx, eax
00430940             ³.  F7D0               ³not eax
00430942             ³.  81E2 80808080      ³and edx, 80808080
00430948             ³. 74 E2              Àjz short 0043092C
0043094A             ³.  8807               mov [edi], al
0043094C             ³.  84C0               test al, al
0043094E             ³. 74 14              jz short 00430964
00430950             ³.  8867 01            mov [edi+1], ah
00430953             ³.  84E4               test ah, ah
00430955             ³. 74 0D              jz short 00430964
00430957             ³.  C1E8 10            shr eax, 10
0043095A             ³.  8847 02            mov [edi+2], al
0043095D             ³.  84C0               test al, al
0043095F             ³. 74 03              jz short 00430964
00430961             ³.  8867 03            mov [edi+3], ah
00430964             ³>  5A                 pop edx
00430965             ³.  5F                 pop edi
00430966             ³.  8B4424 04          mov eax, [arg1]
0043096A             À.  C2 0800            retn 8
Title: Re: *test & x* Bug in JWasm and AsmC
Post by: nidud on May 06, 2016, 08:12:44 AM
deleted
Title: Re: *test & x* Bug in JWasm and AsmC
Post by: jj2007 on May 06, 2016, 09:31:44 AM
Actually, this was buggy code, too, the final Switch_ macro is now included here (http://masm32.com/board/index.php?topic=94.msg57249#msg57249). But I wanted to flag it anyway, because one doesn't expect an access violation from an assembler.

wrong:
@CatStr(<swa$ equ !<swArg$!>>, %MbSct)

right:
@CatStr(<swa$ equ !<swArg$>, %MbSct, !>)
Title: Re: *test & x* Bug in JWasm and AsmC
Post by: nidud on May 06, 2016, 09:48:32 AM
deleted
Title: Re: *test & x* Bug in JWasm and AsmC
Post by: nidud on May 09, 2016, 10:16:22 AM
deleted
Title: Re: *test & x* Bug in JWasm and AsmC
Post by: jj2007 on May 09, 2016, 10:55:18 AM
it doesn't like OPTION CSTACK:0 in MasmBasic.inc, line 221
if I comment that out, it stumbles frequently over Mirror$() with error typedef

will check tomorrow...
Title: Re: *test & x* Bug in JWasm and AsmC
Post by: jj2007 on May 09, 2016, 10:38:15 PM
Quote from: nidud on May 09, 2016, 10:16:22 AMI removed the auto-off switch for the C/macro parsing. This means that MasmBasic now will be assembled with all extensions of ASMC.

I got another weird one:

error A2190: INVOKE requires prototype for procedure

ExternDef MbFH:DWORD
invoke SetFileTime, MbFH(4*10), edi, edi, edi


It works with
- eax instead of MbFH()
- MbFH[4*10] instead of MbFH(4*10)

Btw is there any consensus on the use of round vs square brackets here? My checks show that ML and AsmC use the same encoding for both; but for me the round brackets look a bit wrong ::)
Title: Re: *test & x* Bug in JWasm and AsmC
Post by: nidud on May 10, 2016, 01:23:35 AM
deleted