News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

"Hello masm32", not a BOT, new member

Started by LordAdef, January 22, 2017, 09:42:24 AM

Previous topic - Next topic

LordAdef

Quotesub eax, 98
   cdq  ; and it works in XP...
   m2m ebx, 5
   div ebx      

Thanks for that JJ.
So XP complained and needed sign extension. Would you tell me why win7 was ok while XP was not?

One more question if I may: I thought I should be fine as I was doing unsigned values. Should I always CWB/CWD/CQD to avoid such conflicts?

And thanks everyone for the help!!

LordAdef

Hi,

So, I was checking the ml compatibility and found only 2 places where things go bad in ml:

1. In main.asm (Line 431), the IF statement within a Switch-Case:
Quotemain.asm(434) : error A2206: missing operator in expression
main.asm(437) : error A2206: missing operator in expression
main.asm(439) : error A2206: missing operator in expression
main.asm(440) : error A2206: missing operator in expression

The problematic code for ml (comment and ther errors are gone):
QuoteSwitch gm.state
      Case PLAYLEVEL, STANDBY
               ;-------------- GODs MODE KEYS -------------
             .IF  wParam == 0x31              ; key "1"      start timers
                mov gm.state, PLAYLEVEL
                invoke pSetTimer_All, hWnd         
             .ELSEIF wParam == 0x32         ; key "2"      stop timers
                invoke pKillTimer_All, hWnd   
             .ELSEIF wParam == 0x33         ; key "3"      empty
             .ELSEIF wParam == 0x34         ; key "4"      load new level
              m2m gm.state, LEVELDONE
           .ENDIF
          endsw

In Decomp.inc, these const:
Quotedecomp.inc(46) : error A2042: statement too complex
decomp.inc(51) : error A2008: syntax error : integer
decomp.asm(175) : error A2006: undefined symbol : statBlockage1
decomp.asm(175) : error A2114: INVOKE argument type mismatch : argument : 2
decomp.asm(174) : error A2006: undefined symbol : statBlockage1
decomp.asm(184) : error A2006: undefined symbol : statBlockage1

(commenting, leaving few vars and you get no errors.)
QuotestatMines1   dd   137782, 138577, 138899, 141944, 142110, 151425, 151919, 152373, 152569, 153499,\
            153974, 154131, 154289, 190342, 192719, 192878, 194344, 194345
            
statBlockage1 dd    186986, 186987, 186988, 186989, 186990, 186991, 186992, 186993, 186994, 186995,\
            186996, 186997, 186998, 186999, 187000, 187001, 187002, 187003, 187004, 187005,\
            187006, 187007, 187008, 187009, 187010, 187011, 187012, 187013, 187014, 187015,\
            187016, 187146, 187147, 187148, 187149, 187150, 187151, 187152, 187153, 187154,\
            187155, 187156, 187157, 187158, 187159, 187160, 187161, 187162, 187163, 187164,\
            187165, 187166, 187167, 187168, 187169, 187170, 187171, 187172, 187173, 187174,\
            187175, 187176

statFuel2      dd   8867, 48448, 59781, 65220, 68562, 72358, 75612, 81510, 87119, 89510

statMines2      dd      1000
statBlockage2   dd      1000

In short, I´m ml compatible except from these 2 things: the .IF statement and those variables declarations.
HJWasm is ok and gives me no warnings.

ps: makeit.bat in zip was kindly provided by Hutch

nidud

#167
deleted

jj2007

Quote from: LordAdef on April 27, 2017, 01:59:17 AMSo XP complained and needed sign extension. Would you tell me why win7 was ok while XP was not?

edx is undefined when you return from whatever WinAPI call. And the API changes with every Windows version. Not the documented behaviour, of course - that is remarkably stable. But ecx and edx can contain any value (MB preserves ecx, though).

So if you got, by accident, 0 in edx when running it in Win7, the div ebx works fine. But XP has a different edx, and bang :(

The solution is simple: every div MUST be preceded by cdq, except for the rare case when you really want to divide a edx::eax QWORD.

@nidud: you were almost one minute faster ;)

Caution with xor edx, edx: This assumes that eax is positive; OK most of the time, but with idiv you get unexpected results:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  mov eax, -111
  xor edx, edx
  mov ecx, 3
  idiv ecx
  deb 4, "result", eax

  mov eax, -111
  cdq
  mov ecx, 3
  idiv ecx
  deb 4, "result", eax
 
  Inkey
EndOfCode


Output:
result  eax             1431655728
result  eax             -37


