Author Topic: Guaranteed to crash in MASM (unless you are using MASM 6.xx)  (Read 179 times)

aw27

  • Member
  • ****
  • Posts: 852
  • Let's Make ASM Great Again!
Guaranteed to crash in MASM (unless you are using MASM 6.xx)
« on: December 04, 2017, 01:20:10 AM »
This will crash in recent releases of MASM. Builds fine in MASM 6.xxx
SDWORD appears to be the culprit


Code: [Select]
.686
.MODEL FLAT, STDCALL

.data
myVar SDWORD ?

.code

main PROC
int 3 ; <- Remove to run on the command line

mov eax, 3
.IF SDWORD PTR eax > 0
.IF eax==3
lea eax, [eax+2*eax]
mov ecx, 3
mov SDWORD PTR myVar, ecx
.ENDIF
.ENDIF

ret
main ENDP

END main

or this:

Code: [Select]
.686
.MODEL FLAT, STDCALL

.data
myVar SDWORD ?


.code

main PROC
int 3 ; <- Remove to run on the command line

        mov myVar, 3
.IF SDWORD PTR myVar > 0
.IF myVar==3
lea eax, [eax+2*eax]
mov ecx, 3
mov SDWORD PTR myVar, ecx
.ENDIF
.ENDIF

ret
main ENDP

END main

nidud

  • Member
  • *****
  • Posts: 1408
    • https://github.com/nidud/asmc
Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
« Reply #1 on: December 04, 2017, 02:02:26 AM »
Indeed. It's one byte short.
Code: [Select]
    .if sdword ptr eax > 0
        nop
    .endif

Code: [Select]
00000000  83 F8 00    *     cmp    sdword ptr eax, 000h
00000003  7E 00       *     jle    @C0001
00000005  90                nop

Sould be:
Code: [Select]
00000000  83 F8 00    *        cmp    sdword ptr eax, 000h
00000003  7E 01       *        jle    @C0001
00000005  90                   nop

jj2007

  • Member
  • *****
  • Posts: 7742
  • Assembler is fun ;-)
    • MasmBasic
Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
« Reply #2 on: December 04, 2017, 02:07:21 AM »
Looks similar to the MASM 14.0 .if signed comparison bug thread.

The SDWORD ptr doesn't work e.g. in ML 14 and 15, the jmp is one byte off. It works fine in ML 6.14 ... 10.0, though. It seems M$ has recently lost control over their pile of s**t.

Workaround:
         mov SDWORD PTR myVar, ecx
         nop

Rumours say there is also a perfect clone for ML that handles all recent opcodes perfectly, is three times faster and absolutely bug-free, at least compared to recent M$ assemblers 8)

aw27

  • Member
  • ****
  • Posts: 852
  • Let's Make ASM Great Again!
Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
« Reply #3 on: December 04, 2017, 02:15:27 AM »
I was not aware of the need for the nop   :(

So, now everybody knows that the bug is still on the latest and greatest:
Microsoft (R) Macro Assembler Version 14.11.25547.0
Copyright (C) Microsoft Corporation.  All rights reserved.

nidud

  • Member
  • *****
  • Posts: 1408
    • https://github.com/nidud/asmc
Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
« Reply #4 on: December 04, 2017, 02:26:34 AM »
It works fine in ML 6.14 ... 10.0,

Seems to work in version 12 as well.

jj2007

  • Member
  • *****
  • Posts: 7742
  • Assembler is fun ;-)
    • MasmBasic
Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
« Reply #5 on: December 04, 2017, 02:26:55 AM »
I was not aware of the need for the nop   :(

Contact Hyde, Irvine, Kusswurm and Iczelion - they must update their books and tutorials 8)

(hint: UAsm works without the magic nop)

nidud

  • Member
  • *****
  • Posts: 1408
    • https://github.com/nidud/asmc
Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
« Reply #6 on: December 04, 2017, 02:57:09 AM »
Re: MASM 14.0 .if signed comparison bug

did you report this discovery to Microsoft?
No, I haven't. I don't even know where I could report this sort of information to Microsoft.
You can try https://connect.microsoft.com/VisualStudio/

aw27

  • Member
  • ****
  • Posts: 852
  • Let's Make ASM Great Again!
Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
« Reply #7 on: December 04, 2017, 03:04:19 AM »
Re: MASM 14.0 .if signed comparison bug

did you report this discovery to Microsoft?
No, I haven't. I don't even know where I could report this sort of information to Microsoft.
You can try https://connect.microsoft.com/VisualStudio/

LOL  :icon_eek:

aw27

  • Member
  • ****
  • Posts: 852
  • Let's Make ASM Great Again!
Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
« Reply #8 on: December 04, 2017, 03:21:57 AM »
And the case of the mysterious disappearance of "dec ebx" (yes, NOP shall fix).

Code: [Select]
.686
.MODEL FLAT, STDCALL

.data
myValue SDWORD 10


.code

main PROC
int 3 ; <- Remove to run on the command line

mov edx, 3
mov ebx, edx
.WHILE ebx>0
.WHILE ecx<myValue
inc ecx
.ENDW
dec ebx ; <-- will disappear
.ENDW

ret
main ENDP

END main

jj2007

  • Member
  • *****
  • Posts: 7742
  • Assembler is fun ;-)
    • MasmBasic
Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
« Reply #9 on: December 04, 2017, 03:28:29 AM »
And the case of the mysterious disappearance of "dec ebx" (yes, NOP shall fix).
We shouldn't be too critical, José. At least, with the extra nop, this is one of the last Micros**t assemblers who understand the .While ... .Endw syntax :t

aw27

  • Member
  • ****
  • Posts: 852
  • Let's Make ASM Great Again!
Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
« Reply #10 on: December 04, 2017, 04:44:37 AM »
And the case of the mysterious disappearance of "dec ebx" (yes, NOP shall fix).
We shouldn't be too critical, José. At least, with the extra nop, this is one of the last Micros**t assemblers who understand the .While ... .Endw syntax :t

Let's enjoy it while it lasts then.  :biggrin:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4926
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
« Reply #11 on: December 04, 2017, 09:47:55 AM »
 :biggrin:

Real Men[tm] code in mnemonics, if you need lots of high level hand holding, try a visual garbage generator.  :P
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

jj2007

  • Member
  • *****
  • Posts: 7742
  • Assembler is fun ;-)
    • MasmBasic
Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
« Reply #12 on: December 04, 2017, 10:29:30 AM »
Real Men[tm] code in mnemonics

      dec ebx ; <-- will disappear

The dec ebx is a mnemonic. For recent MASM versions, you need to resort to the level below mnemonics:
Code: [Select]
db 4bh ; dec ebx
For Real MenTM, the db nnn notation should be made obligatory 8)

HSE

  • Member
  • ****
  • Posts: 552
  • <AMD>< 7-32>
Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
« Reply #13 on: December 04, 2017, 12:43:41 PM »
For Real MenTM, the db nnn notation should be made obligatory 8)
You have tried to say "Real Crazy MenTM"?  :biggrin: