News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

*test & x* Bug in JWasm and AsmC

Started by jj2007, December 31, 2015, 03:45:44 AM

Previous topic - Next topic

jj2007

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

HSE

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
Equations in Assembly: SmplMath

jj2007

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)

TouEnMasm

#3
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
Fa is a musical note to play with CL

jj2007

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.


TWell

.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

jj2007

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.

TWell

#7
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

HSE

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
Equations in Assembly: SmplMath

jj2007

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.

HSE

#10
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"
Equations in Assembly: SmplMath

jj2007

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

nidud

#12
deleted

jj2007

Actually, this was buggy code, too, the final Switch_ macro is now included here. 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, !>)

nidud

#14
deleted