Besides, cdq is one byte shorter than xor edx, edx ;)

HSE

I'm thinking gm.state is the problem because ml need OPTION DOTNAME to allow that point. I can't test it, but now is working perfect with others assemblers. 
Equations in Assembly: SmplMath

jj2007

Dots are OK for structures. The problem was elsewhere:
- ML has a maximum line length
- ML does not support 0x12 syntax

Attached a slightly corrected version.

LordAdef

Thanks HSE and JJ,

Yep, dot notation is fine. I´ve always tested for ml compatibility and from time to time I bump into something. But dot notation has been there for a long time, ml was fine with that.

In fact, I find this compatibility thing quite instructive. I´m using RichMasm/HJWasm, but I´m trying to keep the compatibility so I can share the code here in the forum.

Not meaning to start a war here, but I notice JWasm is more tolerant in many places, such as this 0x32 notation and the line limit I crossed and JJ pinpointed. But they are close enough not to be a big deal.

I´m not sure if there is a feature comparison available. That would be interesting.

jj2007

Quote from: LordAdef on April 27, 2017, 08:36:10 PMI´m not sure if there is a feature comparison available.

Well, kind of :P

For MasmBasic fans, here a special feature of ML:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  mov esi, Chr$("This is a hello World string")
  xor ecx, ecx
  xor edx, edx
  mov eax, [ecx+edx+esi+10]      ; three register addressing!
  push 0
  push eax
  deb 1, "Test", $esp
  pop edx
  pop eax
EndOfCode

OPT_Assembler ML  ; use Microsoft MASM


Note you must force ML because HJWasm is not yet enabled for three register addressing mode (Habran and Johnsa are working on it).

Here is the 64-bit version:include \Masm32\MasmBasic\Res\JBasic.inc
.data
buffer db "Just a test", 0
Init ; OPT_64 1 ; 64 bit assembly
  PrintLine Chr$("This code was assembled with ", @AsmUsed$(1), " in ", jbit$, "-bit format")
  mov rsi, Chr$("This is a hello World string")
  xor ecx, ecx
  xor edx, edx
  mov rax, [rcx+rdx+rsi+10]      ; three register addressing!
  lea rdx, buffer
  usedeb=1
  mov [rdx], rax
  deb 1, "Test", $rdx
EndOfCode

OPT_Assembler ML  ; use the latest and best version of Microsoft MASM


Output:
This code was assembled with ml64 in 64-bit format
Test    $rdx    hello Woest

nidud

#173
deleted

nidud

#174
deleted

jj2007

Quote from: nidud on April 27, 2017, 11:12:49 PM
hello.asm(20) : error A2030: multiple index registers not allowed

Yes, ML 6.14 and 6.15 throw errors. Microsoft introduced this feature in ML version 8.0 and higher. As my 64-bit example above demonstrates, it builds fine in ML64 (a bit slow, perhaps - 15 seconds), even with version 14:Microsoft (R) Macro Assembler (x64) Version 14.00.24210.0
Copyright (C) Microsoft Corporation.  All rights reserved.

*** Link  Skel_GccVc.obj  using polink, sub CONSOLE /entry:start- no resources ***

Creating object: Tmp_File.exp
Creating library: Tmp_File.lib

***  build all took 15522 ms  ***


Rumours say that Intel and AMD are not happy that M$ allows coders to use this feature 8)

nidud

#176
deleted

jj2007

> mov eax, [ebx+eax+ecx+edx+esi+10]

Yep, that is the right spirit :t

Let's push the cpu to its limits:
  lea rdx, [rcx+rdx+rsi+r8+r9+r10+r11+r12+10]      ; eight register addressing!

Works fine, and builds in less than fifteen seconds:Microsoft (R) Macro Assembler (x64) Version 14.00.24210.0
Copyright (C) Microsoft Corporation.  All rights reserved.


*** Link  SkelMbEmpty.obj  using polink, sub CONSOLE /entry:start- no resources ***

Creating object: Tmp_File.exp
Creating library: Tmp_File.lib

***  build all took 14992 ms  ***



nidud

#178
deleted

jj2007

I am sure johnsa and habran are aware of their responsibilities. These new Microsoft features must be implemented asap 8)

[ok ok, this is The Campus, therefore, message to all n00bs readings this: do not believe everything that is written on this forum! Most of us are human beings, we are stupid or ignorant at times, and we see it as our moral obligation to pull your legs. Bashing Micros**t for their incredible bugs is our responsibility, too, and we take that very seriously :eusa_boohoo:]