Author Topic: Probable Bug related to opattr  (Read 295 times)

Biterider

  • Member
  • ****
  • Posts: 575
  • ObjAsm Developer
    • ObjAsm
Probable Bug related to opattr
« on: November 02, 2020, 02:17:53 AM »
Hi
I encountered strange behavior while evaluating an expression.
I've compared it to the ML output and while it's different I think it's probably wrong too.  :sad:
The whole thing is related to the syntax opattr(xxx) vs (opattr xxx).
Attached is the test code.

Regards, Biterider

TouEnMasm

  • Member
  • *****
  • Posts: 1502
    • EditMasm
Re: Probable Bug related to opattr
« Reply #1 on: November 02, 2020, 02:40:36 AM »

Sorry but what is wrong ??   ,perhaps the copy of the wrong line could help ?

Fa is a musical note to play with CL

Biterider

  • Member
  • ****
  • Posts: 575
  • ObjAsm Developer
    • ObjAsm
Re: Probable Bug related to opattr
« Reply #2 on: November 02, 2020, 03:29:13 AM »
Hi
The test code evaluates 3 different syntaxes:

Code: [Select]
  Result = OAT_REGISTER and opattr(eax)
  Result = opattr(eax) and OAT_REGISTER
  Result = (opattr eax) and OAT_REGISTER

and returns the result to a log file.
This is done from a batch file that compiles the same asm file for ML and UASM one after the other.
If you look at the contents of the log file you can see that both assembers do not return the same values and are acting a little strange for the 3 syntaxes.

I hope it's a little more understandable now.

Regards, Biterider


jj2007

  • Member
  • *****
  • Posts: 10856
  • Assembler is fun ;-)
    • MasmBasic
Re: Probable Bug related to opattr
« Reply #3 on: November 02, 2020, 04:15:18 AM »
I always use oa=opattr(arg) and 127 to mask out the external label and language bits. Using and 127 the 810 becomes 42, as shown in the image. Attached a batch file that creates two log files configured for Alt Tab switching.

;     Bit       Set If...
;     0         References a code label
;     1         Is a memory expression or has a relocatable data label
;     2         Is an immediate expression
;     3         Uses direct memory addressing, i.e. is an absolute memory reference
;     4         Is a register expression
;     5         References no undefined symbols and is without error
;     6         References a stack location (usually a LOCAL variable or parameter)
;     7         References an external label
;     8-10      Language type (0=no type)
               ; 76543210      ; use and 127 to mask external label and language bits
atMemory        = 34            ;
00100010      ; [edx+20], [ebx+20], [eax+edx+20], JWasm: [eax+4*eax+20], [eax+20]
atImmediate     = 36            ;
00100100
atLabel         = 37            ;
10100101
atOffset        = 38            ;
10100110      ; offset CrLf$ (immediate and mem expression)
atGlobal        = 42            ;
10101010      ; CrLf$, Masm: [eax+4*eax+20], [eax+20]
atRegLabel      = 43            ;
10101011      ; Masm: [eax+start] (Jwasm yields 37)
atRegister      = 48            ;
00110000      ; also xmm
atLocal         = 98            ; 01100010

Biterider

  • Member
  • ****
  • Posts: 575
  • ObjAsm Developer
    • ObjAsm
Re: Probable Bug related to opattr
« Reply #4 on: November 02, 2020, 04:49:46 AM »
Hi JJ
Thank you for your feedback.
As you can see from your evaluation, the values are not the same between assemblers.
Your code lacks the AND operation, which produces different results when you change the order of the operands but only in combination with opattr.
The use of immediate values and their permutations produces the same result (direct test).

Code: [Select]
  Result = OAT_REGISTER and opattr(xxx)
  Result = opattr(xxx) and OAT_REGISTER

At the moment, the only safe syntax seems to be
Code: [Select]
Result = (opattr xxx) and OAT_REGISTER
For more clarity I build a table showing the results

Biterider


_japheth

  • Regular Member
  • *
  • Posts: 25
Re: Probable Bug related to opattr
« Reply #5 on: November 02, 2020, 06:20:01 PM »
The OPATTR operator has a very low precedence, lower than AND, that's why "opattr x and y" may give unexpected results.
The road to hell is paved with good intentions.

HSE

  • Member
  • *****
  • Posts: 1464
  • <AMD>< 7-32>
Re: Probable Bug related to opattr
« Reply #6 on: November 02, 2020, 10:28:11 PM »
The OPATTR operator has a very low precedence, lower than AND, that's why "opattr x and y" may give unexpected results.
Fantastic!

I was forgotten why I use double parenthesis  :biggrin::
Code: [Select]
    IF (OPATTR(tk_dest)) and 00010000y ;; register
         tk_op3 tk_dest , tk_exp
    ELSEIF (OPATTR(tk_dest)) and 00000100y ;; inmediate
        .err A2052 invalid bit operation on inmediate
    ELSE

Biterider

  • Member
  • ****
  • Posts: 575
  • ObjAsm Developer
    • ObjAsm
Re: Probable Bug related to opattr
« Reply #7 on: November 03, 2020, 01:58:24 AM »

Hi Japheth
Thanks for the clarification.
Now the results make sense again.

Biterider