The MASM Forum

General => The Laboratory => Topic started by: AW on December 04, 2017, 01:20:10 AM

Title: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
Post by: AW 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
Title: Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
Post by: nidud 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
Title: Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
Post by: jj2007 on December 04, 2017, 02:07:21 AM
Looks similar to the MASM 14.0 .if signed comparison bug (http://masm32.com/board/index.php?topic=6447.0) 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)
Title: Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
Post by: AW 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.
Title: Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
Post by: nidud 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.
Title: Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
Post by: jj2007 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 (http://www.terraspace.co.uk/uasm.html))
Title: Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
Post by: nidud 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/
Title: Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
Post by: AW 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:
Title: Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
Post by: AW 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
Title: Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
Post by: jj2007 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
Title: Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
Post by: AW 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:
Title: Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
Post by: hutch-- 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
Title: Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
Post by: jj2007 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)
Title: Re: Guaranteed to crash in MASM (unless you are using MASM 6.xx)
Post by: HSE 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: